Skip to content

Instantly share code, notes, and snippets.

@maurorappa
Created April 17, 2019 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurorappa/d9481313a87f911832f60ecbf95e8017 to your computer and use it in GitHub Desktop.
Save maurorappa/d9481313a87f911832f60ecbf95e8017 to your computer and use it in GitHub Desktop.
Prometheus client
package main
import (
"context"
"fmt"
"time"
"github.com/prometheus/client_golang/api"
"github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
)
func main() {
client, err := api.NewClient(api.Config{Address: "http://192.168.0.89:9090"})
if err != nil {
fmt.Printf("%s",err )
}
step, _ := time.ParseDuration("15s")
queryAPI := v1.NewAPI(client)
Range := v1.Range{
Start: time.Now().Add(-time.Hour * 24 ),
End: time.Now(),
Step: step,
}
values, err := queryAPI.QueryRange(context.Background(), "up{job=\"greenhouse\"}", Range)
if err != nil {
fmt.Printf("%s",err )
}
fmt.Printf("%s\n",values )
if values.Type() == model.ValVector {
if vector, ok := values.(model.Vector); ok {
for _, sample := range vector {
fmt.Printf("%s\n",sample )
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment