{"id":22368351,"url":"https://github.com/olexnzarov/processinfo","last_synced_at":"2025-03-26T16:12:45.776Z","repository":{"id":196863650,"uuid":"697324259","full_name":"olexnzarov/processinfo","owner":"olexnzarov","description":"A package that lets you get overall CPU utilization and memory usage of a process","archived":false,"fork":false,"pushed_at":"2023-09-27T14:06:52.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T17:53:16.781Z","etag":null,"topics":["cpu-usage","crossplatform","memory-usage","pidusage","proc-pid-stat","proc-stat"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olexnzarov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-27T13:53:20.000Z","updated_at":"2023-09-27T14:15:41.000Z","dependencies_parsed_at":"2023-09-28T00:41:56.002Z","dependency_job_id":null,"html_url":"https://github.com/olexnzarov/processinfo","commit_stats":null,"previous_names":["olexnzarov/processinfo"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olexnzarov%2Fprocessinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olexnzarov%2Fprocessinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olexnzarov%2Fprocessinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olexnzarov%2Fprocessinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olexnzarov","download_url":"https://codeload.github.com/olexnzarov/processinfo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245689511,"owners_count":20656417,"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":["cpu-usage","crossplatform","memory-usage","pidusage","proc-pid-stat","proc-stat"],"created_at":"2024-12-04T18:29:03.726Z","updated_at":"2025-03-26T16:12:45.741Z","avatar_url":"https://github.com/olexnzarov.png","language":"Go","readme":"# processinfo [![GoDoc](https://pkg.go.dev/badge/github.com/olexnzarov/processinfo)](https://pkg.go.dev/github.com/olexnzarov/processinfo) [![Github release](https://img.shields.io/github/release/olexnzarov/processinfo.svg)](https://github.com/olexnzarov/processinfo/releases) [![Test status](https://github.com/olexnzarov/processinfo/actions/workflows/tests.yml/badge.svg)](https://github.com/olexnzarov/processinfo/actions/workflows/tests.yml)\r\n\r\nprocessinfo is a package that lets you get process stats, such as overall CPU utilization and memory usage.\r\n\r\n**Features**\r\n\r\n- Ability to get process information every N seconds.\r\n- Easy-to-use interface.\r\n- Supports Linux and Windows. \r\n\r\n## Installation\r\n\r\n```sh\r\ngo get github.com/olexnzarov/processinfo\r\n```\r\n\r\n## Usage\r\n\r\n```go\r\nfunc GetMemoryUsage(pid int) (uint64, error) {\r\n  return processinfo.Get(pid).Memory\r\n}\r\n\r\n// This is a preferred way of getting accurate overall CPU usage of a process.\r\n// This function will return an average for the given time duration.\r\n// It will also block the execution for 'sampleTime' duration.\r\nfunc GetAverageProcessorUsage(pid int, sampleTime time.Duration) float64 {\r\n  ctx, cancel := context.WithCancel(context.Background())\r\n  defer cancel()\r\n  infoChannel := processinfo.NewSampler(ctx, pid, sampleTime)\r\n  \u003c-infoChannel\r\n  info := \u003c-infoChannel\r\n  return info.CPU\r\n}\r\n\r\n// Print process information every 5 seconds until the context ends.\r\nfunc WatchProcess(ctx context.Context, pid int) {\r\n  infoChannel := processinfo.NewSampler(ctx, pid, time.Second * 5)\r\n  for info := range infoChannel {\r\n    fmt.Printf(\"Process %d:\\n  CPU: %.2f%%\\n  Memory: %dbytes\\n\", pid, info.CPU, info.Memory)\r\n  }\r\n}\r\n```\r\n\r\n## Examples\r\n\r\nThis package was created for use in [gofu](https://github.com/olexnzarov/gofu), a modern process manager. Check it out for examples on how to use this package.\r\n\r\n## License\r\n\r\nThis code is available under the MIT license, allowing for free use, modification, and distribution.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folexnzarov%2Fprocessinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folexnzarov%2Fprocessinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folexnzarov%2Fprocessinfo/lists"}