Skip to content

Commit

Permalink
Merge pull request #3 from samcm/feat/network-spec-metrics
Browse files Browse the repository at this point in the history
feat(network): Add metrics about the spec and chain of the network
  • Loading branch information
samcm committed May 9, 2022
2 parents 1b32867 + 2edbbbb commit 6cd4b69
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 13 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
github.com/rs/zerolog v1.26.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
Expand Down
18 changes: 18 additions & 0 deletions pkg/exporter/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Node interface {
Bootstrap(ctx context.Context) error
SyncStatus(ctx context.Context) (*SyncStatus, error)
NodeVersion(ctx context.Context) (string, error)
Spec(ctx context.Context) (map[string]interface{}, error)
}

type node struct {
Expand Down Expand Up @@ -124,3 +125,20 @@ func (c *node) NodeVersion(ctx context.Context) (string, error) {

return version, nil
}

func (c *node) Spec(ctx context.Context) (map[string]interface{}, error) {
provider, isProvider := c.client.(eth2client.SpecProvider)
if !isProvider {
c.refreshClient(ctx)
return nil, errors.New("client does not implement eth2client.SpecProvider")
}

spec, err := provider.Spec(ctx)
if err != nil {
return nil, err
}

c.metrics.ObserveSpec(spec)

return spec, nil
}
45 changes: 39 additions & 6 deletions pkg/exporter/consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Metrics interface {
ObserveSyncDistance(slots uint64)
ObserveSyncIsSyncing(syncing bool)
ObserveNodeVersion(version string)
ObserveSpec(spec map[string]interface{})
}

type metrics struct {
Expand All @@ -18,6 +19,8 @@ type metrics struct {
syncDistance prometheus.Gauge
syncIsSyncing prometheus.Gauge
nodeVersion *prometheus.GaugeVec

specMetrics SpecMetrics
}

func NewMetrics(nodeName, namespace string) Metrics {
Expand All @@ -29,54 +32,55 @@ func NewMetrics(nodeName, namespace string) Metrics {
syncPercentage: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_sync_percentage",
Name: "sync_percentage",
Help: "How synced the node is with the network (0-100%).",
ConstLabels: constLabels,
},
),
syncEstimatedHighestSlot: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_sync_estimated_highest_slot",
Name: "sync_estimated_highest_slot",
Help: "The estimated highest slot of the network.",
ConstLabels: constLabels,
},
),
syncHeadSlot: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_sync_head_slot",
Name: "sync_head_slot",
Help: "The current slot of the node.",
ConstLabels: constLabels,
},
),
syncDistance: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_sync_distance",
Name: "sync_distance",
Help: "The sync distance of the node.",
ConstLabels: constLabels,
},
),
syncIsSyncing: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_sync_is_syncing",
Name: "sync_is_syncing",
Help: "1 if the node is in syncing state.",
ConstLabels: constLabels,
},
),
nodeVersion: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "eth_node_version",
Name: "node_version",
Help: "The version of the running beacon node.",
ConstLabels: constLabels,
},
[]string{
"version",
},
),
specMetrics: NewSpecMetrics(namespace, constLabels),
}

prometheus.MustRegister(m.syncPercentage)
Expand All @@ -85,6 +89,31 @@ func NewMetrics(nodeName, namespace string) Metrics {
prometheus.MustRegister(m.syncDistance)
prometheus.MustRegister(m.syncIsSyncing)
prometheus.MustRegister(m.nodeVersion)

prometheus.MustRegister(m.specMetrics.SafeSlotsToUpdateJustified)
prometheus.MustRegister(m.specMetrics.DepositChainID)
prometheus.MustRegister(m.specMetrics.ConfigName)
prometheus.MustRegister(m.specMetrics.MaxValidatorsPerCommittee)
prometheus.MustRegister(m.specMetrics.SecondsPerEth1Block)
prometheus.MustRegister(m.specMetrics.BaseRewardFactor)
prometheus.MustRegister(m.specMetrics.EpochsPerSyncCommitteePeriod)
prometheus.MustRegister(m.specMetrics.EffectiveBalanceIncrement)
prometheus.MustRegister(m.specMetrics.MaxAttestations)
prometheus.MustRegister(m.specMetrics.MinSyncCommitteeParticipants)
prometheus.MustRegister(m.specMetrics.GenesisDelay)
prometheus.MustRegister(m.specMetrics.SecondsPerSlot)
prometheus.MustRegister(m.specMetrics.MaxEffectiveBalance)
prometheus.MustRegister(m.specMetrics.TerminalTotalDifficulty)
prometheus.MustRegister(m.specMetrics.MaxDeposits)
prometheus.MustRegister(m.specMetrics.MinGenesisActiveValidatorCount)
prometheus.MustRegister(m.specMetrics.TargetCommitteeSize)
prometheus.MustRegister(m.specMetrics.SyncCommitteeSize)
prometheus.MustRegister(m.specMetrics.Eth1FollowDistance)
prometheus.MustRegister(m.specMetrics.TerminalBlockHashActivationEpoch)
prometheus.MustRegister(m.specMetrics.MinDepositAmount)
prometheus.MustRegister(m.specMetrics.SlotsPerEpoch)
prometheus.MustRegister(m.specMetrics.PresetBase)

return m
}

Expand Down Expand Up @@ -116,3 +145,7 @@ func (m *metrics) ObserveSyncIsSyncing(syncing bool) {
func (m *metrics) ObserveNodeVersion(version string) {
m.nodeVersion.WithLabelValues(version).Set(float64(1))
}

func (m *metrics) ObserveSpec(spec map[string]interface{}) {
m.specMetrics.Update(spec)
}
Loading

0 comments on commit 6cd4b69

Please sign in to comment.