View Source hackney_telemetry (hackney_telemetry v0.2.0)
Telemetry adapter for Hackney metrics.
To use it, configure Hackney mod_metrics to use this module and make sure that the hackney_telemetry application starts before your application.
Hackney calls the module specified by mod_metrics to report instrumentation metrics. This module receives the data from Hackney and passes it to a hackney_telemetry_worker which keeps the current state of the metric and generates Telemetry events.
This module implements all the callbacks required by hackney_metrics.
Hackney supports storing metrics in Folsom or Exometer. Unfortunately, these libraries libraries do not export data in a way that is useful for Telemetry, so we need to transform the metrics data before reporting it.
Modules such as [Telemetry.Metrics](https://hex.pm/packages/telemetry_metrics) can create gauges and histograms, so we just need to keep track of metric values and report them to Telemetry.
Metrics are identified by a name, which is a list of atoms or charlist strings, e.g.:
- [hackney, free_count] - [hackney_pool, api_graphql, free_count]
Metrics also have type: counter, histogram, gauge, or meter.
For more information see: - https://github.com/benoitc/hackney/blob/master/README.md#metrics
Summary
Functions
Decrement counter metric by 1.
Decrement counter metric by the given value.
Delete metric worker.
Increment counter metric by 1.
Increment counter metric by the given value.
Create metric worker.
Update gauge metric.
Update histogram metric.
Update meter metric.
Types
-type hackney_metric() :: list().
-type metric_type() :: counter | gauge | histogram | meter.
Functions
-spec decrement_counter(hackney_metric()) -> ok.
Decrement counter metric by 1.
-spec decrement_counter(hackney_metric(), non_neg_integer()) -> ok.
Decrement counter metric by the given value.
-spec delete(hackney_metric()) -> ok.
Delete metric worker.
-spec increment_counter(hackney_metric()) -> ok.
Increment counter metric by 1.
-spec increment_counter(hackney_metric(), non_neg_integer()) -> ok.
Increment counter metric by the given value.
-spec new(metric_type(), hackney_metric()) -> ok.
Create metric worker.
Hackney calls this function when it creates a new pool. It spawns a worker process to handle the new metrics.
Hackney general metrics are ignored here because they are already included in the hackney_telemetry_sup supervisor.
-spec update_gauge(hackney_metric(), any()) -> ok.
Update gauge metric.
Gauges only keep the latest value, so we just need to replace the old state.
-spec update_histogram(hackney_metric(), any()) -> ok.
Update histogram metric.
-spec update_meter(hackney_metric(), any()) -> ok.
Update meter metric.
A meter is a type of counter that only goes forward.