surport outside instance
This commit is contained in:
parent
b70e9ff90d
commit
1d8453af9d
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -39,9 +40,16 @@ func dumpMetricExporterPusher() error {
|
|||||||
return errors.New("not initilized, forgot call 'SetupMetricsExporterPusher'?")
|
return errors.New("not initilized, forgot call 'SetupMetricsExporterPusher'?")
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitMetrics() {
|
func InitMetrics(instanceValue string) {
|
||||||
instance := getInstanceIpAddress()
|
var instance = instanceValue
|
||||||
log.Infof("self instance ip: [%s]", instance)
|
if instanceValue == "" {
|
||||||
|
instance = getInstanceIpAddress()
|
||||||
|
} else if ap := strings.Split(instanceValue, ":"); len(ap) == 2 &&
|
||||||
|
ap[0] == "0.0.0.0" || ap[0] == "" {
|
||||||
|
instance = getInstanceIpAddress() + ":" + ap[1]
|
||||||
|
}
|
||||||
|
log.Infof("self instance: [%s]", instance)
|
||||||
|
|
||||||
metricApiCounter = prometheus.NewCounterVec(
|
metricApiCounter = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "api_requests_total",
|
Name: "api_requests_total",
|
||||||
@ -59,6 +67,7 @@ func InitMetrics() {
|
|||||||
},
|
},
|
||||||
[]string{"api", "errcode", "appid"},
|
[]string{"api", "errcode", "appid"},
|
||||||
)
|
)
|
||||||
|
|
||||||
metricRegistry = prometheus.NewRegistry()
|
metricRegistry = prometheus.NewRegistry()
|
||||||
metricRegistry.MustRegister(metricApiCounter)
|
metricRegistry.MustRegister(metricApiCounter)
|
||||||
metricRegistry.MustRegister(metricApiSummary)
|
metricRegistry.MustRegister(metricApiSummary)
|
||||||
|
Loading…
Reference in New Issue
Block a user