38 lines
750 B
Go
38 lines
750 B
Go
|
package prom
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/prometheus/client_golang/prometheus"
|
||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||
|
"math/rand"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestRawProm(t *testing.T) {
|
||
|
vec := prometheus.NewHistogramVec(
|
||
|
prometheus.HistogramOpts{
|
||
|
Name: "test",
|
||
|
Help: "test help",
|
||
|
Buckets: []float64{1, 50, 100},
|
||
|
},
|
||
|
[]string{"app"},
|
||
|
)
|
||
|
prometheus.MustRegister(vec)
|
||
|
|
||
|
go func() {
|
||
|
for i := 0; i < 1000; i++ {
|
||
|
vec.WithLabelValues("battle").Observe(float64(rand.Intn(100)))
|
||
|
time.Sleep(time.Second)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
gin.SetMode(gin.ReleaseMode)
|
||
|
engine := gin.Default()
|
||
|
engine.GET("/metrics", gin.WrapH(promhttp.Handler()))
|
||
|
err := engine.Run(":12345")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|