Stud.IP  5.4
Metrics Class Reference

Static Public Member Functions

static count ($stat, $increment, $sampleRate=1)
 
static increment ($stat, $sampleRate=1)
 
static decrement ($stat, $sampleRate=1)
 
static gauge ($stat, $value, $sampleRate=1)
 
static timing ($stat, $milliseconds, $sampleRate=1)
 
static startTimer ()
 

Detailed Description

Front-end proxy to a metrics collection service provided by installed MetricsPlugins.

Send metrics to the metrics collection service using gauges, counters or timers (depending on the type of stat you want to measure):

// send a metric that counts something e.g. number of users logging in:
Metrics::count('core.user_login', 1);
// use the shortcut:
Metrics::increment('core.user_login');
// send a metric that represents an instantaneous measurement of a
// value like number of currently logged in users or the number of
// courses currently available
Metrics::gauge('core.global_blubbers', 173723);
// send a metric that measures the number of milliseconds elapsed
// between a start and end time e.g. milliseconds spent searching
// for a course using the Stud.IP quicksearch
$start_time = microtime(true) * 1000;
// now do something for some time
$end_time = microtime(true) * 1000;
Metrics::timing('core.quick_searched', $end_time - $start_time);
// use Metrics::startTimer instead:
// now do something for some time
// send the measured milliseconds since calling Metrics::startTimer
$timer('core.quick_searched');
// sample rates (a float between 0 and 1) may be given to only send
// data this percentage of the time:
Metrics::count('core.user_login', 1, 0.1);
Metrics::increment('core.user_login', 0.2);
Metrics::gauge('core.global_blubbers', 173723, 0.3);
Metrics::timing('core.request_time', 747, 0.4);
$timer('core.quick_searched', 42, 0.5);

Please note: Names of stats must be strings containing lowercase characters or underscores. You may use . (dots) to namespace them. Metrics send from Stud.IP core code should start with 'core.' for example 'core.request_time'.

Author
mlunz.nosp@m.ena@.nosp@m.uos.d.nosp@m.e GPL 2 or later
Since
Stud.IP 3.1

Member Function Documentation

◆ count()

static count (   $stat,
  $increment,
  $sampleRate = 1 
)
static

Increment a counter.

Parameters
string$statthe name of the counter
integer$incrementthe amount to increment by; must be within [-2^63, 2^63]
float$sampleRatea float between 0 and 1; will only be send this percentage of time

◆ decrement()

static decrement (   $stat,
  $sampleRate = 1 
)
static

Increment a counter by -1.

Parameters
string$statthe name of the counter
float$sampleRatea float between 0 and 1; will only be send this percentage of time

◆ gauge()

static gauge (   $stat,
  $value,
  $sampleRate = 1 
)
static

Set a gauge value.

Parameters
string$statthe name of the gauge
integer$valuethe value of the gauge; must be within [0, 2^64]
float$sampleRatea float between 0 and 1; will only be send this percentage of time

◆ increment()

static increment (   $stat,
  $sampleRate = 1 
)
static

Increment a counter by +1.

Parameters
string$statthe name of the counter
float$sampleRatea float between 0 and 1; will only be send this percentage of time

◆ startTimer()

static startTimer ( )
static

Return a timer function that you may invoke to send the recorded time between calling Metrics::startTimer and calling its resulting timer.

The timer function has this signature:

$timer = function ($stat, $sampleRate = 1) {...};

Invoke the timer function using a stat name and an optional sample rate:

$timer('core.sampleTiming');
// or ...
$timer('core.sampleTiming', 0.1);
Returns
Callable the timing function

◆ timing()

static timing (   $stat,
  $milliseconds,
  $sampleRate = 1 
)
static

Record a timing.

Parameters
string$statthe name of the counter
integer$millisecondsthe amount to milliseconds that something lastedincrement by; must be within [0, 2^64]
float$sampleRatea float between 0 and 1; will only be send this percentage of time

The documentation for this class was generated from the following file: