[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 // 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

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

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

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