|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | 03-May-2022 | - |
| .circleci/ | H | 01-Feb-2020 | - | 29 | 27 |
| .github/ISSUE_TEMPLATE/ | H | 01-Feb-2020 | - | 45 | 32 |
| cpu/ | H | 01-Feb-2020 | - | 2,137 | 1,747 |
| disk/ | H | 01-Feb-2020 | - | 2,190 | 1,763 |
| docker/ | H | 01-Feb-2020 | - | 524 | 396 |
| host/ | H | 01-Feb-2020 | - | 3,351 | 2,610 |
| internal/common/ | H | 01-Feb-2020 | - | 1,855 | 1,506 |
| load/ | H | 01-Feb-2020 | - | 400 | 306 |
| mem/ | H | 01-Feb-2020 | - | 1,457 | 1,162 |
| net/ | H | 01-Feb-2020 | - | 3,668 | 3,004 |
| process/ | H | 01-Feb-2020 | - | 7,247 | 5,923 |
| winservices/ | H | 01-Feb-2020 | - | 160 | 115 |
| .gitignore | H A D | 01-Feb-2020 | 30 | 7 | 6 |
| Gopkg.lock | H A D | 01-Feb-2020 | 2 KiB | 77 | 68 |
| Gopkg.toml | H A D | 01-Feb-2020 | 870 | 43 | 37 |
| LICENSE | H A D | 01-Feb-2020 | 3.1 KiB | 61 | 49 |
| Makefile | H A D | 01-Feb-2020 | 1.6 KiB | 38 | 27 |
| README.rst | H A D | 01-Feb-2020 | 9.7 KiB | 329 | 243 |
| coverall.sh | H A D | 01-Feb-2020 | 564 | 27 | 19 |
| doc.go | H A D | 01-Feb-2020 | 17 | 2 | 1 |
| mktypes.sh | H A D | 01-Feb-2020 | 626 | 41 | 34 |
| v2migration.sh | H A D | 01-Feb-2020 | 5 KiB | 135 | 111 |
| windows_memo.rst | H A D | 01-Feb-2020 | 646 | 36 | 34 |
README.rst
1gopsutil: psutil for golang
2==============================
3
4.. image:: https://circleci.com/gh/shirou/gopsutil.svg?&style=shield
5 :target: https://circleci.com/gh/shirou/gopsutil
6
7.. image:: https://coveralls.io/repos/shirou/gopsutil/badge.svg?branch=master
8 :target: https://coveralls.io/r/shirou/gopsutil?branch=master
9
10.. image:: https://godoc.org/github.com/shirou/gopsutil?status.svg
11 :target: http://godoc.org/github.com/shirou/gopsutil
12
13This is a port of psutil (https://github.com/giampaolo/psutil). The challenge is porting all
14psutil functions on some architectures.
15
16
17Breaking Changes! golang 1.8 is required
18-------------------------------------------
19
20After v2.17.04, golang 1.8 is required to build.
21
22
23Tag semantics
24-------------------------
25
26gopsutil tag policy is almost same as Semantic Versioning, but automatically increase like Ubuntu versioning.
27
28for example, `v2.17.04` means
29
30- v2: major version
31- 17: release year, 2017
32- 04: release month
33
34gopsutil aims to keep backwards-compatiblity until major version change.
35
36Taged at every end of month, but there are only a few commits, it can be skipped.
37
38
39Available Architectures
40------------------------------------
41
42- FreeBSD i386/amd64/arm
43- Linux i386/amd64/arm(raspberry pi)
44- Windows/amd64
45- Darwin i386/amd64
46- OpenBSD amd64 (Thank you @mpfz0r!)
47- Solaris amd64 (developed and tested on SmartOS/Illumos, Thank you @jen20!)
48
49All works are implemented without cgo by porting c struct to golang struct.
50
51
52Usage
53---------
54
55Note: gopsutil v2 breaks compatibility. If you want to stay with compatibility, please use v1 branch and vendoring.
56
57.. code:: go
58
59 package main
60
61 import (
62 "fmt"
63
64 "github.com/shirou/gopsutil/mem"
65 )
66
67 func main() {
68 v, _ := mem.VirtualMemory()
69
70 // almost every return value is a struct
71 fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
72
73 // convert to JSON. String() is also implemented
74 fmt.Println(v)
75 }
76
77The output is below.
78
79::
80
81 Total: 3179569152, Free:284233728, UsedPercent:84.508194%
82 {"total":3179569152,"available":492572672,"used":2895335424,"usedPercent":84.50819439828305, (snip...)}
83
84You can set an alternative location to :code:`/proc` by setting the :code:`HOST_PROC` environment variable.
85
86You can set an alternative location to :code:`/sys` by setting the :code:`HOST_SYS` environment variable.
87
88You can set an alternative location to :code:`/etc` by setting the :code:`HOST_ETC` environment variable.
89
90You can set an alternative location to :code:`/var` by setting the :code:`HOST_VAR` environment variable.
91
92You can set an alternative location to :code:`/run` by setting the :code:`HOST_RUN` environment variable.
93
94You can set an alternative location to :code:`/dev` by setting the :code:`HOST_DEV` environment variable.
95
96
97Documentation
98------------------------
99
100see http://godoc.org/github.com/shirou/gopsutil
101
102Requirements
103-----------------
104
105- go1.7 or above is required.
106
107
108More Info
109--------------------
110
111Several methods have been added which are not present in psutil, but will provide useful information.
112
113- host/HostInfo() (linux)
114
115 - Hostname
116 - Uptime
117 - Procs
118 - OS (ex: "linux")
119 - Platform (ex: "ubuntu", "arch")
120 - PlatformFamily (ex: "debian")
121 - PlatformVersion (ex: "Ubuntu 13.10")
122 - VirtualizationSystem (ex: "LXC")
123 - VirtualizationRole (ex: "guest"/"host")
124
125- IOCounters
126
127 - Label (linux only) The registered `device mapper name <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm>`_
128
129- cpu/CPUInfo() (linux, freebsd)
130
131 - CPU (ex: 0, 1, ...)
132 - VendorID (ex: "GenuineIntel")
133 - Family
134 - Model
135 - Stepping
136 - PhysicalID
137 - CoreID
138 - Cores (ex: 2)
139 - ModelName (ex: "Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz")
140 - Mhz
141 - CacheSize
142 - Flags (ex: "fpu vme de pse tsc msr pae mce cx8 ...")
143 - Microcode
144
145- load/LoadAvg() (linux, freebsd)
146
147 - Load1
148 - Load5
149 - Load15
150
151- docker/GetDockerIDList() (linux only)
152
153 - container id list ([]string)
154
155- docker/CgroupCPU() (linux only)
156
157 - user
158 - system
159
160- docker/CgroupMem() (linux only)
161
162 - various status
163
164- net_protocols (linux only)
165
166 - system wide stats on network protocols (i.e IP, TCP, UDP, etc.)
167 - sourced from /proc/net/snmp
168
169- iptables nf_conntrack (linux only)
170
171 - system wide stats on netfilter conntrack module
172 - sourced from /proc/sys/net/netfilter/nf_conntrack_count
173
174Some codes are ported from Ohai. many thanks.
175
176
177Current Status
178------------------
179
180- x: work
181- b: almost works, but something is broken
182
183=================== ====== ======= ======= ====== ======= =======
184name Linux FreeBSD OpenBSD MacOSX Windows Solaris
185cpu_times x x x x x
186cpu_count x x x x x
187cpu_percent x x x x x
188cpu_times_percent x x x x x
189virtual_memory x x x x x b
190swap_memory x x x x
191disk_partitions x x x x x
192disk_io_counters x x x
193disk_usage x x x x x
194net_io_counters x x x b x
195boot_time x x x x x
196users x x x x x
197pids x x x x x
198pid_exists x x x x x
199net_connections x x x
200net_protocols x
201net_if_addrs
202net_if_stats
203netfilter_conntrack x
204=================== ====== ======= ======= ====== =======
205
206Process class
207^^^^^^^^^^^^^^^
208
209================ ===== ======= ======= ====== =======
210name Linux FreeBSD OpenBSD MacOSX Windows
211pid x x x x x
212ppid x x x x x
213name x x x x x
214cmdline x x x x
215create_time x x x
216status x x x x
217cwd x
218exe x x x x
219uids x x x x
220gids x x x x
221terminal x x x x
222io_counters x x x x
223nice x x x x x
224num_fds x
225num_ctx_switches x
226num_threads x x x x x
227cpu_times x x
228memory_info x x x x x
229memory_info_ex x
230memory_maps x
231open_files x
232send_signal x x x x
233suspend x x x x
234resume x x x x
235terminate x x x x x
236kill x x x x
237username x x x x x
238ionice
239rlimit x
240num_handlers
241threads x
242cpu_percent x x x
243cpu_affinity
244memory_percent
245parent x x x x
246children x x x x x
247connections x x x
248is_running
249page_faults x
250================ ===== ======= ======= ====== =======
251
252Original Metrics
253^^^^^^^^^^^^^^^^^^^
254
255================== ===== ======= ======= ====== ======= =======
256item Linux FreeBSD OpenBSD MacOSX Windows Solaris
257**HostInfo**
258hostname x x x x x x
259 uptime x x x x x
260 proces x x x x
261 os x x x x x x
262 platform x x x x x
263 platformfamily x x x x x
264 virtualization x
265**CPU**
266 VendorID x x x x x x
267 Family x x x x x x
268 Model x x x x x x
269 Stepping x x x x x x
270 PhysicalID x x
271 CoreID x x
272 Cores x x x
273 ModelName x x x x x x
274 Microcode x x
275**LoadAvg**
276 Load1 x x x x
277 Load5 x x x x
278 Load15 x x x x
279**GetDockerID**
280 container id x no no no no
281**CgroupsCPU**
282 user x no no no no
283 system x no no no no
284**CgroupsMem**
285 various x no no no no
286================== ===== ======= ======= ====== ======= =======
287
288- future work
289
290 - process_iter
291 - wait_procs
292 - Process class
293
294 - as_dict
295 - wait
296
297
298License
299------------
300
301New BSD License (same as psutil)
302
303
304Related Works
305-----------------------
306
307I have been influenced by the following great works:
308
309- psutil: https://github.com/giampaolo/psutil
310- dstat: https://github.com/dagwieers/dstat
311- gosigar: https://github.com/cloudfoundry/gosigar/
312- goprocinfo: https://github.com/c9s/goprocinfo
313- go-ps: https://github.com/mitchellh/go-ps
314- ohai: https://github.com/opscode/ohai/
315- bosun: https://github.com/bosun-monitor/bosun/tree/master/cmd/scollector/collectors
316- mackerel: https://github.com/mackerelio/mackerel-agent/tree/master/metrics
317
318How to Contribute
319---------------------------
320
3211. Fork it
3222. Create your feature branch (git checkout -b my-new-feature)
3233. Commit your changes (git commit -am 'Add some feature')
3244. Push to the branch (git push origin my-new-feature)
3255. Create new Pull Request
326
327My English is terrible, so documentation or correcting comments are also
328welcome.
329