diff --git a/cron_job_definitions.go b/cron_job_definitions.go index cce97437..84a52572 100644 --- a/cron_job_definitions.go +++ b/cron_job_definitions.go @@ -87,7 +87,7 @@ func taskSyncTransactions(ctx context.Context, client *Client) error { } func taskCalculateMetrics(ctx context.Context, client *Client) error { - metrics, enabled := client.Metrics() + m, enabled := client.Metrics() if !enabled { return errors.New("metrics are not enabled") } @@ -97,7 +97,49 @@ func taskCalculateMetrics(ctx context.Context, client *Client) error { if xpubsCount, err := getXPubsCount(ctx, nil, nil, modelOpts...); err != nil { client.options.logger.Error().Err(err).Msg("error getting xpubs count") } else { - metrics.Stats.XPub.Set(float64(xpubsCount)) + m.Stats.XPub.Set(float64(xpubsCount)) + } + + if utxosCount, err := getUtxosCount(ctx, nil, nil, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting utxos count") + } else { + m.Stats.Utxo.Set(float64(utxosCount)) + } + + if paymailsCount, err := getPaymailAddressesCount(ctx, nil, nil, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting paymails count") + } else { + m.Stats.Paymail.Set(float64(paymailsCount)) + } + + if destinationsCount, err := getDestinationsCount(ctx, nil, nil, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting destinations count") + } else { + m.Stats.Destination.Set(float64(destinationsCount)) + } + + if accessKeysCount, err := getAccessKeysCount(ctx, nil, nil, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting access keys count") + } else { + m.Stats.AccessKey.Set(float64(accessKeysCount)) + } + + inTransactionsFilter := map[string]interface{}{ + "direction": TransactionDirectionIn, + } + if transactionsCount, err := getTransactionsCount(ctx, nil, &inTransactionsFilter, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting transactions count") + } else { + m.Stats.TransactionIn.Set(float64(transactionsCount)) + } + + outTransactionsFilter := map[string]interface{}{ + "direction": TransactionDirectionOut, + } + if transactionsCount, err := getTransactionsCount(ctx, nil, &outTransactionsFilter, modelOpts...); err != nil { + client.options.logger.Error().Err(err).Msg("error getting transactions count") + } else { + m.Stats.TransactionOut.Set(float64(transactionsCount)) } return nil diff --git a/metrics/naming.go b/metrics/naming.go index 3d1f74a9..32b60fbd 100644 --- a/metrics/naming.go +++ b/metrics/naming.go @@ -13,4 +13,12 @@ const ( cronLastExecutionGaugeName = domainPrefix + "cron_last_execution_gauge" ) -const xpubGaugeName = domainPrefix + "xpub_gauge" +const ( + xpubGaugeName = domainPrefix + "xpub_gauge" + utxoGaugeName = domainPrefix + "utxo_gauge" + transactionInGaugeName = domainPrefix + "transaction_in_gauge" + transactionOutGaugeName = domainPrefix + "transaction_out_gauge" + paymailGaugeName = domainPrefix + "paymail_gauge" + destinationGaugeName = domainPrefix + "destination_gauge" + accessKeyGaugeName = domainPrefix + "access_key_gauge" +) diff --git a/metrics/stats.go b/metrics/stats.go index 0dd11780..7d09432f 100644 --- a/metrics/stats.go +++ b/metrics/stats.go @@ -2,11 +2,23 @@ package metrics // Stats is a struct that contains all the gauges that are used to track the calculated stats of the application type Stats struct { - XPub GaugeInterface + XPub GaugeInterface + Utxo GaugeInterface + TransactionIn GaugeInterface + TransactionOut GaugeInterface + Paymail GaugeInterface + Destination GaugeInterface + AccessKey GaugeInterface } func registerStats(collector Collector) Stats { return Stats{ - XPub: collector.RegisterGauge(xpubGaugeName), + XPub: collector.RegisterGauge(xpubGaugeName), + Utxo: collector.RegisterGauge(utxoGaugeName), + TransactionIn: collector.RegisterGauge(transactionInGaugeName), + TransactionOut: collector.RegisterGauge(transactionOutGaugeName), + Paymail: collector.RegisterGauge(paymailGaugeName), + Destination: collector.RegisterGauge(destinationGaugeName), + AccessKey: collector.RegisterGauge(accessKeyGaugeName), } }