{"id":15019993,"url":"https://github.com/docker/go-metrics","last_synced_at":"2025-05-16T10:06:38.174Z","repository":{"id":10245144,"uuid":"65046945","full_name":"docker/go-metrics","owner":"docker","description":"Package for metrics collection in Docker projects","archived":false,"fork":false,"pushed_at":"2023-03-08T10:26:48.000Z","size":1745,"stargazers_count":88,"open_issues_count":6,"forks_count":32,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-03T01:04:39.927Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2016-08-05T20:27:11.000Z","updated_at":"2025-02-28T03:01:56.000Z","dependencies_parsed_at":"2024-06-18T12:37:09.655Z","dependency_job_id":"19325e28-dceb-4720-b830-230eeaa956a0","html_url":"https://github.com/docker/go-metrics","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/docker%2Fgo-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker%2Fgo-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker%2Fgo-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker%2Fgo-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docker","download_url":"https://codeload.github.com/docker/go-metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254040584,"owners_count":22004571,"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-09-24T19:54:26.395Z","updated_at":"2025-05-16T10:06:38.155Z","avatar_url":"https://github.com/docker.png","language":"Go","readme":"# go-metrics [![GoDoc](https://godoc.org/github.com/docker/go-metrics?status.svg)](https://godoc.org/github.com/docker/go-metrics) ![Badge Badge](http://doyouevenbadge.com/github.com/docker/go-metrics)\n\nThis package is small wrapper around the prometheus go client to help enforce convention and best practices for metrics collection in Docker projects.\n\n## Best Practices\n\nThis packages is meant to be used for collecting metrics in Docker projects.\nIt is not meant to be used as a replacement for the prometheus client but to help enforce consistent naming across metrics collected.\nIf you have not already read the prometheus best practices around naming and labels you can read the page [here](https://prometheus.io/docs/practices/naming/).\n\nThe following are a few Docker specific rules that will help you name and work with metrics in your project.\n\n1. Namespace and Subsystem\n\nThis package provides you with a namespace type that allows you to specify the same namespace and subsystem for your metrics.\n\n```go\nns := metrics.NewNamespace(\"engine\", \"daemon\", metrics.Labels{\n        \"version\": dockerversion.Version,\n        \"commit\":  dockerversion.GitCommit,\n})\n```\n\nIn the example above we are creating metrics for the Docker engine's daemon package.\n`engine` would be the namespace in this example where `daemon` is the subsystem or package where we are collecting the metrics.\n\nA namespace also allows you to attach constant labels to the metrics such as the git commit and version that it is collecting.\n\n2. Declaring your Metrics\n\nTry to keep all your metric declarations in one file.\nThis makes it easy for others to see what constant labels are defined on the namespace and what labels are defined on the metrics when they are created.\n\n3. Use labels instead of multiple metrics\n\nLabels allow you to define one metric such as the time it takes to perform a certain action on an object.\nIf we wanted to collect timings on various container actions such as create, start, and delete then we can define one metric called `container_actions` and use labels to specify the type of action.\n\n\n```go\ncontainerActions = ns.NewLabeledTimer(\"container_actions\", \"The number of milliseconds it takes to process each container action\", \"action\")\n```\n\nThe last parameter is the label name or key.\nWhen adding a data point to the metric you will use the `WithValues` function to specify the `action` that you are collecting for.\n\n```go\ncontainerActions.WithValues(\"create\").UpdateSince(start)\n```\n\n4. Always use a unit\n\nThe metric name should describe what you are measuring but you also need to provide the unit that it is being measured with.\nFor a timer, the standard unit is seconds and a counter's standard unit is a total.\nFor gauges you must provide the unit.\nThis package provides a standard set of units for use within the Docker projects.\n\n```go\nNanoseconds Unit = \"nanoseconds\"\nSeconds     Unit = \"seconds\"\nBytes       Unit = \"bytes\"\nTotal       Unit = \"total\"\n```\n\nIf you need to use a unit but it is not defined in the package please open a PR to add it but first try to see if one of the already created units will work for your metric, i.e. seconds or nanoseconds vs adding milliseconds.\n\n## Docs\n\nPackage documentation can be found [here](https://godoc.org/github.com/docker/go-metrics).\n\n## HTTP Metrics\n\nTo instrument a http handler, you can wrap the code like this:\n\n```go\nnamespace := metrics.NewNamespace(\"docker_distribution\", \"http\", metrics.Labels{\"handler\": \"your_http_handler_name\"})\nhttpMetrics := namespace.NewDefaultHttpMetrics()\nmetrics.Register(namespace)\ninstrumentedHandler = metrics.InstrumentHandler(httpMetrics, unInstrumentedHandler)\n```\nNote: The `handler` label must be provided when a new namespace is created.\n\n## Additional Metrics\n\nAdditional metrics are also defined here that are not available in the prometheus client.\nIf you need a custom metrics and it is generic enough to be used by multiple projects, define it here.\n\n\n## Copyright and license\n\nCopyright © 2016 Docker, Inc. All rights reserved, except as follows. Code is released under the Apache 2.0 license. The README.md file, and files in the \"docs\" folder are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file \"LICENSE.docs\". You may obtain a duplicate copy of the same license, titled CC-BY-SA-4.0, at http://creativecommons.org/licenses/by/4.0/.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocker%2Fgo-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocker%2Fgo-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocker%2Fgo-metrics/lists"}