{"id":13564485,"url":"https://github.com/rcrowley/go-metrics","last_synced_at":"2025-04-08T19:18:51.515Z","repository":{"id":1896766,"uuid":"2823239","full_name":"rcrowley/go-metrics","owner":"rcrowley","description":"Go port of Coda Hale's Metrics library","archived":false,"fork":false,"pushed_at":"2023-08-19T15:34:44.000Z","size":1301,"stargazers_count":3474,"open_issues_count":80,"forks_count":494,"subscribers_count":84,"default_branch":"master","last_synced_at":"2025-03-31T18:07:16.895Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/rcrowley.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":"2011-11-21T21:35:09.000Z","updated_at":"2025-03-15T06:29:50.000Z","dependencies_parsed_at":"2022-07-20T14:17:39.560Z","dependency_job_id":"d82c3615-47bb-463f-b79b-0ccdd5a88eb6","html_url":"https://github.com/rcrowley/go-metrics","commit_stats":{"total_commits":312,"total_committers":85,"mean_commits":"3.6705882352941175","dds":0.5128205128205128,"last_synced_commit":"cf1acfcdf4751e0554ffa765d03e479ec491cad6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowley%2Fgo-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowley%2Fgo-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowley%2Fgo-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowley%2Fgo-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcrowley","download_url":"https://codeload.github.com/rcrowley/go-metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247909202,"owners_count":21016479,"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":[],"created_at":"2024-08-01T13:01:32.056Z","updated_at":"2025-04-08T19:18:51.507Z","avatar_url":"https://github.com/rcrowley.png","language":"Go","funding_links":[],"categories":["Software Packages","Go","💻 项目实战","软件包","DevOps Tools"],"sub_categories":["DevOps Tools","💾 Redis","DevOps工具","Contents"],"readme":"go-metrics\n==========\n\n![travis build status](https://travis-ci.org/rcrowley/go-metrics.svg?branch=master)\n\nGo port of Coda Hale's Metrics library: \u003chttps://github.com/dropwizard/metrics\u003e.\n\nDocumentation: \u003chttp://godoc.org/github.com/rcrowley/go-metrics\u003e.\n\nArchived as of April 1 2025\n-----\nThis repository is no longer maintained. The authors recommend you explore the\nfollowing newer, more widely adopted libraries for your Go instrumentation\nneeds:\n\n* [OpenTelemetry Go SDK](https://opentelemetry.io/docs/languages/go/instrumentation/#metrics)\n* [Prometheus Go Client Library](https://pkg.go.dev/github.com/prometheus/client_golang/prometheus)\n\nUsage\n-----\n\nCreate and update metrics:\n\n```go\nc := metrics.NewCounter()\nmetrics.Register(\"foo\", c)\nc.Inc(47)\n\ng := metrics.NewGauge()\nmetrics.Register(\"bar\", g)\ng.Update(47)\n\nr := NewRegistry()\ng := metrics.NewRegisteredFunctionalGauge(\"cache-evictions\", r, func() int64 { return cache.getEvictionsCount() })\n\ns := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)\nh := metrics.NewHistogram(s)\nmetrics.Register(\"baz\", h)\nh.Update(47)\n\nm := metrics.NewMeter()\nmetrics.Register(\"quux\", m)\nm.Mark(47)\n\nt := metrics.NewTimer()\nmetrics.Register(\"bang\", t)\nt.Time(func() {})\nt.Update(47)\n```\n\nRegister() is not threadsafe. For threadsafe metric registration use\nGetOrRegister:\n\n```go\nt := metrics.GetOrRegisterTimer(\"account.create.latency\", nil)\nt.Time(func() {})\nt.Update(47)\n```\n\n**NOTE:** Be sure to unregister short-lived meters and timers otherwise they will\nleak memory:\n\n```go\n// Will call Stop() on the Meter to allow for garbage collection\nmetrics.Unregister(\"quux\")\n// Or similarly for a Timer that embeds a Meter\nmetrics.Unregister(\"bang\")\n```\n\nPeriodically log every metric in human-readable form to standard error:\n\n```go\ngo metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, \"metrics: \", log.Lmicroseconds))\n```\n\nPeriodically log every metric in slightly-more-parseable form to syslog:\n\n```go\nw, _ := syslog.Dial(\"unixgram\", \"/dev/log\", syslog.LOG_INFO, \"metrics\")\ngo metrics.Syslog(metrics.DefaultRegistry, 60e9, w)\n```\n\nPeriodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite):\n\n```go\n\nimport \"github.com/cyberdelia/go-metrics-graphite\"\n\naddr, _ := net.ResolveTCPAddr(\"tcp\", \"127.0.0.1:2003\")\ngo graphite.Graphite(metrics.DefaultRegistry, 10e9, \"metrics\", addr)\n```\n\nPeriodically emit every metric into InfluxDB:\n\n**NOTE:** this has been pulled out of the library due to constant fluctuations\nin the InfluxDB API. In fact, all client libraries are on their way out. see\nissues [#121](https://github.com/rcrowley/go-metrics/issues/121) and\n[#124](https://github.com/rcrowley/go-metrics/issues/124) for progress and details.\n\n```go\nimport \"github.com/vrischmann/go-metrics-influxdb\"\n\ngo influxdb.InfluxDB(metrics.DefaultRegistry,\n  10e9, \n  \"127.0.0.1:8086\", \n  \"database-name\", \n  \"username\", \n  \"password\"\n)\n```\n\nPeriodically upload every metric to Librato using the [Librato client](https://github.com/mihasya/go-metrics-librato):\n\n**Note**: the client included with this repository under the `librato` package\nhas been deprecated and moved to the repository linked above.\n\n```go\nimport \"github.com/mihasya/go-metrics-librato\"\n\ngo librato.Librato(metrics.DefaultRegistry,\n    10e9,                  // interval\n    \"example@example.com\", // account owner email address\n    \"token\",               // Librato API token\n    \"hostname\",            // source\n    []float64{0.95},       // percentiles to send\n    time.Millisecond,      // time unit\n)\n```\n\nPeriodically emit every metric to StatHat:\n\n```go\nimport \"github.com/rcrowley/go-metrics/stathat\"\n\ngo stathat.Stathat(metrics.DefaultRegistry, 10e9, \"example@example.com\")\n```\n\nMaintain all metrics along with expvars at `/debug/metrics`:\n\nThis uses the same mechanism as [the official expvar](http://golang.org/pkg/expvar/)\nbut exposed under `/debug/metrics`, which shows a json representation of all your usual expvars\nas well as all your go-metrics.\n\n\n```go\nimport \"github.com/rcrowley/go-metrics/exp\"\n\nexp.Exp(metrics.DefaultRegistry)\n```\n\nInstallation\n------------\n\n```sh\ngo get github.com/rcrowley/go-metrics\n```\n\nStatHat support additionally requires their Go client:\n\n```sh\ngo get github.com/stathat/go\n```\n\nPublishing Metrics\n------------------\n\nClients are available for the following destinations:\n\n* AppOptics - https://github.com/ysamlan/go-metrics-appoptics\n* Librato - https://github.com/mihasya/go-metrics-librato\n* Graphite - https://github.com/cyberdelia/go-metrics-graphite\n* InfluxDB - https://github.com/vrischmann/go-metrics-influxdb\n* Ganglia - https://github.com/appscode/metlia\n* Prometheus - https://github.com/deathowl/go-metrics-prometheus\n* DataDog - https://github.com/syntaqx/go-metrics-datadog\n* SignalFX - https://github.com/pascallouisperez/go-metrics-signalfx\n* Honeycomb - https://github.com/getspine/go-metrics-honeycomb\n* Wavefront - https://github.com/wavefrontHQ/go-metrics-wavefront\n* Open-Falcon - https://github.com/g4zhuj/go-metrics-falcon\n* AWS CloudWatch - [https://github.com/savaki/cloudmetrics](https://github.com/savaki/cloudmetrics)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcrowley%2Fgo-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcrowley%2Fgo-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcrowley%2Fgo-metrics/lists"}