1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-29 13:49:21 +08:00
shirou_gopsutil/README.rst

224 lines
4.7 KiB
ReStructuredText
Raw Normal View History

2014-04-18 16:34:47 +09:00
gopsutil: psutil for golang
==============================
2014-04-24 21:48:51 +09:00
.. image:: https://drone.io/github.com/shirou/gopsutil/status.png
:target: https://drone.io/github.com/shirou/gopsutil
2014-04-25 14:38:26 +09:00
2014-05-11 17:06:53 +09:00
.. image:: https://coveralls.io/repos/shirou/gopsutil/badge.png?branch=master
:target: https://coveralls.io/r/shirou/gopsutil?branch=master
This is a port of psutil (http://pythonhosted.org/psutil/). The challenge is porting all
psutil functions on some architectures...
2014-04-22 12:38:12 +09:00
Available Architectures
2014-04-22 12:31:36 +09:00
------------------------------------
2014-04-18 16:34:47 +09:00
2014-04-22 12:31:36 +09:00
- FreeBSD/amd64
2014-04-23 10:37:21 +09:00
- Linux/amd64
2014-05-14 00:12:17 +09:00
- Linux/arm (raspberry pi)
2014-04-23 10:37:21 +09:00
- Windows/amd64
2014-04-22 12:31:36 +09:00
(I do not have a darwin machine)
2014-04-23 12:53:27 +09:00
All works are implemented without cgo by porting c struct to golang struct.
2014-04-25 14:38:26 +09:00
Usage
2014-04-22 12:31:36 +09:00
---------
::
2014-04-30 23:17:33 +09:00
import (
"fmt"
"github.com/shirou/gopsutil"
)
func main() {
v, _ := gopsutil.VirtualMemory()
// almost every return value is a struct
2014-04-30 23:17:33 +09:00
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
// convert to JSON. String() is also implemented
2014-06-24 14:50:52 +09:00
fmt.Println(v)
2014-04-30 23:17:33 +09:00
}
2014-04-22 12:31:36 +09:00
The output is below.
::
Total: 3179569152, Free:284233728, UsedPercent:84.508194%
{"total":3179569152,"available":492572672,"used":2895335424,"usedPercent":84.50819439828305, (snip)}
Documentation
------------------------
2014-04-22 12:31:36 +09:00
see http://godoc.org/github.com/shirou/gopsutil
More Info
2014-05-16 16:42:16 +09:00
--------------------
Several methods have been added which are not present in psutil, but which provide useful information.
- HostInfo() (linux)
- Hostname
- Uptime
- Procs
- OS (ex: "linux")
- Platform (ex: "ubuntu", "arch")
- PlatformFamily (ex: "debian")
- PlatformVersion (ex: "Ubuntu 13.10")
- VirtualizationSystem (ex: "LXC")
- VirtualizationRole (ex: "guest"/"host")
- CPUInfo() (linux, freebsd)
- CPU (ex: 0, 1, ...)
- VendorID (ex: "GenuineIntel")
- Family
- Model
- Stepping
- PhysicalID
- CoreID
- Cores (ex: 2)
- ModelName (ex: "Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz")
2014-05-16 18:12:18 +09:00
- Mhz
- CacheSize
- Flags (ex: "fpu vme de pse tsc msr pae mce cx8 ...")
2014-05-16 18:12:18 +09:00
2014-05-16 19:03:15 +09:00
- LoadAvg() (linux, freebsd)
- Load1
- Load5
- Load15
2014-06-10 14:38:01 +09:00
- GetDockerIDList() (linux)
- container id list ([]string)
- CgroupCPU() (linux)
- user
- system
- CgroupMem() (linux)
- various status
2014-06-24 14:50:52 +09:00
Some codes are ported from Ohai. many thanks.
2014-05-16 16:42:16 +09:00
2014-04-22 12:38:12 +09:00
Current Status
------------------
- done
2014-04-23 11:37:00 +09:00
- cpu_times (linux, freebsd)
2014-04-22 12:38:12 +09:00
- cpu_count (linux, freebsd, windows)
- virtual_memory (linux, freebsd, windows)
- swap_memory (linux, freebsd)
- disk_partitions (linux, freebsd, windows)
2014-04-29 14:59:22 +09:00
- disk_io_counters (linux)
2014-04-22 19:25:28 +09:00
- disk_usage (linux, freebsd, windows)
2014-05-18 23:23:47 +09:00
- net_io_counters (linux, freebsd, windows)
2014-04-23 10:37:21 +09:00
- boot_time (linux, freebsd, windows(but little broken))
2014-04-22 17:51:58 +09:00
- users (linux, freebsd)
2014-04-24 00:31:57 +09:00
- pids (linux, freebsd)
- pid_exists (linux, freebsd)
2014-04-25 14:38:26 +09:00
- Process class
2014-04-30 16:29:16 +09:00
- pid (linux, freebsd, windows)
- ppid (linux, freebsd, windows)
2014-04-30 16:29:16 +09:00
- name (linux)
- cmdline (linux)
- create_time (linux)
- status (linux)
- cwd (linux)
2014-04-30 16:29:16 +09:00
- exe (linux, freebsd, windows)
- uids (linux, freebsd)
- gids (linux, freebsd)
- terminal (linux, freebsd)
- io_counters (linux)
2014-04-30 16:29:16 +09:00
- nice (linux)
- num_fds (linux)
- num_ctx_switches (linux)
- num_threads (linux, freebsd, windows)
2014-04-30 16:29:16 +09:00
- cpu_times (linux)
- memory_info (linux, freebsd)
2014-04-30 16:29:16 +09:00
- memory_info_ex (linux)
- memory_maps() (linux)
- open_files (linux)
- send_signal (linux, freebsd)
- suspend (linux, freebsd)
- resume (linux, freebsd)
- terminate (linux, freebsd)
- kill (linux, freebsd)
2014-04-22 12:38:12 +09:00
- not yet
- cpu_percent
- cpu_times_percent
- net_connections
- Process class
2014-04-25 14:38:26 +09:00
- username
- ionice
- rlimit
- num_handlers
- threads
- cpu_percent
- cpu_affinity
- memory_percent
- children
- connections
- is_running
- future work
2014-04-22 12:38:12 +09:00
- process_iter
- wait_procs
2014-04-25 14:38:26 +09:00
- Process class
- parent (use ppid instead)
2014-04-25 14:38:26 +09:00
- as_dict
- wait
2014-04-22 12:38:12 +09:00
2014-04-22 12:31:36 +09:00
License
------------
New BSD License (same as psutil)
Related Works
2014-04-22 12:31:36 +09:00
-----------------------
I have been influenced by the following great works:
2014-04-18 16:34:47 +09:00
- psutil: http://pythonhosted.org/psutil/
- dstat: https://github.com/dagwieers/dstat
- gosiger: https://github.com/cloudfoundry/gosigar/
- goprocinfo: https://github.com/c9s/goprocinfo
- go-ps: https://github.com/mitchellh/go-ps
2014-05-16 16:42:16 +09:00
- ohai: https://github.com/opscode/ohai/
2014-04-29 15:34:48 +09:00
How to Contribute
2014-04-29 15:34:48 +09:00
---------------------------
1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create new Pull Request
My Engilsh is terrible, so documentation or correcting comments are also
2014-04-29 15:34:48 +09:00
welcome.