|
|
@ -16,13 +16,14 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
// PrometheusConfig is the config for the prometheus service
|
|
|
|
// PrometheusConfig is the config for the prometheus service
|
|
|
|
type PrometheusConfig struct { |
|
|
|
type PrometheusConfig struct { |
|
|
|
Enabled bool |
|
|
|
Enabled bool |
|
|
|
IP string |
|
|
|
IP string |
|
|
|
Port int |
|
|
|
Port int |
|
|
|
Gateway string // address of the pushgateway
|
|
|
|
EnablePush bool // enable pushgateway support
|
|
|
|
Network string // network type, used as job prefix
|
|
|
|
Gateway string // address of the pushgateway
|
|
|
|
Shard uint32 // shard id, used as job suffix
|
|
|
|
Network string // network type, used as job prefix
|
|
|
|
Instance string //identifier of the instance in prometheus metrics
|
|
|
|
Shard uint32 // shard id, used as job suffix
|
|
|
|
|
|
|
|
Instance string //identifier of the instance in prometheus metrics
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Service provides Prometheus metrics via the /metrics route. This route will
|
|
|
|
// Service provides Prometheus metrics via the /metrics route. This route will
|
|
|
@ -69,6 +70,10 @@ func NewService(additionalHandlers ...Handler) { |
|
|
|
// start pusher to push metrics to prometheus pushgateway
|
|
|
|
// start pusher to push metrics to prometheus pushgateway
|
|
|
|
// every minute
|
|
|
|
// every minute
|
|
|
|
go func(config PrometheusConfig) { |
|
|
|
go func(config PrometheusConfig) { |
|
|
|
|
|
|
|
if !config.EnablePush { |
|
|
|
|
|
|
|
utils.Logger().Info().Msg("Prometheus pushgateway support is disabled...") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
ticker := time.NewTicker(time.Minute) |
|
|
|
ticker := time.NewTicker(time.Minute) |
|
|
|
defer ticker.Stop() |
|
|
|
defer ticker.Stop() |
|
|
|
for { |
|
|
|
for { |
|
|
@ -130,6 +135,7 @@ func SetConfig( |
|
|
|
enabled bool, |
|
|
|
enabled bool, |
|
|
|
ip string, |
|
|
|
ip string, |
|
|
|
port int, |
|
|
|
port int, |
|
|
|
|
|
|
|
enablepush bool, |
|
|
|
gateway string, |
|
|
|
gateway string, |
|
|
|
network string, |
|
|
|
network string, |
|
|
|
shard uint32, |
|
|
|
shard uint32, |
|
|
@ -138,6 +144,7 @@ func SetConfig( |
|
|
|
config.Enabled = enabled |
|
|
|
config.Enabled = enabled |
|
|
|
config.IP = ip |
|
|
|
config.IP = ip |
|
|
|
config.Port = port |
|
|
|
config.Port = port |
|
|
|
|
|
|
|
config.EnablePush = enablepush |
|
|
|
config.Gateway = gateway |
|
|
|
config.Gateway = gateway |
|
|
|
config.Network = network |
|
|
|
config.Network = network |
|
|
|
config.Shard = shard |
|
|
|
config.Shard = shard |
|
|
|