[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. 21
      api/service/prometheus/service.go
  2. 9
      cmd/harmony/config.go
  3. 18
      cmd/harmony/default.go
  4. 9
      cmd/harmony/flags.go
  5. 1
      cmd/harmony/main.go

@ -16,13 +16,14 @@ import (
// PrometheusConfig is the config for the prometheus service
type PrometheusConfig struct {
Enabled bool
IP string
Port int
Gateway string // address of the pushgateway
Network string // network type, used as job prefix
Shard uint32 // shard id, used as job suffix
Instance string //identifier of the instance in prometheus metrics
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
Instance string //identifier of the instance in prometheus metrics
}
// 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
// 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

@ -143,10 +143,11 @@ type legacyConfig struct {
}
type prometheusConfig struct {
Enabled bool
IP string
Port int
Gateway string
Enabled bool
IP string
Port int
EnablePush bool
Gateway string
}
// TODO: use specific type wise validation instead of general string types assertion.

@ -66,10 +66,11 @@ var defaultConfig = harmonyConfig{
Verbosity: 3,
},
Prometheus: &prometheusConfig{
Enabled: true,
IP: "0.0.0.0",
Port: nodeconfig.DefaultPrometheusPort,
Gateway: "https://gateway.harmony.one",
Enabled: true,
IP: "0.0.0.0",
Port: nodeconfig.DefaultPrometheusPort,
Gateway: "https://gateway.harmony.one",
EnablePush: true,
},
}
@ -100,10 +101,11 @@ var defaultConsensusConfig = consensusConfig{
}
var defaultPrometheusConfig = prometheusConfig{
Enabled: true,
IP: "0.0.0.0",
Port: 9900,
Gateway: "https://gateway.harmony.one",
Enabled: true,
IP: "0.0.0.0",
Port: 9900,
EnablePush: true,
Gateway: "https://gateway.harmony.one",
}
const (

@ -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