{"id":13694216,"url":"https://github.com/mackerelio/go-osstat","last_synced_at":"2026-03-09T03:06:43.822Z","repository":{"id":25956291,"uuid":"106974012","full_name":"mackerelio/go-osstat","owner":"mackerelio","description":"OS system statistics library for Go","archived":false,"fork":false,"pushed_at":"2024-07-04T16:22:35.000Z","size":175,"stargazers_count":382,"open_issues_count":1,"forks_count":51,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-08-03T17:19:04.623Z","etag":null,"topics":["go","golang","golang-library","system-information"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mackerelio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-15T01:05:39.000Z","updated_at":"2024-08-03T01:34:52.000Z","dependencies_parsed_at":"2023-01-14T04:45:08.890Z","dependency_job_id":"88439481-ec1f-4491-a367-ec8731e69e3a","html_url":"https://github.com/mackerelio/go-osstat","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackerelio%2Fgo-osstat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackerelio%2Fgo-osstat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackerelio%2Fgo-osstat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackerelio%2Fgo-osstat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mackerelio","download_url":"https://codeload.github.com/mackerelio/go-osstat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224346375,"owners_count":17296203,"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","golang-library","system-information"],"created_at":"2024-08-02T17:01:27.005Z","updated_at":"2026-03-09T03:06:43.750Z","avatar_url":"https://github.com/mackerelio.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["监控告警","Monitoring"],"readme":"# OS system statistics library for Go\nThis is a library to get system metrics like cpu load and memory usage.\nThe library is created for [mackerel-agent](https://github.com/mackerelio/mackerel-agent).\n\n[![GoDev](https://pkg.go.dev/badge/github.com/mackerelio/go-osstat)](https://pkg.go.dev/github.com/mackerelio/go-osstat)\n[![Build Status](https://github.com/mackerelio/go-osstat/workflows/Build/badge.svg)](https://github.com/mackerelio/go-osstat/workflows/Build/badge.svg)\n\n## Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mackerelio/go-osstat/memory\"\n)\n\nfunc main() {\n\tmemory, err := memory.Get()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"%s\\n\", err)\n\t\treturn\n\t}\n\tfmt.Printf(\"memory total: %d bytes\\n\", memory.Total)\n\tfmt.Printf(\"memory used: %d bytes\\n\", memory.Used)\n\tfmt.Printf(\"memory cached: %d bytes\\n\", memory.Cached)\n\tfmt.Printf(\"memory free: %d bytes\\n\", memory.Free)\n}\n```\n\n## Supported OS\n\n||loadavg|uptime|cpu|memory|network|disk i/o|\n|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n|Linux|yes|yes|yes|yes|yes|yes|\n|Darwin|yes|yes|*1|yes|yes|no|\n|FreeBSD|yes|yes|no|yes|yes|no|\n|NetBSD|yes|yes|no|no|yes|no|\n|OpenBSD|yes|yes|no|no|no|no|\n|Windows|no|yes|no|yes|no|no|\n\n*1: unavailable without cgo\n\n## Note for counter values\nThis library returns the counter value for cpu, network and disk I/O statistics by design. To get the cpu usage in percent, network traffic in kB/s or disk IOPS, sleep for a while and calculate the difference.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/mackerelio/go-osstat/cpu\"\n)\n\nfunc main() {\n\tbefore, err := cpu.Get()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"%s\\n\", err)\n\t\treturn\n\t}\n\ttime.Sleep(time.Duration(1) * time.Second)\n\tafter, err := cpu.Get()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"%s\\n\", err)\n\t\treturn\n\t}\n\ttotal := float64(after.Total - before.Total)\n\tfmt.Printf(\"cpu user: %f %%\\n\", float64(after.User-before.User)/total*100)\n\tfmt.Printf(\"cpu system: %f %%\\n\", float64(after.System-before.System)/total*100)\n\tfmt.Printf(\"cpu idle: %f %%\\n\", float64(after.Idle-before.Idle)/total*100)\n}\n```\n\n## LICENSE\n```\nCopyright 2017-2019 Hatena Co., Ltd.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackerelio%2Fgo-osstat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmackerelio%2Fgo-osstat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackerelio%2Fgo-osstat/lists"}