Created
April 13, 2019 00:15
-
-
Save fivesheep/8fca998717ab4b54ec73428e7c39812a to your computer and use it in GitHub Desktop.
promethues histograms with negative bounds
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 ( | |
"fmt" | |
"github.com/prometheus/client_golang/prometheus" | |
"github.com/prometheus/client_golang/prometheus/promhttp" | |
"io/ioutil" | |
"log" | |
"math/rand" | |
"net/http" | |
"time" | |
) | |
func main() { | |
rand.Seed(time.Now().Unix()) | |
http.Handle("/metrics", promhttp.Handler()) | |
histogram := prometheus.NewHistogram( | |
prometheus.HistogramOpts{ | |
Namespace: "foo", | |
Name: "bar", | |
Help: "This is my histogram with negative bounds", | |
Buckets: []float64{-10,-5,0,5,10}, | |
}) | |
prometheus.MustRegister(histogram) | |
go func() { | |
for { | |
histogram.Observe(rand.NormFloat64()*100) | |
time.Sleep(time.Millisecond) | |
} | |
}() | |
go func() { | |
for { | |
time.Sleep(10*time.Second) | |
resp, _ := http.Get("http://127.0.0.1:40800/metrics") | |
data, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println(string(data)) | |
//os.Exit(0) | |
} | |
}() | |
log.Fatal(http.ListenAndServe("127.0.0.1:40800", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment