{"id":13530223,"url":"https://github.com/tevjef/go-runtime-metrics","last_synced_at":"2025-04-01T17:32:15.652Z","repository":{"id":57481072,"uuid":"75533199","full_name":"tevjef/go-runtime-metrics","owner":"tevjef","description":"Collect golang runtime metrics, pushing to InfluxDB or pulling with Telegraf","archived":false,"fork":false,"pushed_at":"2018-02-04T21:10:17.000Z","size":449,"stargazers_count":284,"open_issues_count":5,"forks_count":37,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-02T07:11:17.767Z","etag":null,"topics":["expvars","golang","golang-library","influxdb","runtime-metrics","telegraf"],"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/tevjef.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}},"created_at":"2016-12-04T11:25:49.000Z","updated_at":"2024-07-12T12:17:52.000Z","dependencies_parsed_at":"2022-09-26T17:41:25.363Z","dependency_job_id":null,"html_url":"https://github.com/tevjef/go-runtime-metrics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevjef%2Fgo-runtime-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevjef%2Fgo-runtime-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevjef%2Fgo-runtime-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tevjef%2Fgo-runtime-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tevjef","download_url":"https://codeload.github.com/tevjef/go-runtime-metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222748348,"owners_count":17031898,"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":["expvars","golang","golang-library","influxdb","runtime-metrics","telegraf"],"created_at":"2024-08-01T07:00:46.123Z","updated_at":"2024-11-02T16:31:52.173Z","avatar_url":"https://github.com/tevjef.png","language":"Go","funding_links":[],"categories":["Collecting data into InfluxDB","Go"],"sub_categories":["Libraries"],"readme":"# go-runtime-metrics\nCollect golang runtime metrics, pushing to [InfluxDB](https://www.influxdata.com/time-series-platform/influxdb/) or pulling with [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/). Inspired by https://github.com/bmhatfield/go-runtime-metrics\n\n## Installation\n\n    go get -u github.com/tevjef/go-runtime-metrics\n    \n## Push Usage\n\nThis library can be configured to push metrics directly to InfluxDB.\n\n```go\nimport (\n\tmetrics \"github.com/tevjef/go-runtime-metrics\"\n)\n\nfunc main() {\n\terr := metrics.RunCollector(metrics.DefaultConfig)\n\t\n\tif err != nil {\n\t   // handle error\n\t}\n}\n\t\n```\n\nOnce imported and running, you can expect a number of Go runtime metrics to be sent to InfluxDB. \nAn example of what this looks like when configured to work with [Grafana](http://grafana.org/):\n\n![](/grafana.png)\n\n[Download Dashboard](https://grafana.net/dashboards/1144)\n\n## Pull Usage via [expvar](https://golang.org/pkg/expvar/)\n\nPackage [expvar](https://golang.org/pkg/expvar/) provides a standardized interface to public variables. This library provides an exported InfluxDB formatted variable with a few other benefits: \n\n* Metric names are easily parsed by regexp.\n* Lighter than the standard library memstat expvar\n* Includes stats for `cpu.cgo_calls`, `cpu.goroutines` and timing of the last GC pause with `mem.gc.pause`.\n* Works out the box with Telegraf's [InfluxDB input plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/influxdb)\n\nImport this library's expvar package with `import _ \"github.com/tevjef/go-runtime-metrics/expvar\"` to export a variable with default configurations.\n```json\n{\n  \"/go/bin/binary\": {\n    \"name\": \"go_runtime_metrics\",\n    \"tags\": {\n      \"go.arch\": \"amd64\",\n      \"go.os\": \"darwin\",\n      \"go.version\": \"go1.7.4\"\n    },\n    \"values\": {\n      \"cpu.count\": 4,\n      \"cpu.cgo_calls\": 1,\n      \"cpu.goroutines\": 2,\n      \"mem.alloc\": 667576,\n      \"mem.frees\": 104,\n      \"mem.gc.count\": 0,\n      \"mem.gc.last\": 0,\n      \"mem.gc.next\": 4194304,\n      \"mem.gc.pause\": 0,\n      \"mem.gc.pause_total\": 0,\n      \"mem.gc.sys\": 65536,\n      \"mem.heap.alloc\": 667576,\n      \"mem.heap.idle\": 475136,\n      \"mem.heap.inuse\": 1327104,\n      \"mem.heap.objects\": 5227,\n      \"mem.heap.released\": 0,\n      \"mem.heap.sys\": 1802240,\n      \"mem.lookups\": 3,\n      \"mem.malloc\": 5331,\n      \"mem.othersys\": 820558,\n      \"mem.stack.inuse\": 294912,\n      \"mem.stack.mcache_inuse\": 4800,\n      \"mem.stack.mcache_sys\": 16384,\n      \"mem.stack.mspan_inuse\": 14160,\n      \"mem.stack.mspan_sys\": 16384,\n      \"mem.stack.sys\": 294912,\n      \"mem.sys\": 3018752,\n      \"mem.total\": 667576\n    }\n  }\n}\n```\n\n#### Configuring with [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/)\n\nYour program must import `_ \"github.com/tevjef/go-runtime-metrics/expvar` in order for an InfluxDB formatted variable to be exported via `/debug/vars`.\n\n1. [Install Telegraf](https://github.com/influxdata/telegraf#installation)\n\n2. Make a config file utilizing the influxdb input plugin and an output plugin of your choice.\n\n    ```toml\n    [[inputs.influxdb]]\n      urls = [\"http://localhost:6060/debug/vars\"]\n    \n    [[outputs.influxdb]]\n      urls = [\"http://localhost:8086\"]\n      ## The target database for metrics (telegraf will create it if not exists).\n      database = \"stats\" # required\n      \n    ## [[outputs.file]]\n    ##   files = [\"stdout\"]\n    ##   data_format = \"json\"\n    ```\n\n3. Start the Telegraf agent with `telegraf -config config.conf`\n\n\n#### Benchmarks\n\nBenchmark against standard library memstat expvar: \n```\n$ go test -bench=. -parallel 16 -cpu 1,2,4\n\nBenchmarkMetrics          100000             12456 ns/op            4226 B/op         21 allocs/op\nBenchmarkMetrics-2         20000             63597 ns/op            4264 B/op         21 allocs/op\nBenchmarkMetrics-4         50000             28797 ns/op            4266 B/op         21 allocs/op\nBenchmarkMemstat           20000             78009 ns/op           52264 B/op         12 allocs/op\nBenchmarkMemstat-2         10000            155930 ns/op           52264 B/op         12 allocs/op\nBenchmarkMemstat-4         10000            144849 ns/op           52266 B/op         12 allocs/op\n\n```\n\n\n```\n  System Info: \n\n  Processor Name:\tIntel Core i5\n  Processor Speed:\t3.5 GHz\n  Number of Processors:\t1\n  Total Number of Cores:\t4\n  L2 Cache (per Core):\t256 KB\n  L3 Cache:\t6 MB\n  Memory:\t32 GB\n  Bus Speed:\t400 MHz\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftevjef%2Fgo-runtime-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftevjef%2Fgo-runtime-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftevjef%2Fgo-runtime-metrics/lists"}