{"id":13366769,"url":"https://github.com/shirou/Gopsutil","last_synced_at":"2025-03-12T18:31:24.691Z","repository":{"id":16160207,"uuid":"18906266","full_name":"shirou/gopsutil","owner":"shirou","description":"psutil for golang","archived":false,"fork":false,"pushed_at":"2024-10-28T22:40:07.000Z","size":3378,"stargazers_count":10586,"open_issues_count":199,"forks_count":1585,"subscribers_count":214,"default_branch":"master","last_synced_at":"2024-10-29T19:25:45.883Z","etag":null,"topics":["go","golang","system-information"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shirou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"shirou"}},"created_at":"2014-04-18T07:35:28.000Z","updated_at":"2024-10-29T18:26:01.000Z","dependencies_parsed_at":"2023-10-11T04:45:52.057Z","dependency_job_id":"15fec6c8-ca4c-419e-8ad8-c23e05bb2cf7","html_url":"https://github.com/shirou/gopsutil","commit_stats":{"total_commits":1760,"total_committers":342,"mean_commits":5.146198830409356,"dds":0.6556818181818183,"last_synced_commit":"68512056e8696381f82ddce6f07abad4ea7ca864"},"previous_names":[],"tags_count":107,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirou%2Fgopsutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirou%2Fgopsutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirou%2Fgopsutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirou%2Fgopsutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shirou","download_url":"https://codeload.github.com/shirou/gopsutil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271295,"owners_count":20264432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","system-information"],"created_at":"2024-07-30T00:01:31.416Z","updated_at":"2025-03-12T18:31:24.683Z","avatar_url":"https://github.com/shirou.png","language":"Go","readme":"# gopsutil: psutil for golang\n\n[![Test](https://github.com/shirou/gopsutil/actions/workflows/test.yml/badge.svg)](https://github.com/shirou/gopsutil/actions/workflows/test.yml) [![Go Reference](https://pkg.go.dev/badge/github.com/shirou/gopsutil/v4.svg)](https://pkg.go.dev/github.com/shirou/gopsutil/v4) [![Calendar Versioning](https://img.shields.io/badge/calver-vMAJOR.YY.MM-22bfda.svg)](https://calver.org/)\n\nThis is a port of psutil (https://github.com/giampaolo/psutil). The\nchallenge is porting all psutil functions on some architectures.\n\n## migration\n\n### v4 migration\n\nThere are some breaking changes. Please see [v4 release note](https://github.com/shirou/gopsutil/releases/tag/v4.24.5).\n\n## Tag semantics\n\ngopsutil tag policy is almost same as Semantic Versioning, but\nautomatically increases like [Ubuntu versioning](https://calver.org/).\n\nFor example, v4.24.04 means\n\n- v4: major version\n- 24: release year, 2024\n- 04: release month\n\ngopsutil aims to keep backwards compatibility until major version change.\n\nTagged at every end of month, but if there are only a few commits, it\ncan be skipped.\n\n## Available Architectures\n\n- FreeBSD i386/amd64/arm\n- Linux i386/amd64/arm(raspberry pi)\n- Windows i386/amd64/arm/arm64\n- Darwin amd64/arm64\n- OpenBSD i386/amd64/armv7/arm64/riscv64 (Thank you @mpfz0r!)\n- Solaris amd64 (developed and tested on SmartOS/Illumos, Thank you @jen20!)\n\nThese have partial support:\n\n- CPU on DragonFly BSD (#893, Thank you @gballet!)\n- host on Linux RISC-V (#896, Thank you @tklauser!)\n\nAll works are implemented without cgo by porting C structs to golang structs.\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/shirou/gopsutil/v4/mem\"\n)\n\nfunc main() {\n    v, _ := mem.VirtualMemory()\n\n    // almost every return value is a struct\n    fmt.Printf(\"Total: %v, Free:%v, UsedPercent:%f%%\\n\", v.Total, v.Free, v.UsedPercent)\n\n    // convert to JSON. String() is also implemented\n    fmt.Println(v)\n}\n```\n\nThe output is below.\n\n    Total: 3179569152, Free:284233728, UsedPercent:84.508194%\n    {\"total\":3179569152,\"available\":492572672,\"used\":2895335424,\"usedPercent\":84.50819439828305, (snip...)}\n\nYou can set alternative locations for various system directories by using the following environment variables:\n\n- /proc: `HOST_PROC`\n- /sys: `HOST_SYS`\n- /etc: `HOST_ETC`\n- /var: `HOST_VAR`\n- /run: `HOST_RUN`\n- /dev: `HOST_DEV`\n- /: `HOST_ROOT`\n- /proc/N/mountinfo: `HOST_PROC_MOUNTINFO`\n\n### Adding settings using `context` (from v3.23.6)\n\nAs of v3.23.6, it is now possible to pass a path location using `context`: import `\"github.com/shirou/gopsutil/v3/common\"` and pass a context with `common.EnvMap` set to `common.EnvKey`, and the location will be used within each function.\n\n```\n\tctx := context.WithValue(context.Background(), \n\t\tcommon.EnvKey, common.EnvMap{common.HostProcEnvKey: \"/myproc\"},\n\t)\n\tv, err := mem.VirtualMemoryWithContext(ctx)\n```\n\nFirst priority is given to the value set in `context`, then the value from the environment variable, and finally the default location.\n\n### Caching\n\nAs of v3.24.1, it is now possible to cached some values. These values default to false, not cached. \n\nBe very careful that enabling the cache may cause inconsistencies. For example, if you enable caching of boottime on Linux, be aware that unintended values may be returned if [the boottime is changed by NTP after booted](https://github.com/shirou/gopsutil/issues/1070#issuecomment-842512782).\n\n- `host`\n  - EnableBootTimeCache\n- `process`\n  - EnableBootTimeCache\n\n### `Ex` struct (from v4.24.5)\n\ngopsutil is designed to work across multiple platforms. However, there are differences in the information available on different platforms, such as memory information that exists on Linux but not on Windows.\n\nAs of v4.24.5, to access this platform-specific information, gopsutil provides functions named `Ex` within the package. Currently, these functions are available in the mem and sensor packages.\n\nThe Ex structs are specific to each platform. For example, on Linux, there is an `ExLinux` struct, which can be obtained using the `mem.NewExLinux()` function. On Windows, it's `mem.ExWindows()`. These Ex structs provide platform-specific information.\n\n```\nex := NewExWindows()\nv, err := ex.VirtualMemory()\nif err != nil {\n    panic(err)\n}\n\nfmt.Println(v.VirtualAvail)\nfmt.Println(v.VirtualTotal)\n\n// Output:\n// 140731958648832\n// 140737488224256\n```\n\ngopsutil aims to minimize platform differences by offering common functions. However, there are many requests to obtain unique information for each platform. The Ex structs are designed to meet those requests. Additional functionalities might be added in the future. The use of these structures makes it clear that the information they provide is specific to each platform, which is why they have been designed in this way.\n\n## Documentation\n\nSee https://pkg.go.dev/github.com/shirou/gopsutil/v4 or https://godocs.io/github.com/shirou/gopsutil/v4\n\n## Requirements\n\n- go1.18 or above is required.\n\n## More Info\n\nSeveral methods have been added which are not present in psutil, but\nwill provide useful information.\n\n- host/HostInfo() (linux)\n  - Hostname\n  - Uptime\n  - Procs\n  - OS (ex: \"linux\")\n  - Platform (ex: \"ubuntu\", \"arch\")\n  - PlatformFamily (ex: \"debian\")\n  - PlatformVersion (ex: \"Ubuntu 13.10\")\n  - VirtualizationSystem (ex: \"LXC\")\n  - VirtualizationRole (ex: \"guest\"/\"host\")\n- IOCounters\n  - Label (linux only) The registered [device mapper\n    name](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm)\n- cpu/CPUInfo() (linux, freebsd)\n  - CPU (ex: 0, 1, ...)\n  - VendorID (ex: \"GenuineIntel\")\n  - Family\n  - Model\n  - Stepping\n  - PhysicalID\n  - CoreID\n  - Cores (ex: 2)\n  - ModelName (ex: \"Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz\")\n  - Mhz\n  - CacheSize\n  - Flags (ex: \"fpu vme de pse tsc msr pae mce cx8 ...\")\n  - Microcode\n- load/Avg() (linux, freebsd, solaris)\n  - Load1\n  - Load5\n  - Load15\n- docker/GetDockerIDList() (linux only)\n  - container id list ([]string)\n- docker/CgroupCPU() (linux only)\n  - user\n  - system\n- docker/CgroupMem() (linux only)\n  - various status\n- net_protocols (linux only)\n  - system wide stats on network protocols (i.e IP, TCP, UDP, etc.)\n  - sourced from /proc/net/snmp\n- iptables nf_conntrack (linux only)\n  - system wide stats on netfilter conntrack module\n  - sourced from /proc/sys/net/netfilter/nf_conntrack_count\n\nSome code is ported from Ohai. Many thanks.\n\n## Current Status\n\n- x: works\n- b: almost works, but something is broken\n\n|name                  |Linux  |FreeBSD  |OpenBSD  |macOS   |Windows  |Solaris  |Plan 9   |AIX      |\n|----------------------|-------|---------|---------|--------|---------|---------|---------|---------|\n|cpu\\_times            |x      |x        |x        |x       |x        |         |b        |x        |\n|cpu\\_count            |x      |x        |x        |x       |x        |         |x        |x        |\n|cpu\\_percent          |x      |x        |x        |x       |x        |         |         |x        |\n|cpu\\_times\\_percent   |x      |x        |x        |x       |x        |         |         |x        |\n|virtual\\_memory       |x      |x        |x        |x       |x        |b        |x        |x        |\n|swap\\_memory          |x      |x        |x        |x       |         |         |x        |X        |\n|disk\\_partitions      |x      |x        |x        |x       |x        |         |         |x        |\n|disk\\_io\\_counters    |x      |x        |x        |x       |x        |         |         |         |\n|disk\\_usage           |x      |x        |x        |x       |x        |         |         |x        |\n|net\\_io\\_counters     |x      |x        |x        |b       |x        |x        |         |         |\n|boot\\_time            |x      |x        |x        |x       |x        |         |         |X        |\n|users                 |x      |x        |x        |x       |x        |         |         |x        |\n|pids                  |x      |x        |x        |x       |x        |         |         |         |\n|pid\\_exists           |x      |x        |x        |x       |x        |         |         |         |\n|net\\_connections      |x      |x        |x        |x       |         |         |         |x        |\n|net\\_protocols        |x      |         |         |        |         |         |         |x        |\n|net\\_if\\_addrs        |       |         |         |        |         |         |         |x        |\n|net\\_if\\_stats        |       |         |         |        |         |         |         |x        |\n|netfilter\\_conntrack  |x      |         |         |        |         |         |         |         |\n|sensors_temperature   |x      |         |         |x       |x        |x        |         |         |\n\n\n### Process class\n\n|name                |Linux  |FreeBSD  |OpenBSD  |macOS  |Windows  |\n|--------------------|-------|---------|---------|-------|---------|\n|pid                 |x      |x        |x        |x      |x        |\n|ppid                |x      |x        |x        |x      |x        |\n|name                |x      |x        |x        |x      |x        |\n|cmdline             |x      |x        |x        |x      |x        |\n|create\\_time        |x      |         |         |x      |x        |\n|status              |x      |x        |x        |x      |         |\n|cwd                 |x      |x        |x        |x      |x        |\n|exe                 |x      |x        |x        |       |x        |\n|uids                |x      |x        |x        |x      |         |\n|gids                |x      |x        |x        |x      |         |\n|terminal            |x      |x        |x        |       |         |\n|io\\_counters        |x      |x        |x        |       |x        |\n|nice                |x      |x        |x        |x      |x        |\n|num\\_fds            |x      |         |         |       |x        |\n|num\\_ctx\\_switches  |x      |         |         |       |         |\n|num\\_threads        |x      |x        |x        |x      |x        |\n|cpu\\_times          |x      |         |         |       |x        |\n|memory\\_info        |x      |x        |x        |x      |x        |\n|memory\\_maps        |x      |         |         |       |         |\n|open\\_files         |x      |         |         |       |x        |\n|send\\_signal        |x      |x        |x        |x      |         |\n|suspend             |x      |x        |x        |x      |x        |\n|resume              |x      |x        |x        |x      |x        |\n|terminate           |x      |x        |x        |x      |x        |\n|kill                |x      |x        |x        |x      |         |\n|username            |x      |x        |x        |x      |x        |\n|ionice              |       |         |         |       |         |\n|rlimit              |x      |         |         |       |         |\n|num\\_handlers       |       |         |         |       |         |\n|threads             |x      |         |         |       |         |\n|cpu\\_percent        |x      |         |x        |x      |x        |\n|cpu\\_affinity       |       |         |         |       |         |\n|memory\\_percent     |x      |         |         |       |x        |\n|parent              |x      |         |x        |x      |x        |\n|children            |x      |x        |x        |x      |x        |\n|connections         |x      |         |x        |x      |         |\n|is\\_running         |       |         |         |       |         |\n|page\\_faults        |x      |         |         |       |x        |\n\n### gopsutil Original Metrics\n\n|item                    |Linux  |FreeBSD  |OpenBSD  |macOS   |Windows |Solaris  |AIX      |\n|------------------------|-------|---------|---------|--------|--------|---------|---------|\n|**HostInfo**            |       |         |         |        |        |         |         |\n|hostname                |x      |x        |x        |x       |x       |x        |X        |\n|uptime                  |x      |x        |x        |x       |        |x        |x        |\n|process                 |x      |x        |x        |        |        |x        |         |\n|os                      |x      |x        |x        |x       |x       |x        |x        |\n|platform                |x      |x        |x        |x       |        |x        |x        |\n|platformfamily          |x      |x        |x        |x       |        |x        |x        |\n|virtualization          |x      |         |         |        |        |         |         |\n|**CPU**                 |       |         |         |        |        |         |         |\n|VendorID                |x      |x        |x        |x       |x       |x        |x        |\n|Family                  |x      |x        |x        |x       |x       |x        |x        |\n|Model                   |x      |x        |x        |x       |x       |x        |x        |\n|Stepping                |x      |x        |x        |x       |x       |x        |         |\n|PhysicalID              |x      |         |         |        |        |x        |         |\n|CoreID                  |x      |         |         |        |        |x        |         |\n|Cores                   |x      |         |         |x       |x       |x        |x        |\n|ModelName               |x      |x        |x        |x       |x       |x        |x        |\n|Microcode               |x      |         |         |        |        |x        |         |\n|**LoadAvg**             |       |         |         |        |        |         |         |\n|Load1                   |x      |x        |x        |x       |x       |x        |x        |\n|Load5                   |x      |x        |x        |x       |x       |x        |x        |\n|Load15                  |x      |x        |x        |x       |x       |x        |x        |\n|**Docker GetDockerID**  |       |         |         |        |        |         |         |\n|container id            |x      |no       |no       |no      |no      |no       |no       |\n|**Docker CgroupsCPU**   |       |         |         |        |        |         |         |\n|user                    |x      |no       |no       |no      |no      |no       |no       |\n|system                  |x      |no       |no       |no      |no      |no       |no       |\n|**Docker CgroupsMem**   |       |         |         |        |        |         |         |\n|various                 |x      |no       |no       |no      |no      |no       |no       |\n\n- future work\n  - process_iter\n  - wait_procs\n  - Process class\n    - as_dict\n    - wait\n  - AIX processes\n\n## License\n\nNew BSD License (same as psutil)\n\n## Related Works\n\nI have been influenced by the following great works:\n\n- psutil: https://github.com/giampaolo/psutil\n- dstat: https://github.com/dagwieers/dstat\n- gosigar: https://github.com/cloudfoundry/gosigar/\n- goprocinfo: https://github.com/c9s/goprocinfo\n- go-ps: https://github.com/mitchellh/go-ps\n- ohai: https://github.com/opscode/ohai/\n- bosun:\n  https://github.com/bosun-monitor/bosun/tree/master/cmd/scollector/collectors\n- mackerel:\n  https://github.com/mackerelio/mackerel-agent/tree/master/metrics\n\n## How to Contribute\n\n1.  Fork it\n2.  Create your feature branch (git checkout -b my-new-feature)\n3.  Commit your changes (git commit -am 'Add some feature')\n4.  Push to the branch (git push origin my-new-feature)\n5.  Create new Pull Request\n\nEnglish is not my native language, so PRs correcting grammar or spelling are welcome and appreciated.\n","funding_links":["https://github.com/sponsors/shirou"],"categories":["杂项","雜項"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirou%2FGopsutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshirou%2FGopsutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirou%2FGopsutil/lists"}