Skip to content

Go package for collecting and sending metrics to a trap check

License

Notifications You must be signed in to change notification settings

circonus-labs/go-trapmetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package go-trapmetrics

Go Reference

A simplified, streamlined, and updated replacement for circonus-gometrics. Covers basic functionality for collecting and submitting metrics to Circonus.

package main

import (
    "fmt"

    apiclient "github.com/circonus-labs/go-apiclient"
    trapcheck "github.com/circonus-labs/go-trapcheck"
    trapmetrics "github.com/circonus-labs/go-trapmetrics"
)

func main() {

    client, err := apiclient.New(&apiclient.Config{/* ...settings... */})
    if err != nil {
        panic(err)
    }

    check, err := trapcheck.New(&trapcheck.Config{Client: client, /* ...other settings... */})
    if err != nil {
        panic(err)
    }

    metrics, err := trapmetrics.New(&trapmetrics.Config{Check: check, /* ...other settings...*/})
    if err != nil {
        panic(err)
    }

    // NOTE: gauges and text take an optional timestamp for the sample, pass nil to use current time
    ts := time.Now()    
    metrics.GaugeSet("gauge",trapmetrics.Tags{{Category:"a",Value:"b"}},123,&ts)
    metrics.TextSet("text",nil,"some text",nil)

    // Counters and histograms will apply a timestamp at the time of flushing as they only contain
    // one stample and it is mutable until flush time.
    metrics.CounterIncrement("counter",trapmetrics.Tags{{Cateogry:"a",Value:"b"}})
    metrics.HistogramRecordValue("histogram",nil,27)
    metrics.CumulativeHistogramRecordCountForValue("cumulative_histogram",nil,128,3.6)

    result, err := metrics.Flush()
    if err != nil {
        panic(err)
    }

    fmt.Println(result)
}

About

Go package for collecting and sending metrics to a trap check

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages