Asterisk - The Open Source Telephony Project  18.5.0
statsd.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * David M. Lee, II <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 #ifndef _ASTERISK_STATSD_H
20 #define _ASTERISK_STATSD_H
21 
22 /*!
23  * \brief Support for publishing to a statsd server.
24  *
25  * \author David M. Lee, II <[email protected]>
26  * \since 12
27  */
28 
29 #include "asterisk/optional_api.h"
30 
31 /*! An instantaneous measurement of a value. */
32 #define AST_STATSD_GAUGE "g"
33 /*!
34  * Embarrassingly, gauge was misspelled for quite some time.
35  * \deprecated You should spell gauge correctly.
36  */
37 #define AST_STATSD_GUAGE AST_STATSD_GAUGE
38 /*! A change in a value. */
39 #define AST_STATSD_COUNTER "c"
40 /*! Measure of milliseconds. */
41 #define AST_STATSD_TIMER "ms"
42 /*! Distribution of values over time. */
43 #define AST_STATSD_HISTOGRAM "h"
44 /*! Events over time. Sorta like increment-only counters. */
45 #define AST_STATSD_METER "m"
46 
47 /*!
48  * \brief Send a stat to the configured statsd server.
49  *
50  * This function uses a character argument for value instead of
51  * an intmax_t argument. This is designed to be simpler to use for
52  * updating a current value rather than resetting it.
53  *
54  * \param metric_name String (UTF-8) name of the metric.
55  * \param type_str Type of metric to send.
56  * \param value Value to send.
57  * \param sample_rate Percentage of samples to send.
58  * \since 13
59  */
60 AST_OPTIONAL_API(void, ast_statsd_log_string, (const char *metric_name,
61  const char *metric_type, const char *value, double sample_rate), {});
62 
63 /*!
64  * \brief Send a stat to the configured statsd server.
65  * \since 13.7.0
66  *
67  * This is the most flexible function for sending a message to the statsd
68  * server. In addition to allowing the string value and sample rate to be specified,
69  * the metric_name can be formed as a printf style string with variable
70  * arguments.
71  *
72  * \param metric_name Format string (UTF-8) specifying the name of the metric.
73  * \param metric_type Type of metric to send.
74  * \param value Value to send.
75  * \param sample_rate Percentage of samples to send.
76  *
77  * Example Usage:
78  * \code
79  * ast_statsd_log_string_va(AST_STATSD_GAUGE, "+1", 1.0, "endpoints.states.%s", state_name);
80  * \endcode
81  */
83  (const char *metric_name, const char *metric_type, const char *value, double sample_rate, ...), {});
84 
85 /*!
86  * \brief Send a stat to the configured statsd server.
87  *
88  * The is nearly the most flexible function for sending a message to the statsd
89  * server, but also the least easy to use. See ast_statsd_log() or
90  * ast_statsd_log_sample() for a slightly more convenient interface.
91  *
92  * \param metric_name String (UTF-8) name of the metric.
93  * \param type_str Type of metric to send.
94  * \param value Value to send.
95  * \param sample_rate Percentage of samples to send.
96  * \since 12
97  */
98 AST_OPTIONAL_API(void, ast_statsd_log_full, (const char *metric_name,
99  const char *metric_type, intmax_t value, double sample_rate), {});
100 
101 /*!
102  * \brief Send a stat to the configured statsd server.
103  * \since 13.7.0
104  *
105  * This is the most flexible function for sending a message to the statsd
106  * server. In addition to allowing the value and sample rate to be specified,
107  * the metric_name can be formed as a printf style string with variable
108  * arguments.
109  *
110  * \param metric_name Format string (UTF-8) specifying the name of the metric.
111  * \param metric_type Type of metric to send.
112  * \param value Value to send.
113  * \param sample_rate Percentage of samples to send.
114  *
115  * Example Usage:
116  * \code
117  * ast_statsd_log_full_va(AST_STATSD_TIMER, rtt, 1.0, "endpoint.%s.rtt", endpoint_name);
118  * \endcode
119  */
121  (const char *metric_name, const char *metric_type, intmax_t value, double sample_rate, ...), {});
122 
123 /*!
124  * \brief Send a stat to the configured statsd server.
125  * \param metric_name String (UTF-8) name of the metric.
126  * \param metric_type Type of metric to send.
127  * \param value Value to send.
128  * \since 12
129  */
130 AST_OPTIONAL_API(void, ast_statsd_log, (const char *metric_name,
131  const char *metric_type, intmax_t value), {});
132 
133 /*!
134  * \brief Send a random sampling of a stat to the configured statsd server.
135  *
136  * The type of sampled metrics is always \ref AST_STATSD_COUNTER. The given
137  * \a sample_rate should be a percentage between 0.0 and 1.0. If it's <= 0.0,
138  * then no samples will be sent. If it's >= 1.0, then all samples will be sent.
139  *
140  * \param metric_name String (UTF-8) name of the metric.
141  * \param value Value to send.
142  * \param sample_rate Percentage of samples to send.
143  * \since 12
144  */
145 AST_OPTIONAL_API(void, ast_statsd_log_sample, (const char *metric_name,
146  intmax_t value, double sample_rate), {});
147 
148 
149 #endif /* _ASTERISK_STATSD_H */
void ast_statsd_log_full_va(const char *metric_name, const char *metric_type, intmax_t value, double sample_rate,...)
Send a stat to the configured statsd server.
Definition: res_statsd.c:199
Optional API function macros.
void ast_statsd_log_full(const char *metric_name, const char *metric_type, intmax_t value, double sample_rate)
Send a stat to the configured statsd server.
Definition: res_statsd.c:164
#define AST_OPTIONAL_API(result, name, proto, stub)
Declare an optional API function.
Definition: optional_api.h:230
int value
Definition: syslog.c:37
void ast_statsd_log_string(const char *metric_name, const char *metric_type, const char *value, double sample_rate)
Send a stat to the configured statsd server.
Definition: res_statsd.c:111
void ast_statsd_log_sample(const char *metric_name, intmax_t value, double sample_rate)
Send a random sampling of a stat to the configured statsd server.
Definition: res_statsd.c:231
void ast_statsd_log(const char *metric_name, const char *metric_type, intmax_t value)
Send a stat to the configured statsd server.
Definition: res_statsd.c:222
#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub)
Declare an optional API function with compiler attributes.
Definition: optional_api.h:233
void ast_statsd_log_string_va(const char *metric_name, const char *metric_type, const char *value, double sample_rate,...)
Send a stat to the configured statsd server.
Definition: res_statsd.c:176
static snd_pcm_format_t format
Definition: chan_alsa.c:102