micro/metrics/prometheus
Prawn 2998735bf3
Tidying up the new Metrics implementations (#1974)
* Unit tests to check tagging and aggregation of Prometheus metrics

* Removing the logger output routing (because it doesn't actually work in the logger implementation)

* Emitting values with the logging reporter

Co-authored-by: chris <chris@Profanity.local>
2020-08-27 09:08:51 +01:00
..
metric_family.go Observability/metrics update (#1962) 2020-08-21 20:57:10 +12:00
metrics.go Metrics interface and Prometheus implementation (#1929) 2020-08-18 08:27:50 +01:00
README.md Metrics interface and Prometheus implementation (#1929) 2020-08-18 08:27:50 +01:00
reporter_test.go Tidying up the new Metrics implementations (#1974) 2020-08-27 09:08:51 +01:00
reporter.go Observability/metrics update (#1962) 2020-08-21 20:57:10 +12:00

Prometheus

A Prometheus "pull" based implementation of the metrics Reporter interface.

Capabilities

  • Go runtime metrics are handled natively by the Prometheus client library (CPU / MEM / GC / GoRoutines etc).
  • User-defined metrics are registered in the Prometheus client dynamically (they must be pre-registered, hence all of the faffing around in metric_family.go).
  • The metrics are made available on a Prometheus-compatible HTTP endpoint, which can be scraped at any time. This means that the user can very easily access stats even running locally as a standalone binary.
  • Requires a micro.Server parameter (from which it gathers the service name and version). These are included as tags with every metric.

Usage

    prometheusReporter := metrics.New(server)
    tags := metrics.Tags{"greeter": "Janos"}
    err := prometheusReporter.Count("hellos", 1, tags)
    if err != nil {
        fmt.Printf("Error setting a Count metric: %v", err)
    }