Created
April 17, 2019 20:49
-
-
Save maurorappa/d9481313a87f911832f60ecbf95e8017 to your computer and use it in GitHub Desktop.
Prometheus client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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