• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..18-Jul-2019-

cpu/H18-Jul-2019-1,4381,153

disk/H18-Jul-2019-2,3501,845

docker/H18-Jul-2019-402326

host/H18-Jul-2019-2,8122,221

internal/common/H18-Jul-2019-1,4841,175

load/H18-Jul-2019-322240

mem/H18-Jul-2019-1,139906

net/H18-Jul-2019-2,0441,648

process/H18-Jul-2019-5,9724,804

.gitignoreH A D18-Jul-201923 65

LICENSEH A D18-Jul-20193.1 KiB6149

MakefileH A D18-Jul-20191.5 KiB3424

README.rstH A D18-Jul-20199.5 KiB323240

circle.ymlH A D18-Jul-2019400 1413

coverall.shH A D18-Jul-2019564 2719

doc.goH A D18-Jul-201917 21

mktypes.shH A D18-Jul-2019596 3831

v2migration.shH A D18-Jul-20195 KiB135111

windows_memo.rstH A D18-Jul-2019646 3634

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
92Documentation
93------------------------
94
95see http://godoc.org/github.com/shirou/gopsutil
96
97Requirements
98-----------------
99
100- go1.7 or above is required.
101
102
103More Info
104--------------------
105
106Several methods have been added which are not present in psutil, but will provide useful information.
107
108- host/HostInfo()  (linux)
109
110  - Hostname
111  - Uptime
112  - Procs
113  - OS                    (ex: "linux")
114  - Platform              (ex: "ubuntu", "arch")
115  - PlatformFamily        (ex: "debian")
116  - PlatformVersion       (ex: "Ubuntu 13.10")
117  - VirtualizationSystem  (ex: "LXC")
118  - VirtualizationRole    (ex: "guest"/"host")
119
120- IOCounters
121
122  - Label (linux only)    The registered `device mapper name <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm>`_
123
124- cpu/CPUInfo()  (linux, freebsd)
125
126  - CPU          (ex: 0, 1, ...)
127  - VendorID     (ex: "GenuineIntel")
128  - Family
129  - Model
130  - Stepping
131  - PhysicalID
132  - CoreID
133  - Cores        (ex: 2)
134  - ModelName    (ex: "Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz")
135  - Mhz
136  - CacheSize
137  - Flags        (ex: "fpu vme de pse tsc msr pae mce cx8 ...")
138  - Microcode
139
140- load/LoadAvg()  (linux, freebsd)
141
142  - Load1
143  - Load5
144  - Load15
145
146- docker/GetDockerIDList() (linux only)
147
148  - container id list ([]string)
149
150- docker/CgroupCPU() (linux only)
151
152  - user
153  - system
154
155- docker/CgroupMem() (linux only)
156
157  - various status
158
159- net_protocols (linux only)
160
161  - system wide stats on network protocols (i.e IP, TCP, UDP, etc.)
162  - sourced from /proc/net/snmp
163
164- iptables nf_conntrack (linux only)
165
166  - system wide stats on netfilter conntrack module
167  - sourced from /proc/sys/net/netfilter/nf_conntrack_count
168
169Some codes are ported from Ohai. many thanks.
170
171
172Current Status
173------------------
174
175- x: work
176- b: almost works, but something is broken
177
178=================== ====== ======= ======= ====== ======= =======
179name                Linux  FreeBSD OpenBSD MacOSX Windows Solaris
180cpu_times             x      x       x       x       x
181cpu_count             x      x       x       x       x
182cpu_percent           x      x       x       x       x
183cpu_times_percent     x      x       x       x       x
184virtual_memory        x      x       x       x       x       b
185swap_memory           x      x       x       x
186disk_partitions       x      x       x       x       x
187disk_io_counters      x      x       x
188disk_usage            x      x       x       x       x
189net_io_counters       x      x       x       b       x
190boot_time             x      x       x       x       x
191users                 x      x       x       x       x
192pids                  x      x       x       x       x
193pid_exists            x      x       x       x       x
194net_connections       x              x       x
195net_protocols         x
196net_if_addrs
197net_if_stats
198netfilter_conntrack   x
199=================== ====== ======= ======= ====== =======
200
201Process class
202^^^^^^^^^^^^^^^
203
204================ ===== ======= ======= ====== =======
205name             Linux FreeBSD OpenBSD MacOSX Windows
206pid                 x     x      x       x       x
207ppid                x     x      x       x       x
208name                x     x      x       x       x
209cmdline             x     x              x       x
210create_time         x                    x
211status              x     x      x       x
212cwd                 x
213exe                 x     x      x               x
214uids                x     x      x       x
215gids                x     x      x       x
216terminal            x     x      x       x
217io_counters         x     x      x               x
218nice                x     x      x       x       x
219num_fds             x
220num_ctx_switches    x
221num_threads         x     x      x       x       x
222cpu_times           x                            x
223memory_info         x     x      x       x       x
224memory_info_ex      x
225memory_maps         x
226open_files          x
227send_signal         x     x      x       x
228suspend             x     x      x       x
229resume              x     x      x       x
230terminate           x     x      x       x       x
231kill                x     x      x       x
232username            x     x      x       x       x
233ionice
234rlimit              x
235num_handlers
236threads             x
237cpu_percent         x            x       x
238cpu_affinity
239memory_percent
240parent              x            x       x       x
241children            x     x      x       x       x
242connections         x            x       x
243is_running
244================ ===== ======= ======= ====== =======
245
246Original Metrics
247^^^^^^^^^^^^^^^^^^^
248
249================== ===== ======= ======= ====== ======= =======
250item               Linux FreeBSD OpenBSD MacOSX Windows Solaris
251**HostInfo**
252hostname              x     x      x       x       x       x
253  uptime              x     x      x       x               x
254  proces              x     x      x                       x
255  os                  x     x      x       x       x       x
256  platform            x     x      x       x               x
257  platformfamily      x     x      x       x               x
258  virtualization      x
259**CPU**
260  VendorID            x     x      x       x       x      x
261  Family              x     x      x       x       x      x
262  Model               x     x      x       x       x      x
263  Stepping            x     x      x       x       x      x
264  PhysicalID          x                                   x
265  CoreID              x                                   x
266  Cores               x                            x      x
267  ModelName           x     x      x       x       x      x
268  Microcode           x                                   x
269**LoadAvg**
270  Load1               x     x      x       x
271  Load5               x     x      x       x
272  Load15              x     x      x       x
273**GetDockerID**
274  container id        x     no     no      no      no
275**CgroupsCPU**
276  user                x     no     no      no      no
277  system              x     no     no      no      no
278**CgroupsMem**
279  various             x     no     no      no      no
280================== ===== ======= ======= ====== ======= =======
281
282- future work
283
284  - process_iter
285  - wait_procs
286  - Process class
287
288    - as_dict
289    - wait
290
291
292License
293------------
294
295New BSD License (same as psutil)
296
297
298Related Works
299-----------------------
300
301I have been influenced by the following great works:
302
303- psutil: https://github.com/giampaolo/psutil
304- dstat: https://github.com/dagwieers/dstat
305- gosigar: https://github.com/cloudfoundry/gosigar/
306- goprocinfo: https://github.com/c9s/goprocinfo
307- go-ps: https://github.com/mitchellh/go-ps
308- ohai: https://github.com/opscode/ohai/
309- bosun: https://github.com/bosun-monitor/bosun/tree/master/cmd/scollector/collectors
310- mackerel: https://github.com/mackerelio/mackerel-agent/tree/master/metrics
311
312How to Contribute
313---------------------------
314
3151. Fork it
3162. Create your feature branch (git checkout -b my-new-feature)
3173. Commit your changes (git commit -am 'Add some feature')
3184. Push to the branch (git push origin my-new-feature)
3195. Create new Pull Request
320
321My English is terrible, so documentation or correcting comments are also
322welcome.
323