QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Functions
stats.h File Reference

Provides stats aggregation and multiple sinks for collected stats. More...

#include "qev.h"

Go to the source code of this file.

Classes

struct  qev_stats_threshold
 For determining if something should be alerted on. More...
 

Macros

#define qev_stats_counter_inc(counter)   qev_stats_counter_add(counter, 1);
 Increments a counter. More...
 
#define qev_stats_counter_dec(counter)   qev_stats_counter_add(counter, -1);
 Decrements a counter. More...
 
#define qev_stats_time(timer, block)
 Times the execution of the given block of code. More...
 

Typedefs

typedef gint(* qev_stats_monitor_fn )(const gint64 val, const struct qev_stats_threshold thresh, GString *msg)
 A custom monitoring function. More...
 
typedef struct qev_stats_gauge qev_stats_gauge_t
 A gauge stat.
 
typedef struct qev_stats_counter qev_stats_counter_t
 A counter stat.
 
typedef struct qev_stats_timer qev_stats_timer_t
 A timer stat.
 

Functions

qev_stats_gauge_tqev_stats_gauge (const gchar *prefix, const gchar *name, const gchar *description)
 Adds a gauge to the stats lineup. More...
 
qev_stats_gauge_tqev_stats_gauge_monitor (const gchar *prefix, const gchar *name, const qev_stats_monitor_fn monitor, const gchar *description)
 Adds a gauge to the stats lineup. More...
 
void qev_stats_gauge_set (qev_stats_gauge_t *gauge, gint64 val)
 Set the gauge to the given value. More...
 
gint64 qev_stats_gauge_get (qev_stats_gauge_t *gauge)
 Get the value of the gauge right now. More...
 
qev_stats_counter_tqev_stats_counter (const gchar *prefix, const gchar *name, const gboolean reset_on_flush, const gchar *description)
 Adds a counter to the stats lineup. More...
 
qev_stats_counter_tqev_stats_counter_monitor (const gchar *prefix, const gchar *name, const gboolean reset_on_flush, const qev_stats_monitor_fn monitor, const gchar *description)
 Adds a counter to the stats lineup. More...
 
gint64 qev_stats_counter_add (qev_stats_counter_t *counter, const gint64 val)
 Add the given value to the counter. More...
 
gint64 qev_stats_counter_get (qev_stats_counter_t *counter)
 Get the given value to the counter at this instant. More...
 
qev_stats_timer_tqev_stats_timer (const gchar *prefix, const gchar *name, const gchar *description)
 Adds a timer to the stats lineup. More...
 
qev_stats_timer_tqev_stats_timer_monitor (const gchar *prefix, const gchar *name, const qev_stats_monitor_fn monitor_sum, const qev_stats_monitor_fn monitor_stddev, const qev_stats_monitor_fn monitor_mean, const qev_stats_monitor_fn monitor_max, const qev_stats_monitor_fn monitor_min, const qev_stats_monitor_fn monitor_count, const gchar *description)
 Adds a timer to the stats lineup. More...
 
void qev_stats_timer_record (qev_stats_timer_t *timer, const gint64 us)
 Records a time to the timer. More...
 

Detailed Description

Provides stats aggregation and multiple sinks for collected stats.

Typically, stats will be global variables that are treated as references only. Upon passing the stat to any of the add functions, it will be initialized and prepared for life.

Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Macro Definition Documentation

#define qev_stats_counter_dec (   counter)    qev_stats_counter_add(counter, -1);

Decrements a counter.

Parameters
counterA pointer to the counter struct
Returns
The value after decrement
#define qev_stats_counter_inc (   counter)    qev_stats_counter_add(counter, 1);

Increments a counter.

Parameters
counterA pointer to the counter struct
Returns
The value after increment
#define qev_stats_time (   timer,
  block 
)
Value:
{ \
gint64 qev_stats_timer_start = g_get_monotonic_time(); \
block; \
qev_stats_timer_record(timer, g_get_monotonic_time() - qev_stats_timer_start); }
void qev_stats_timer_record(qev_stats_timer_t *timer, const gint64 us)
Records a time to the timer.

Times the execution of the given block of code.

Parameters
timerA pointer to the timer
blockThe block to time

Typedef Documentation

typedef gint(* qev_stats_monitor_fn)(const gint64 val, const struct qev_stats_threshold thresh, GString *msg)

A custom monitoring function.

