DockerCLI/vendor/github.com/docker/go-metrics
Mathieu Champlon 5d54584f03 Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9
Also bringing:
. golang.org/x/net 5561cd9b4330353950f399814f427425c0a26fd2
. github.com/docker/distribution 83389a148052d74ac602f5f1d62f86ff2f3c4aa5
. github.com/docker/swarmkit bd69f6e8e301645afd344913fa1ede53a0a111fb
. github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a24426ee7ef18
. github.com/prometheus/client_golang 52437c81da6b127a9925d17eb3a382a2e5fd395e
. github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
. github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6
. github.com/prometheus/common ebdfc6da46522d58825777cf1f90490a5b1ef1d8
. github.com/prometheus/procfs abf152e5f3e97f2fafac028d2cc06c1feb87ffa5
. github.com/matttproud/golang_protobuf_extensions v1.0.0

Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
2018-05-18 11:44:14 +02:00
..
LICENSE.code Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
LICENSE.docs Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
NOTICE Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
README.md Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
counter.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
docs.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
gauge.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
handler.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
helpers.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
namespace.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
register.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
timer.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00
unit.go Bump moby to d37f5c6bdf788a6cb82c07fb707e31a240eff5f9 2018-05-18 11:44:14 +02:00

README.md

go-metrics GoDoc Badge Badge

This package is small wrapper around the prometheus go client to help enforce convention and best practices for metrics collection in Docker projects.

Best Practices

This packages is meant to be used for collecting metrics in Docker projects. It is not meant to be used as a replacement for the prometheus client but to help enforce consistent naming across metrics collected. If you have not already read the prometheus best practices around naming and labels you can read the page here.

The following are a few Docker specific rules that will help you name and work with metrics in your project.

  1. Namespace and Subsystem

This package provides you with a namespace type that allows you to specify the same namespace and subsystem for your metrics.

ns := metrics.NewNamespace("engine", "daemon", metrics.Labels{
        "version": dockerversion.Version,
        "commit":  dockerversion.GitCommit,
})

In the example above we are creating metrics for the Docker engine's daemon package. engine would be the namespace in this example where daemon is the subsystem or package where we are collecting the metrics.

A namespace also allows you to attach constant labels to the metrics such as the git commit and version that it is collecting.

  1. Declaring your Metrics

Try to keep all your metric declarations in one file. This 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.

  1. Use labels instead of multiple metrics

Labels allow you to define one metric such as the time it takes to perform a certain action on an object. If 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.

containerActions = ns.NewLabeledTimer("container_actions", "The number of milliseconds it takes to process each container action", "action")

The last parameter is the label name or key. When adding a data point to the metric you will use the WithValues function to specify the action that you are collecting for.

containerActions.WithValues("create").UpdateSince(start)
  1. Always use a unit

The metric name should describe what you are measuring but you also need to provide the unit that it is being measured with. For a timer, the standard unit is seconds and a counter's standard unit is a total. For gauges you must provide the unit. This package provides a standard set of units for use within the Docker projects.

Nanoseconds Unit = "nanoseconds"
Seconds     Unit = "seconds"
Bytes       Unit = "bytes"
Total       Unit = "total"

If 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.

Docs

Package documentation can be found here.

Additional Metrics

Additional metrics are also defined here that are not avaliable in the prometheus client. If you need a custom metrics and it is generic enough to be used by multiple projects, define it here.

Copyright © 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/.