[prometheus] add EnablePush flag

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3466/head
Leo Chen 4 years ago
parent 1b15d5a9d7
commit e0ba870ca7
  1. 7
      api/service/prometheus/service.go
  2. 1
      cmd/harmony/config.go
  3. 2
      cmd/harmony/default.go
  4. 9
      cmd/harmony/flags.go
  5. 1
      cmd/harmony/main.go

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

@ -146,6 +146,7 @@ type prometheusConfig struct {
Enabled bool
IP string
Port int
EnablePush bool
Gateway string
}

@ -70,6 +70,7 @@ var defaultConfig = harmonyConfig{
IP: "0.0.0.0",
Port: nodeconfig.DefaultPrometheusPort,
Gateway: "https://gateway.harmony.one",
EnablePush: true,
},
}
@ -103,6 +104,7 @@ var defaultPrometheusConfig = prometheusConfig{
Enabled: true,
IP: "0.0.0.0",
Port: 9900,
EnablePush: true,
Gateway: "https://gateway.harmony.one",
}

@ -171,6 +171,7 @@ var (
prometheusIPFlag,
prometheusPortFlag,
prometheusGatewayFlag,
prometheusEnablePushFlag,
}
)
@ -1211,6 +1212,11 @@ var (
Usage: "prometheus pushgateway URL",
DefValue: defaultConfig.Prometheus.Gateway,
}
prometheusEnablePushFlag = cli.BoolFlag{
Name: "prometheus.push",
Usage: "enable prometheus pushgateway",
DefValue: defaultConfig.Prometheus.EnablePush,
}
)
func applyPrometheusFlags(cmd *cobra.Command, config *harmonyConfig) {
@ -1234,4 +1240,7 @@ func applyPrometheusFlags(cmd *cobra.Command, config *harmonyConfig) {
if cli.IsFlagChanged(cmd, prometheusGatewayFlag) {
config.Prometheus.Gateway = cli.GetStringFlagValue(cmd, prometheusGatewayFlag)
}
if cli.IsFlagChanged(cmd, prometheusEnablePushFlag) {
config.Prometheus.EnablePush = cli.GetBoolFlagValue(cmd, prometheusEnablePushFlag)
}
}

@ -377,6 +377,7 @@ func setupNodeAndRun(hc harmonyConfig) {
hc.Prometheus.Enabled,
hc.Prometheus.IP,
hc.Prometheus.Port,
hc.Prometheus.EnablePush,
hc.Prometheus.Gateway,
hc.Network.NetworkType,
nodeConfig.ShardID,

Loading…
Cancel
Save