Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update metrics
  • Loading branch information
shiqizng committed Feb 9, 2022
commit 233482ed2a8d36a80e03fc48e787bda4f7d8ad0c
9 changes: 8 additions & 1 deletion cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ func handleBlock(block *rpcs.EncodedBlockCert, imp importer.Importer) error {
// Ignore round 0 (which is empty).
if block.Block.Round() > 0 {
metrics.BlockImportTimeSeconds.Observe(dt.Seconds())
metrics.ImportedTxnsPerBlock.Observe(float64(len(block.Block.Payset)))
//metrics.ImportedTxnsPerBlock.WithLabelValues().Set(float64(len(block.Block.Payset)))
metrics.ImportedRoundGauge.Set(float64(block.Block.Round()))
txnCountByType := make(map[string]int)
for _, txn := range block.Block.Payset {
txnCountByType[string(txn.Txn.Type)]++
}
for k, v := range txnCountByType {
metrics.ImportedTxnsPerBlock.WithLabelValues(k).Set(float64(v))
}
}

logger.Infof("round r=%d (%d txn) imported in %s", block.Block.Round(), len(block.Block.Payset), dt.String())
Expand Down
13 changes: 13 additions & 0 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/algorand/go-algorand-sdk/client/v2/algod"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
"github.com/algorand/indexer/util/metrics"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -111,7 +112,13 @@ func (bot *fetcherImpl) catchupLoop(ctx context.Context) error {
var blockbytes []byte
aclient := bot.Algod()
for {
start := time.Now()

blockbytes, err = aclient.BlockRaw(bot.nextRound).Do(ctx)

dt := time.Since(start)
metrics.AlgodRawBlockTimeSeconds.Observe(dt.Seconds())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this metric be named GetAlgodRawBlockTimeSeconds instead? That might be easier to understand when building queries in grafana


if err != nil {
// If context has expired.
if ctx.Err() != nil {
Expand Down Expand Up @@ -150,7 +157,13 @@ func (bot *fetcherImpl) followLoop(ctx context.Context) error {
"r=%d error getting status %d", retries, bot.nextRound)
continue
}
start := time.Now()

blockbytes, err = aclient.BlockRaw(bot.nextRound).Do(ctx)

dt := time.Since(start)
metrics.AlgodRawBlockTimeSeconds.Observe(dt.Seconds())

if err == nil {
break
} else if ctx.Err() != nil { // if context has expired
Expand Down
18 changes: 15 additions & 3 deletions util/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func RegisterPrometheusMetrics() {
prometheus.Register(ImportedRoundGauge)
prometheus.Register(BlockUploadTimeSeconds)
prometheus.Register(PostgresEvalTimeSeconds)
prometheus.Register(AlgodRawBlockTimeSeconds)
}

// Prometheus metric names broken out for reuse.
Expand All @@ -19,6 +20,7 @@ const (
ImportedTxnsPerBlockName = "imported_tx_per_block"
ImportedRoundGaugeName = "imported_round"
PostgresEvalName = "postgres_eval_time_sec"
AlgodRawBlockTimeName = "algod_raw_block_time_sec"
)

// AllMetricNames is a reference for all the custom metric names.
Expand All @@ -28,6 +30,7 @@ var AllMetricNames = []string{
ImportedTxnsPerBlockName,
ImportedRoundGaugeName,
PostgresEvalName,
AlgodRawBlockTimeName,
}

// Initialize the prometheus objects.
Expand All @@ -46,12 +49,14 @@ var (
Help: "Block upload time in seconds.",
})

ImportedTxnsPerBlock = prometheus.NewSummary(
prometheus.SummaryOpts{
ImportedTxnsPerBlock = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: "indexer_daemon",
Name: ImportedTxnsPerBlockName,
Help: "Transactions per block.",
})
},
[]string{"txn_type"},
)

ImportedRoundGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Expand All @@ -66,4 +71,11 @@ var (
Name: PostgresEvalName,
Help: "Time spent calling Eval function in seconds.",
})

AlgodRawBlockTimeSeconds = prometheus.NewSummary(
prometheus.SummaryOpts{
Subsystem: "indexer_daemon",
Name: AlgodRawBlockTimeName,
Help: "Total response time from Algod's raw block endpoint in seconds.",
})
)