Controls.Rate (Hyper v0.1.0)

Copy Markdown View Source

Turns a monotonically increasing byte counter (e.g. /proc/diskstats sectors or /proc/net/dev bytes) into a per-second rate.

The first observation has no baseline, and a reboot resets the counter backwards; both cases return :skip (carrying the new baseline) rather than a meaningless or negative rate. mono_ms must come from System.monotonic_time/1.

Summary

Functions

Given the previous state, the latest cumulative count, and the monotonic timestamp mono_ms of this reading, return the rate in counter-units per second together with the new state.

Types

state()

@type state() :: {non_neg_integer(), integer()} | nil

Functions

compute(arg1, count, mono_ms)

@spec compute(state(), non_neg_integer(), integer()) ::
  {:ok, float(), state()} | {:skip, state()}

Given the previous state, the latest cumulative count, and the monotonic timestamp mono_ms of this reading, return the rate in counter-units per second together with the new state.