View Source hackney_telemetry_worker (hackney_telemetry v0.2.0)

Worker process to handle a hackney metric.

A worker process has two jobs:

(1) Calculate metric values

Hackney does not keep the state of its metrics, but instead emits events to the metrics engine, like "increase this counter by 1", "set this gauge to X", "add Y to this histogram". The job of a metric worker is to process these events and keep up-to-date state representing the value of the tracked metric. State updates run in constant time (O(1)), important since a single request generates about nine metric updates.

(2) Send metric values to Telemetry

If we send the metric value to Telemetry after every update, then telemetry processing may not be able to keep up, and Telemetry will apply backpressure.

Since the worker maintains the most up-to-date value, we can send the current value periodically. Gauge metrics may be less accurate, but it avoids overload.

Start options:

- metric: name of the metric as a list of atoms (required).

- report_interval: how often the worker reports data to telemetry, in milliseconds.

If set to 0, scheduled reports are disabled and the worker will report after every update. Defaults to the value configured in the hackney_telemetry/report_interval config.

Summary

Functions

Generate worker child spec for a supervisor.

gen_server code_change callback

gen_server handle_call implementation.

Handle update event

Handle report events

Initialize server state

Start server

gen_server terminate callback

Return name of the worker process

Types

-type hackney_metric() :: list().
-type keyword() :: {atom(), any()}.
-type keywords() :: [keyword()].
-type transform_fun() :: fun((any(), any()) -> any()).

Functions

-spec child_spec([{metric, hackney_metric()}]) -> supervisor:child_spec().

Generate worker child spec for a supervisor.

Link to this function

code_change(OldVersion, State, Extra)

View Source

gen_server code_change callback

Link to this function

handle_call(Message, From, State)

View Source

gen_server handle_call implementation.

Handle update event

Handle report events

Initialize server state

-spec start_link(keywords()) -> gen_server:start_ret().

Start server

Link to this function

terminate(Reason, State)

View Source

gen_server terminate callback

Link to this function

update(Metric, EventValue, TransformFun)

View Source
-spec update(hackney_metric(), any(), transform_fun()) -> ok.

Update metric

-spec worker_name(hackney_metric()) -> {global, {atom(), hackney_metric()}}.

Return name of the worker process