2020-04-06 19:57:19 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2020-04-18 23:21:25 +08:00
|
|
|
"gitlab.com/unitechdev/golib/metric"
|
2020-04-06 19:57:19 +08:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var callCounter = metric.NewCounterVec(
|
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
|
Namespace: "crm",
|
|
|
|
|
Name: "call_total_count2",
|
|
|
|
|
Help: "Total Request",
|
|
|
|
|
},
|
|
|
|
|
[]string{"privilege", "uri"},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func test2() {
|
|
|
|
|
pusher := metric.InitPusher("http://ops-dev.a.mobimagic.com:9091", "MetricsExample3", prometheus.Labels{})
|
|
|
|
|
|
|
|
|
|
pusher.Collector(callCounter).Add()
|
|
|
|
|
pusher.Push()
|
|
|
|
|
//pusher.Push(callCounter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
//test2()
|
|
|
|
|
|
|
|
|
|
var labels = prometheus.Labels{"app": "app2",
|
|
|
|
|
"country": "INDIA",
|
|
|
|
|
"service": "test2",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pushGateway, job = "http://ops-dev.a.mobimagic.com:9091", "app2"
|
|
|
|
|
|
|
|
|
|
//fmt.Println("labels:", labels)
|
|
|
|
|
metric.InitDefaultPusher(pushGateway, job, labels)
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
callCounter.With(prometheus.Labels{"privilege": "test", "uri": "xxxxx/sswwe"}).Inc()
|
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
|
fmt.Println("Inc 1")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|