[prometheus] add node type into job name

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3466/head
Leo Chen 4 years ago
parent 1bd3b9fe9f
commit 1c739d7581
  1. 32
      api/service/prometheus/service.go
  2. 2
      cmd/harmony/main.go

@ -25,12 +25,14 @@ type PrometheusConfig struct {
EnablePush bool // enable pushgateway support
Gateway string // address of the pushgateway
Network string // network type, used as job prefix
Legacy bool // legacy or not, legacy is harmony internal node
Type string // node type, validator or exlorer node
Shard uint32 // shard id, used as job suffix
Instance string //identifier of the instance in prometheus metrics
}
func (p PrometheusConfig) String() string {
return fmt.Sprintf("%v, %v:%v, %v/%v, %v/%v:%v", p.Enabled, p.IP, p.Port, p.EnablePush, p.Gateway, p.Network, p.Shard, p.Instance)
return fmt.Sprintf("%v, %v:%v, %v/%v, %v/%v/%v/%v:%v", p.Enabled, p.IP, p.Port, p.EnablePush, p.Gateway, p.Network, p.Legacy, p.Type, p.Shard, p.Instance)
}
// Service provides Prometheus metrics via the /metrics route. This route will
@ -54,6 +56,25 @@ var (
config PrometheusConfig
)
func getJobName(config PrometheusConfig) string {
var node string
// legacy nodes are harmony nodes: s0,s1,s2,s3
if config.Legacy {
node = "s"
} else {
if config.Type == "validator" {
// regular validator nodes are: v0,v1,v2,v3
node = "v"
} else {
// explorer nodes are: e0,e1,e2,e3
node = "e"
}
}
return fmt.Sprintf("%s/%s%d", config.Network, node, config.Shard)
}
// NewService sets up a new instance for a given address host:port.
// An empty host will match with any IP so an address like ":19000" is perfectly acceptable.
func NewService(additionalHandlers ...Handler) {
@ -86,8 +107,9 @@ func NewService(additionalHandlers ...Handler) {
endpoint := fmt.Sprintf("%s:%d", config.IP, config.Port)
svc.server = &http.Server{Addr: endpoint, Handler: mux}
if config.EnablePush {
utils.Logger().Info().Msg("Prometheus enabled pushgateway support ...")
svc.pusher = push.New(config.Gateway, fmt.Sprintf("%s/%d", config.Network, config.Shard)).
job := getJobName(config)
utils.Logger().Info().Str("Job", job).Msg("Prometheus enabled pushgateway support ...")
svc.pusher = push.New(config.Gateway, job).
Gatherer(svc.registry).
Grouping("instance", config.Instance)
@ -159,6 +181,8 @@ func SetConfig(
enablepush bool,
gateway string,
network string,
legacy bool,
nodetype string,
shard uint32,
instance string,
) {
@ -168,6 +192,8 @@ func SetConfig(
config.EnablePush = enablepush
config.Gateway = gateway
config.Network = network
config.Legacy = legacy
config.Type = nodetype
config.Shard = shard
config.Instance = instance
}

@ -380,6 +380,8 @@ func setupNodeAndRun(hc harmonyConfig) {
hc.Prometheus.EnablePush,
hc.Prometheus.Gateway,
hc.Network.NetworkType,
hc.General.NoStaking,
hc.General.NodeType,
nodeConfig.ShardID,
myHost.GetID().Pretty(),
)

Loading…
Cancel
Save