Merge pull request #6111 from blockscout/mf-add-prometheus-metrics-for-indexer
Add Prometheus metrics to indexerpull/6124/head
commit
a39246f709
@ -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 |
@ -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 |
Loading…
Reference in new issue