add grouping
This commit is contained in:
parent
426a77f4cf
commit
93bdc425e5
@ -18,6 +18,7 @@ var (
|
|||||||
metricRegistry *prometheus.Registry = nil
|
metricRegistry *prometheus.Registry = nil
|
||||||
metricApiCounter *prometheus.CounterVec = nil
|
metricApiCounter *prometheus.CounterVec = nil
|
||||||
metricApiSummary *prometheus.SummaryVec = nil
|
metricApiSummary *prometheus.SummaryVec = nil
|
||||||
|
instance string = "--unknown--"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metricExporterHandler struct {
|
type metricExporterHandler struct {
|
||||||
@ -41,7 +42,6 @@ func dumpMetricExporterPusher() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitMetrics(instanceValue string) {
|
func InitMetrics(instanceValue string) {
|
||||||
var instance = instanceValue
|
|
||||||
if instanceValue == "" {
|
if instanceValue == "" {
|
||||||
instance = getInstanceIpAddress()
|
instance = getInstanceIpAddress()
|
||||||
} else if ap := strings.Split(instanceValue, ":"); len(ap) == 2 &&
|
} else if ap := strings.Split(instanceValue, ":"); len(ap) == 2 &&
|
||||||
@ -54,7 +54,7 @@ func InitMetrics(instanceValue string) {
|
|||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "api_requests_total",
|
Name: "api_requests_total",
|
||||||
Help: "How many HTTP requests processed",
|
Help: "How many HTTP requests processed",
|
||||||
ConstLabels: prometheus.Labels{"instance": instance},
|
//ConstLabels: prometheus.Labels{"instance": instance},
|
||||||
},
|
},
|
||||||
[]string{"api", "errcode", "appid"},
|
[]string{"api", "errcode", "appid"},
|
||||||
)
|
)
|
||||||
@ -63,7 +63,7 @@ func InitMetrics(instanceValue string) {
|
|||||||
Name: "api_requests_summary",
|
Name: "api_requests_summary",
|
||||||
Help: "The api request summary of cost.",
|
Help: "The api request summary of cost.",
|
||||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||||
ConstLabels: prometheus.Labels{"instance": instance},
|
//ConstLabels: prometheus.Labels{"instance": instance},
|
||||||
},
|
},
|
||||||
[]string{"api", "errcode", "appid"},
|
[]string{"api", "errcode", "appid"},
|
||||||
)
|
)
|
||||||
@ -90,7 +90,11 @@ func SetupMetricsExporterPusher(pushgateway string, jobname string) {
|
|||||||
jobname = fmt.Sprintf("api-metrics-job-%s", getExeFilename())
|
jobname = fmt.Sprintf("api-metrics-job-%s", getExeFilename())
|
||||||
}
|
}
|
||||||
|
|
||||||
var pusher = push.New(pushgateway, jobname).Gatherer(metricRegistry)
|
var pusher = push.
|
||||||
|
New(pushgateway, jobname).
|
||||||
|
Grouping("instance", instance).
|
||||||
|
Gatherer(metricRegistry)
|
||||||
|
|
||||||
MetricExporterPusher = func() error {
|
MetricExporterPusher = func() error {
|
||||||
RecordMetrics("push_metrics_to_prometheus", "0", "selfmonitoring", 1.0)
|
RecordMetrics("push_metrics_to_prometheus", "0", "selfmonitoring", 1.0)
|
||||||
return pusher.Push()
|
return pusher.Push()
|
||||||
|
Loading…
Reference in New Issue
Block a user