Skip to content

Pusher send metrics to Prometheus Push Server using HTTP post request

License

Notifications You must be signed in to change notification settings

kirill-scherba/pusher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pusher

Pusher send metrics to Prometheus Push Server using http post request. This package has not any external dependencies and use only standard go librarie.

GoDoc Go Report Card

Usage example

The sample code below show all this package capabilities. Just create new pusher and send any methrics.

// Initialize random
rand.Seed(time.Now().Unix())

// Get this host name
hostName, err := os.Hostname()
if err != nil {
    log.Fatalln("can't get host name error: ", err)
}

// Create publisher
pusher := pusher.NewPusher("http://example.com:9091", "my_job", hostName)

// Push metrics every 15 seconds
for {
    m, err := pusher.Push(
        pusher.Metric("my_job_couner_2", rand.Float64()*10),
        pusher.Metric("my_job_couner_3", rand.Float64()*10),
        pusher.Metric("my_job_couner_4{label=\"val1\"}", rand.Float64()*100),
        pusher.Metric("my_job_couner_4{label=\"val2\"}", rand.Float64()*100),
    )
    if err != nil {
        log.Println("push error: ", err)
    } else {
        log.Println("push metrics:\n" + m)
    }
    time.Sleep(15 * time.Second)
}

You can find complete packets documentation at: https://pkg.go.dev/github.com/kirill-scherba/pusher


Licence

BSD