|
| 1 | +package statediff |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/ethereum/go-ethereum/metrics" |
| 7 | +) |
| 8 | + |
| 9 | +const ( |
| 10 | + namespace = "statediff" |
| 11 | +) |
| 12 | + |
| 13 | +// Build a fully qualified metric name |
| 14 | +func metricName(subsystem, name string) string { |
| 15 | + if name == "" { |
| 16 | + return "" |
| 17 | + } |
| 18 | + parts := []string{namespace, name} |
| 19 | + if subsystem != "" { |
| 20 | + parts = []string{namespace, subsystem, name} |
| 21 | + } |
| 22 | + // Prometheus uses _ but geth metrics uses / and replaces |
| 23 | + return strings.Join(parts, "/") |
| 24 | +} |
| 25 | + |
| 26 | +type statediffMetricsHandles struct { |
| 27 | + // Height of latest synced by core.BlockChain |
| 28 | + // FIXME |
| 29 | + lastSyncHeight metrics.Gauge |
| 30 | + // Height of the latest block received from chainEvent channel |
| 31 | + lastEventHeight metrics.Gauge |
| 32 | + // Height of latest state diff |
| 33 | + lastStatediffHeight metrics.Gauge |
| 34 | + // Current length of chainEvent channels |
| 35 | + serviceLoopChannelLen metrics.Gauge |
| 36 | + writeLoopChannelLen metrics.Gauge |
| 37 | +} |
| 38 | + |
| 39 | +func RegisterStatediffMetrics(reg metrics.Registry) statediffMetricsHandles { |
| 40 | + ctx := statediffMetricsHandles{ |
| 41 | + lastSyncHeight: metrics.NewGauge(), |
| 42 | + lastEventHeight: metrics.NewGauge(), |
| 43 | + lastStatediffHeight: metrics.NewGauge(), |
| 44 | + serviceLoopChannelLen: metrics.NewGauge(), |
| 45 | + writeLoopChannelLen: metrics.NewGauge(), |
| 46 | + } |
| 47 | + subsys := "service" |
| 48 | + reg.Register(metricName(subsys, "last_sync_height"), ctx.lastSyncHeight) |
| 49 | + reg.Register(metricName(subsys, "last_event_height"), ctx.lastEventHeight) |
| 50 | + reg.Register(metricName(subsys, "last_statediff_height"), ctx.lastStatediffHeight) |
| 51 | + reg.Register(metricName(subsys, "service_loop_channel_len"), ctx.serviceLoopChannelLen) |
| 52 | + reg.Register(metricName(subsys, "write_loop_channel_len"), ctx.writeLoopChannelLen) |
| 53 | + return ctx |
| 54 | +} |
0 commit comments