Skip to content

Commit

Permalink
Does this work?
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Dec 5, 2024
1 parent a6f935b commit fbf4dd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/tbcd/tbcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ var (
Help: "address and port tbcd prometheus listens on",
Print: config.PrintAll,
},
"TBC_PROMETHEUS_SUBSYTEM": config.Config{
Value: &cfg.PrometheusSubsystem,
"TBC_PROMETHEUS_NAMESPACE": config.Config{
Value: &cfg.PrometheusNamespace,
DefaultValue: "tbc",
Help: "prefix of prometheus subsystem",
Help: "prefix of prometheus namespace",
Print: config.PrintAll,
},
"TBC_PPROF_ADDRESS": config.Config{
Expand Down
22 changes: 6 additions & 16 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Config struct {
Network string
PeersWanted int
PrometheusListenAddress string
PrometheusSubsystem string
PrometheusNamespace string
PprofListenAddress string
Seeds []string

Expand All @@ -112,7 +112,7 @@ func NewDefaultConfig() *Config {
MaxCachedTxs: defaultMaxCachedTxs,
MempoolEnabled: false, // XXX default to false until it is fixed
PeersWanted: defaultPeersWanted,
PrometheusSubsystem: appName,
PrometheusNamespace: appName,
ExternalHeaderMode: false, // Default anyway, but for readability
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func NewServer(cfg *Config) (*Server, error) {
pings: pings,
timeSource: blockchain.NewMedianTime(),
cmdsProcessed: prometheus.NewCounter(prometheus.CounterOpts{ // XXX: move into Collectors func
Subsystem: cfg.PrometheusSubsystem,
Namespace: cfg.PrometheusNamespace,
Name: "rpc_calls_total",
Help: "The total number of successful RPC commands",
}),
Expand Down Expand Up @@ -2151,73 +2151,63 @@ func (s *Server) DBClose() error {
}

// Collectors returns the Prometheus collectors available for the server.
func (s *Server) Collectors(namespace, subsystem string) []prometheus.Collector {
func (s *Server) Collectors() []prometheus.Collector {
// Naming: https://prometheus.io/docs/practices/naming/
namespace := s.cfg.PrometheusNamespace
return []prometheus.Collector{
s.cmdsProcessed,
newValueVecFunc(prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "blockheader_height", // XXX: rename to block_height?
Help: "Best block canonical height and hash",
}, []string{"hash", "timestamp"}), s.promBlockHeader),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "blocks_missing",
Help: "Number of missing blocks. -1 means more than 64 missing",
}, s.promBlocksMissing),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "running",
Help: "Whether the TBC service is running",
}, s.promRunning),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "synced",
Help: "Whether the TBC service is synced",
}, s.promSynced),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "utxo_sync_height",
Help: "Height of the UTXO indexer",
}, s.promUtxo),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "tx_sync_height",
Help: "Height of transaction indexer",
}, s.promTx),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "peers_connected",
Help: "Number of peers connected",
}, s.promConnectedPeers),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "peers_good",
Help: "Number of good peers",
}, s.promGoodPeers),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "peers_bad",
Help: "Number of bad peers",
}, s.promBadPeers),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "mempool_count",
Help: "Number of transactions in mempool",
}, s.promMempoolCount),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "mempool_size_bytes",
Help: "Size of mempool in bytes",
}, s.promMempoolSize),
Expand Down Expand Up @@ -2346,7 +2336,7 @@ func (s *Server) Run(pctx context.Context) error {
if err != nil {
return fmt.Errorf("create server: %w", err)
}
cs := s.Collectors(appName, s.cfg.PrometheusSubsystem)
cs := s.Collectors()
s.wg.Add(1)
go func() {
defer s.wg.Done()
Expand Down

0 comments on commit fbf4dd5

Please sign in to comment.