Skip to content

Latest commit

 

History

History
79 lines (51 loc) · 2.45 KB

metrics.md

File metadata and controls

79 lines (51 loc) · 2.45 KB

Metrics

Kooper comes with metrics support, this means that when you use kooper to bootstrap your operator or controller you have the possibility of instrumenting your controller for free.

Backends

At this moment these are the supported backends:

  • Prometheus.

Custom backend

ALthough Kooper supports by default some of the de-facto standard instrumenting backends, you could create your own backend, you just need to implement the provided interface that is named as Recorder:

type Recorder interface {
    ...
}

Measured metrics

The measured metrics are:

  • Number of delete and add queued events (to be processed).
  • Number of delete and add processed events.
  • Number of delete and add processed events with an error.
  • Duration of delete and add processed events.

How to use the recorder with the controller.

When you create a controller you can pass the metrics recorder that you want. Note: If you pass a nil backend, it will not record any metric

If you want a full example, there is a controller example that uses the different metric backends

Prometheus

Prometheus backend needs a prometheus registerer and a namespace (a prefix for the metircs).

For example:

import (
    ...
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
    ...
)

...

    reg := prometheus.NewRegistry()
    m := metrics.NewPrometheus(metricsPrefix, reg)

    ...

    ctrl := controller.NewSequential(30*time.Second, hand, retr, m, log)

    ...

    h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
    logger.Infof("serving metrics at %s", metricsAddr)
    http.ListenAndServe(metricsAddr, h)

    return m
}

If you are using the default prometheus methods instead of a custom registry, you could get that from prometheus.DefaultRegisterer instead of creating a new registry reg := prometheus.NewRegistry()

Grafana dashboard (For Prometheus metrics)

There is a grafana dashboard for your Kubernetes controllers. You can get it here