Malachi.Metrics (malachi v0.8.13)

View Source

Real-time operational and security metrics kept in ETS (atomic update_counter), plus a periodically-sampled system snapshot and its recent history.

The increment_*/record_* functions bump counters on the hot path (fast, lock-free), rate-limit and connection-limit blocks, auth failures and account lockouts, audit events, dashboard-auth outcomes, and TLS handshakes; get_system_metrics/0 reads the live BEAM snapshot (memory, processes, io) folded together with those counters, and get_history/1 returns the recent snapshots. A counter is created on first touch, so callers never need to initialize one.

Summary

Functions

Returns a specification to start this module under a supervisor.

The recent per-second history samples for the last seconds (default 60).

A snapshot of system-wide metrics (memory, processes, connections, auth) for the dashboard.

Increment account lockout counter.

Increment account lockout blocked attempt counter.

Increment audit event counter by event type.

Increment connection limit blocked counter.

Increment dashboard authentication blocked (rate limited) counter.

Increment dashboard authentication failure counter.

Increment dashboard authentication success counter.

Increment failed authentication attempt counter.

Increment rate limit blocked counter for specific action.

Increment TLS handshake failure counter.

Increment TLS handshake success counter.

Records an authentication attempt with result (:ok / :error).

Records count records consumed (from the consume telemetry event).

Records a segment that failed checksum verification, by reason (:bad_crc, :bad_magic, :incomplete). Non-zero means data at rest is damaged somewhere on this node, which is otherwise a silent condition: a damaged copy serves short reads without any error.

Records count records and bytes value bytes produced (from the produce telemetry event).

Records a quorum replication with result (:ok / :no_quorum).

Records one integrity scrub pass: how many segments it verified, repaired, and could not repair. A verified total that stops advancing is how an operator sees that the scrub itself has stopped, which the failure counters alone cannot show (they stay at zero both when all is well and when nothing is checking). The unrepairable total is the one that calls for a human: it counts damage the cluster could not heal by itself, which on a single node is every finding there is.

Record the negotiated TLS version for a connection.

Starts the metrics server (owns the ETS counter table).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_history(seconds \\ 60)

The recent per-second history samples for the last seconds (default 60).

get_system_metrics()

A snapshot of system-wide metrics (memory, processes, connections, auth) for the dashboard.

increment_account_lockout()

Increment account lockout counter.

increment_account_lockout_blocked()

Increment account lockout blocked attempt counter.

increment_audit_event(event_type)

Increment audit event counter by event type.

increment_connection_limit_blocked()

Increment connection limit blocked counter.

increment_dashboard_auth_blocked()

Increment dashboard authentication blocked (rate limited) counter.

increment_dashboard_auth_failed()

Increment dashboard authentication failure counter.

increment_dashboard_auth_success()

Increment dashboard authentication success counter.

increment_failed_auth_attempt()

Increment failed authentication attempt counter.

increment_rate_limit_blocked(action)

Increment rate limit blocked counter for specific action.

increment_tls_handshake_failed()

Increment TLS handshake failure counter.

increment_tls_handshake_success()

Increment TLS handshake success counter.

record_auth(result)

Records an authentication attempt with result (:ok / :error).

record_consume(count)

Records count records consumed (from the consume telemetry event).

record_integrity_failure(reason)

Records a segment that failed checksum verification, by reason (:bad_crc, :bad_magic, :incomplete). Non-zero means data at rest is damaged somewhere on this node, which is otherwise a silent condition: a damaged copy serves short reads without any error.

record_produce(count, bytes)

Records count records and bytes value bytes produced (from the produce telemetry event).

record_replication(result)

Records a quorum replication with result (:ok / :no_quorum).

record_scrub_pass(verified, repaired, unrepairable)

Records one integrity scrub pass: how many segments it verified, repaired, and could not repair. A verified total that stops advancing is how an operator sees that the scrub itself has stopped, which the failure counters alone cannot show (they stay at zero both when all is well and when nothing is checking). The unrepairable total is the one that calls for a human: it counts damage the cluster could not heal by itself, which on a single node is every finding there is.

record_tls_version(version)

Record the negotiated TLS version for a connection.

start_link(_)

Starts the metrics server (owns the ETS counter table).