[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 Enabled bool
IP string IP string
Port int Port int
EnablePush bool // enable pushgateway support
Gateway string // address of the pushgateway Gateway string // address of the pushgateway
Network string // network type, used as job prefix Network string // network type, used as job prefix
Shard uint32 // shard id, used as job suffix Shard uint32 // shard id, used as job suffix
@ -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

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

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

@ -171,6 +171,7 @@ var (
prometheusIPFlag, prometheusIPFlag,
prometheusPortFlag, prometheusPortFlag,
prometheusGatewayFlag, prometheusGatewayFlag,
prometheusEnablePushFlag,
} }
) )
@ -1211,6 +1212,11 @@ var (
Usage: "prometheus pushgateway URL", Usage: "prometheus pushgateway URL",
DefValue: defaultConfig.Prometheus.Gateway, 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) { func applyPrometheusFlags(cmd *cobra.Command, config *harmonyConfig) {
@ -1234,4 +1240,7 @@ func applyPrometheusFlags(cmd *cobra.Command, config *harmonyConfig) {
if cli.IsFlagChanged(cmd, prometheusGatewayFlag) { if cli.IsFlagChanged(cmd, prometheusGatewayFlag) {
config.Prometheus.Gateway = cli.GetStringFlagValue(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.Enabled,
hc.Prometheus.IP, hc.Prometheus.IP,
hc.Prometheus.Port, hc.Prometheus.Port,
hc.Prometheus.EnablePush,
hc.Prometheus.Gateway, hc.Prometheus.Gateway,
hc.Network.NetworkType, hc.Network.NetworkType,
nodeConfig.ShardID, nodeConfig.ShardID,

Loading…
Cancel
Save