arussellsaw.github.io witty tagline

Telemetry

repo

Metrics for your Go applications

I’ve been working on a caching proxy in my free time, for caching KairosDB when used with our Grafana dashboards. In working on this project, i had a thought that it would be great if i could pull out some metrics in order to track performance and usage of the proxy, and thanks to Go’s fantastic packaging/imports model, i had the motivation to make a dedicated library, so that my future projects, and hopefully others can have an easy workflow for metrics and alerting.

Here’s a little snippet that shows how easily you can pull out function timing using telemetry.


package main

import(
    "time"
    "net/http"

    "github.com/arussellsaw/telemetry"
    )

func main() {
    tel, metricsHandler := telemetry.New((5 * time.Second))
    http.HandleFunc("/metrics", metricsHandler.ServeHTTP)
    go http.ListenAndServe(":80", nil)

    tel.Average.New("demo.timing", (60 * time.Second))

    start := time.Now()
    somethingYouWantToTime()
    tel.Average.Add("demo.timing", float32(time.Since(start).Nanoseconds()))
}

The largest utility that telemetry provides is the time constrained metrics, it’s easy enough to echo out increasing counters, but telemetry has a built in metric manager that culls old stats, this allows you to provide ‘per minute’ metrics, meaning it’s very easy to have metrics that work well in things like Grafana.

grafana-dashboard

Please email me or get in contact via twitter if you end up using the library, i’d love to see what other people are doing with my work!