Repository navigation
Expand file tree
/
Copy pathmetrics.js
More file actions
88 lines (77 loc) · 2.84 KB
/
Copy pathmetrics.js
File metadata and controls
88 lines (77 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Prometheus metrics for the Octraban indexer.
* Exposes: event ingestion rate, decode latency, DB pool utilisation, RPC errors.
*/
import { Registry, Counter, Histogram, Gauge, collectDefaultMetrics } from "prom-client";
export const registry = new Registry();
// Collect default Node.js metrics (event loop lag, GC, heap, etc.)
collectDefaultMetrics({ register: registry });
/** Total Soroban events ingested from RPC. */
export const eventsIngested = new Counter({
name: "soroban_events_ingested_total",
help: "Total number of Soroban contract events ingested",
labelNames: ["function"],
registers: [registry],
});
/** Histogram of decode() durations in milliseconds. */
export const decodeLatency = new Histogram({
name: "soroban_decode_duration_ms",
help: "Event decode latency in milliseconds",
buckets: [1, 5, 10, 25, 50, 100, 250, 500],
registers: [registry],
});
/** Number of RPC errors by error type. */
export const rpcErrors = new Counter({
name: "soroban_rpc_errors_total",
help: "Total RPC errors encountered by the indexer",
labelNames: ["type"],
registers: [registry],
});
/** Current DB pool size (total connections). */
export const dbPoolTotal = new Gauge({
name: "soroban_db_pool_total",
help: "Total connections in the PostgreSQL pool",
registers: [registry],
});
/** Current DB pool idle connections. */
export const dbPoolIdle = new Gauge({
name: "soroban_db_pool_idle",
help: "Idle connections in the PostgreSQL pool",
registers: [registry],
});
/** Current DB pool waiting clients. */
export const dbPoolWaiting = new Gauge({
name: "soroban_db_pool_waiting",
help: "Clients waiting for a DB connection",
registers: [registry],
});
/** Decoder schema violations (validation failures before DB insert). */
export const decoderSchemaViolationsTotal = new Counter({
name: "soroban_decoder_schema_violations_total",
help: "Total decoder schema validation failures by field",
labelNames: ["field"],
registers: [registry],
});
/**
* Events the decoder could not attribute to a recognised function — it fell
* back to function: "unknown" and raw_topics only. A rising rate means a
* growing share of events are going through with no human-readable
* description (unregistered ABI, unrecognised event signature, or a decoder
* regression) and should be investigated.
*/
export const decodeFallbackTotal = new Counter({
name: "soroban_decode_fallback_total",
help: "Total events that fell back to unrecognized (function: unknown) decoding, by contract",
labelNames: ["contract_id"],
registers: [registry],
});
/**
* Update DB pool gauges from a pg.Pool instance.
* Call this periodically (e.g. every 15 s).
* @param {import('pg').Pool} pool
*/
export function updateDbPoolMetrics(pool) {
dbPoolTotal.set(pool.totalCount);
dbPoolIdle.set(pool.idleCount);
dbPoolWaiting.set(pool.waitingCount);
}