forked from go-ego/riot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
149 lines (121 loc) · 3.3 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2016 ego authors
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package riot
import (
"sync"
"github.com/go-vgo/gt/info"
)
var (
lck sync.RWMutex
// InitMemUsed init mem used
InitMemUsed uint64
// InitDiskUsed init disk used
InitDiskUsed uint64
)
func init() {
lck.Lock()
InitMemUsed, _ = MemUsed()
InitDiskUsed, _ = DiskUsed()
lck.Unlock()
}
// MemPercent returns the amount of use memory in percent.
func MemPercent() (string, error) {
return info.MemPercent()
}
// MemUsed returns the amount of used memory in bytes.
func MemUsed() (uint64, error) {
return info.MemUsed()
}
// UsedMem returns the amount of riot used memory in bytes
// after init() func.
func (engine *Engine) UsedMem() (uint64, error) {
memUsed, err := MemUsed()
if err != nil {
return 0, err
}
return memUsed - InitMemUsed, err
}
// MemTotal returns the amount of total memory in bytes.
func MemTotal() (uint64, error) {
return info.MemTotal()
}
// MemFree returns the amount of free memory in bytes.
func MemFree() (uint64, error) {
return info.MemFree()
}
// ToKB bytes to kb
func ToKB(data uint64) uint64 {
return data / 1024
}
// ToMB bytes to mb
func ToMB(data uint64) uint64 {
return data / 1024 / 1024
}
// ToGB bytes to gb
func ToGB(data uint64) uint64 {
return data / 1024 / 1024 / 1024
}
// Disk init the disk
// func Disk(pt ...bool) ([]*disk.UsageStat, error) {
// return info.Disk(pt...)
// }
// DiskPercent returns the amount of use disk in percent.
func DiskPercent() (string, error) {
return info.DiskPercent()
}
// DiskUsed returns the amount of use disk in bytes.
func DiskUsed() (uint64, error) {
return info.DiskUsed()
}
// UsedDisk returns the amount of use disk in bytes
// after init() func.
func (engine *Engine) UsedDisk() (uint64, error) {
diskUsed, err := DiskUsed()
if err != nil {
return 0, err
}
return diskUsed - InitDiskUsed, err
}
// DiskTotal returns the amount of total disk in bytes.
func DiskTotal() (uint64, error) {
return info.DiskTotal()
}
// DiskFree returns the amount of free disk in bytes.
func DiskFree() (uint64, error) {
return info.DiskFree()
}
// CPUInfo returns the cpu info
func CPUInfo(args ...int) (string, error) {
return info.CPUInfo(args...)
}
// CPUPercent returns the amount of use cpu in percent.
func CPUPercent() ([]float64, error) {
return info.CPUPercent()
}
// Uptime returns the system uptime in seconds.
func Uptime() (uptime uint64, err error) {
return info.Uptime()
}
// PlatformInfo fetches system platform information.
func PlatformInfo() (platform, family, osVersion string, err error) {
return info.PlatformInfo()
}
// Platform returns the platform name and OS Version.
func Platform() (string, error) {
return info.Platform()
}
// KernelVer returns the kernel version as a string.
func KernelVer() (string, error) {
return info.KernelVer()
}