{"id":16838507,"url":"https://github.com/zserge/metric","last_synced_at":"2025-04-06T02:09:58.573Z","repository":{"id":57483414,"uuid":"134559360","full_name":"zserge/metric","owner":"zserge","description":"Minimal metrics for Go (counter/gauge/histogram). No dependencies. Compatible with expvar. Web UI included.","archived":false,"fork":false,"pushed_at":"2019-12-20T04:43:31.000Z","size":108,"stargazers_count":358,"open_issues_count":4,"forks_count":27,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T01:09:44.025Z","etag":null,"topics":["counter","gauge","histogram","metrics","minimal"],"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/zserge.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":"2018-05-23T11:25:51.000Z","updated_at":"2025-02-11T21:34:04.000Z","dependencies_parsed_at":"2022-08-27T20:02:28.056Z","dependency_job_id":null,"html_url":"https://github.com/zserge/metric","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fmetric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fmetric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fmetric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fmetric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zserge","download_url":"https://codeload.github.com/zserge/metric/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"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":["counter","gauge","histogram","metrics","minimal"],"created_at":"2024-10-13T12:23:59.858Z","updated_at":"2025-04-06T02:09:58.538Z","avatar_url":"https://github.com/zserge.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# metric\n\n[![Build Status](https://travis-ci.org/zserge/metric.svg?branch=master)](https://travis-ci.org/zserge/metric)\n[![GoDoc](https://godoc.org/github.com/zserge/metric?status.svg)](https://godoc.org/github.com/zserge/metric)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zserge/metric)](https://goreportcard.com/report/github.com/zserge/metric)\n\nPackage provides simple uniform interface for metrics such as counters,\ngauges and histograms. It keeps track of metrics in runtime and can be used for\nsome basic web service instrumentation in Go, where complex tools such as\nPrometheus or InfluxDB are not required.\n\nIt is compatible with [expvar](https://golang.org/pkg/expvar/) package, that is\nalso commonly used for monitoring.\n\n## Usage\n\n```go\n// Create new metric. All metrics may take time frames if you want them to keep\n// history. If no time frames are given the metric only keeps track of a single\n// current value.\nc := metric.NewCounter(\"15m10s\") // 15 minutes of history with 10 second precision\n// Increment counter\nc.Add(1)\n// Return JSON with all recorded counter values\nc.String() // Or json.Marshal(c)\n\n// With expvar\n\n// Register a metric\nexpvar.Publish(\"latency\", metric.NewHistogram(\"5m1s\", \"15m30s\", \"1h1m\"))\n// Register HTTP handler to visualize metrics\nhttp.Handle(\"/debug/metrics\", metric.Handler(metric.Exposed))\n\n// Measure time and update the metric\nstart := time.Now()\n...\nexpvar.Get(\"latency\").(metric.Metric).Add(time.Since(start).Seconds())\n```\n\nMetrics are thread-safe and can be updated from background goroutines.\n\n## Web UI\n\nNothing fancy, really, but still better than reading plain JSON. No javascript,\nonly good old HTML, CSS and SVG.\n\n![web ui](example/screenshot.png)\n\nOf course you may customize a list of metrics to show in the web UI.\n\nIf you need precise values - you may use `/debug/vars` HTTP endpoint provided\nby `expvar`.\n\n## License\n\nCode is distributed under MIT license, feel free to use it in your proprietary\nprojects as well.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Fmetric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzserge%2Fmetric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Fmetric/lists"}