forked from blockscout/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from matter-labs/indexer-prometheus-metrics
Indexer prometheus metrics
- Loading branch information
Showing
6 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
defmodule Indexer.Prometheus.Instrumenter do | ||
@moduledoc """ | ||
Blocks fetch and import metrics for `Prometheus`. | ||
""" | ||
|
||
use Prometheus.Metric | ||
|
||
@histogram [ | ||
name: :block_full_processing_duration_microseconds, | ||
labels: [:fetcher], | ||
buckets: [1000, 5000, 10000, 100_000], | ||
duration_unit: :microseconds, | ||
help: "Block whole processing time including fetch and import" | ||
] | ||
|
||
@histogram [ | ||
name: :block_import_duration_microseconds, | ||
labels: [:fetcher], | ||
buckets: [1000, 5000, 10000, 100_000], | ||
duration_unit: :microseconds, | ||
help: "Block import time" | ||
] | ||
|
||
@histogram [ | ||
name: :block_batch_fetch_request_duration_microseconds, | ||
labels: [:fetcher], | ||
buckets: [1000, 5000, 10000, 100_000], | ||
duration_unit: :microseconds, | ||
help: "Block fetch batch request processing time" | ||
] | ||
|
||
@gauge [name: :missing_block_count, help: "Number of missing blocks in the database"] | ||
|
||
@gauge [name: :delay_from_last_node_block, help: "Delay from the last block on the node in seconds"] | ||
|
||
@counter [name: :import_errors_count, help: "Number of database import errors"] | ||
|
||
def block_full_process(time, fetcher) do | ||
Histogram.observe([name: :block_full_processing_duration_microseconds, labels: [fetcher]], time) | ||
end | ||
|
||
def block_import(time, fetcher) do | ||
Histogram.observe([name: :block_import_duration_microseconds, labels: [fetcher]], time) | ||
end | ||
|
||
def block_batch_fetch(time, fetcher) do | ||
Histogram.observe([name: :block_batch_fetch_request_duration_microseconds, labels: [fetcher]], time) | ||
end | ||
|
||
def missing_blocks(missing_block_count) do | ||
Gauge.set([name: :missing_block_count], missing_block_count) | ||
end | ||
|
||
def node_delay(delay) do | ||
Gauge.set([name: :delay_from_last_node_block], delay) | ||
end | ||
|
||
def import_errors(error_count \\ 1) do | ||
Counter.inc([name: :import_errors_count], error_count) | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
apps/indexer/lib/indexer/prometheus/pending_block_operations_collector.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Indexer.Prometheus.PendingBlockOperationsCollector do | ||
@moduledoc """ | ||
Custom collector to count number of records in pending_block_operations table. | ||
""" | ||
|
||
use Prometheus.Collector | ||
|
||
alias Explorer.Chain.PendingBlockOperation | ||
alias Explorer.Repo | ||
alias Prometheus.Model | ||
|
||
def collect_mf(_registry, callback) do | ||
callback.( | ||
create_gauge( | ||
:pending_block_operations_count, | ||
"Number of records in pending_block_operations table", | ||
Repo.aggregate(PendingBlockOperation, :count) | ||
) | ||
) | ||
end | ||
|
||
def collect_metrics(:pending_block_operations_count, count) do | ||
Model.gauge_metrics([{count}]) | ||
end | ||
|
||
defp create_gauge(name, help, data) do | ||
Model.create_mf(name, help, :gauge, __MODULE__, data) | ||
end | ||
end |