Returns a value (typically 0 - 3) indicating how everything is going, typically based off of values in thresh.

Parameters
valThe value of the stat
threshThe array of thresholds configured
thrsThe number of thresholds
msg[out]Message to be included with the return value; print your status message into the given GString.
Returns
By convention, returns take one of the following values, but it's acceptable to return different values if your sink knows what to do with them.
0 when OK
1 when WARNING
2 when CRITICAL
3 when UNKNOWN

Function Documentation

qev_stats_counter_t* qev_stats_counter ( const gchar *  prefix,
const gchar *  name,
const gboolean  reset_on_flush,
const gchar *  description 
)

Adds a counter to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
reset_on_flushIf the counter should be reset between stats flushes
descriptionWhat this counter actually measures.
Returns
The stat, useful for qev_stats_counter_inc/dec() and qev_stats_counter_get()
gint64 qev_stats_counter_add ( qev_stats_counter_t counter,
const gint64  val 
)

Add the given value to the counter.

Parameters
counterThe counter to add the value to
valThe value to add, be it positive or negative.
Returns
The value of the counter after the operation
gint64 qev_stats_counter_get ( qev_stats_counter_t counter)

Get the given value to the counter at this instant.

Parameters
counterThe counter to add the value to
Returns
The value of the counter right now
qev_stats_counter_t* qev_stats_counter_monitor ( const gchar *  prefix,
const gchar *  name,
const gboolean  reset_on_flush,
const qev_stats_monitor_fn  monitor,
const gchar *  description 
)

Adds a counter to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
reset_on_flushIf the counter should be reset between stats flushes
monitorA custom monitor function (NULL for default monitor)
descriptionWhat this counter actually measures.
Returns
The stat, useful for qev_stats_counter_inc/dec() and qev_stats_counter_get()
qev_stats_gauge_t* qev_stats_gauge ( const gchar *  prefix,
const gchar *  name,
const gchar *  description 
)

Adds a gauge to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
descriptionWhat this gauge actually measures.
Returns
The stat, useful for qev_stats_gauge_set/get()
gint64 qev_stats_gauge_get ( qev_stats_gauge_t gauge)

Get the value of the gauge right now.

Parameters
gaugeThe gauge to set
Returns
The value of the gauge
qev_stats_gauge_t* qev_stats_gauge_monitor ( const gchar *  prefix,
const gchar *  name,
const qev_stats_monitor_fn  monitor,
const gchar *  description 
)

Adds a gauge to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
monitorA custom monitor function (NULL for default monitor)
descriptionWhat this gauge actually measures.
Returns
The stat, useful for qev_stats_gauge_set/get()
void qev_stats_gauge_set ( qev_stats_gauge_t gauge,
gint64  val 
)

Set the gauge to the given value.

Parameters
gaugeThe gauge to set
valThe value to set to
qev_stats_timer_t* qev_stats_timer ( const gchar *  prefix,
const gchar *  name,
const gchar *  description 
)

Adds a timer to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
descriptionWhat this timer actually times.
Returns
The timer, used for qev_stats_record_time()
qev_stats_timer_t* qev_stats_timer_monitor ( const gchar *  prefix,
const gchar *  name,
const qev_stats_monitor_fn  monitor_sum,
const qev_stats_monitor_fn  monitor_stddev,
const qev_stats_monitor_fn  monitor_mean,
const qev_stats_monitor_fn  monitor_max,
const qev_stats_monitor_fn  monitor_min,
const qev_stats_monitor_fn  monitor_count,
const gchar *  description 
)

Adds a timer to the stats lineup.

Parameters
prefixA prefix for the stat to have
nameThe name of the stat (may be A-Za-z0-9._-, . being the path separator)
monitor_sumCustom monitor for the timer's sum value (NULL for default monitor)
monitor_stddevCustom monitor for the timer's standard deviation value (NULL for default monitor)
monitor_meanCustom monitor for the timer's mean value (NULL for default monitor)
monitor_maxCustom monitor for the timer's max value (NULL for default monitor)
monitor_minCustom monitor for the timer's min value (NULL for default monitor)
monitor_countCustom monitor for the timer's count (NULL for default monitor)
descriptionWhat this timer actually times.
Returns
The timer, used for qev_stats_record_time()
void qev_stats_timer_record ( qev_stats_timer_t timer,
const gint64  us 
)

Records a time to the timer.

Parameters
timerThe timer struct
usMicroseconds to record