Skip to content

Instantly share code, notes, and snippets.

@WakeupTsai
Created June 12, 2018 03:29
Show Gist options
  • Save WakeupTsai/b9eb8590528529030f4f69ce83009d7a to your computer and use it in GitHub Desktop.
Save WakeupTsai/b9eb8590528529030f4f69ce83009d7a to your computer and use it in GitHub Desktop.
Client for prometheus example
package main
import (
"fmt"
"reflect"
"time"
"github.com/prometheus/client_golang/api"
prometheus "github.com/prometheus/client_golang/api/prometheus/v1"
"golang.org/x/net/context"
)
func main() {
metrick := `sum by(pod_name)(container_memory_usage_bytes{namespace="kube-system"})`
conf := api.Config{
Address: "http://192.168.64.14:30003",
RoundTripper: api.DefaultRoundTripper,
}
client, err := api.NewClient(conf)
if err != nil {
fmt.Printf("Error while creating api.NewClient %s", err)
}
testTime := time.Now()
api := prometheus.NewAPI(client)
q, _ := api.Query(context.Background(), metrick, testTime)
fmt.Println(reflect.TypeOf(q))
fmt.Println(q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment