Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Macros | Functions | Variables
res_statsd.c File Reference
#include "asterisk.h"
#include "asterisk/config_options.h"
#include "asterisk/module.h"
#include "asterisk/netsock2.h"
#include "asterisk/statsd.h"
Include dependency graph for res_statsd.c:

Go to the source code of this file.

Data Structures

struct  conf
 All configuration options for http media cache. More...
 
struct  conf_global_options
 Global configuration options for statsd client. More...
 

Macros

#define AST_API_MODULE
 Support for publishing to a StatsD server. More...
 
#define DEFAULT_STATSD_PORT   8125
 
#define MAX_PREFIX   40
 

Functions

static void __init_statsd_buf (void)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static AO2_GLOBAL_OBJ_STATIC (confs)
 Locking container for safe configuration access. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
void AST_OPTIONAL_API_NAME() ast_statsd_log (const char *metric_name, const char *metric_type, intmax_t value)
 Send a stat to the configured statsd server. More...
 
void AST_OPTIONAL_API_NAME() 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. More...
 
void AST_OPTIONAL_API_NAME() 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. More...
 
void AST_OPTIONAL_API_NAME() 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. More...
 
void AST_OPTIONAL_API_NAME() 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. More...
 
void AST_OPTIONAL_API_NAME() 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. More...
 
static void * conf_alloc (void)
 Creates the statis http conf object. More...
 
static void conf_destructor (void *obj)
 Disposes of the statsd conf object. More...
 
static void conf_server (const struct conf *cfg, struct ast_sockaddr *addr)
 
 CONFIG_INFO_STANDARD (cfg_info, confs, conf_alloc,.files=ACO_FILES(&conf_file))
 
static char is_enabled (void)
 Helper function to check if module is enabled. More...
 
static int load_module (void)
 
static int reload_module (void)
 
static int statsd_init (void)
 
static void statsd_shutdown (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "StatsD client support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_REALTIME_DRIVER + 5, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct aco_file conf_file
 The conf file that's processed for the module. More...
 
static struct aco_type global_option
 Mapping of the statsd conf struct's globals to the general context in the config file. More...
 
static struct aco_typeglobal_options [] = ACO_TYPES(&global_option)
 
static int socket_fd = -1
 
static struct ast_threadstorage statsd_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_statsd_buf , .custom_init = NULL , }
 

Macro Definition Documentation

◆ AST_API_MODULE

#define AST_API_MODULE

Support for publishing to a StatsD server.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m
Since
12

Definition at line 95 of file res_statsd.c.

◆ DEFAULT_STATSD_PORT

#define DEFAULT_STATSD_PORT   8125

Definition at line 98 of file res_statsd.c.

◆ MAX_PREFIX

#define MAX_PREFIX   40

Definition at line 100 of file res_statsd.c.

Function Documentation

◆ __init_statsd_buf()

static void __init_statsd_buf ( void  )
static

Definition at line 203 of file res_statsd.c.

207{

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 460 of file res_statsd.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 460 of file res_statsd.c.

◆ AO2_GLOBAL_OBJ_STATIC()

static AO2_GLOBAL_OBJ_STATIC ( confs  )
static

Locking container for safe configuration access.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 460 of file res_statsd.c.

◆ ast_statsd_log()

void AST_OPTIONAL_API_NAME() ast_statsd_log ( const char *  metric_name,
const char *  metric_type,
intmax_t  value 
)

Send a stat to the configured statsd server.

Parameters
metric_nameString (UTF-8) name of the metric.
metric_typeType of metric to send.
valueValue to send.
Since
12

Definition at line 251 of file res_statsd.c.

253{
254 char char_value[30];
255 snprintf(char_value, sizeof(char_value), "%jd", value);
256
257 ast_statsd_log_string(metric_name, metric_type, char_value, 1.0);
258}
void AST_OPTIONAL_API_NAME() 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:136
int value
Definition: syslog.c:37

References ast_statsd_log_string(), and value.

Referenced by load_module(), statsmaker(), and updates().

◆ ast_statsd_log_full()

void AST_OPTIONAL_API_NAME() 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.

The is nearly the most flexible function for sending a message to the statsd server, but also the least easy to use. See ast_statsd_log() or ast_statsd_log_sample() for a slightly more convenient interface.

Parameters
metric_nameString (UTF-8) name of the metric.
metric_typeType of metric to send.
valueValue to send.
sample_ratePercentage of samples to send.
Since
12

Definition at line 193 of file res_statsd.c.

195{
196 char char_value[30];
197 snprintf(char_value, sizeof(char_value), "%jd", value);
198
199 ast_statsd_log_string(metric_name, metric_type, char_value, sample_rate);
200
201}

References ast_statsd_log_string(), and value.

Referenced by ast_statsd_log_full_va().

◆ ast_statsd_log_full_va()

void AST_OPTIONAL_API_NAME() 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.

Since
13.7.0

This is the most flexible function for sending a message to the statsd server. In addition to allowing the value and sample rate to be specified, the metric_name can be formed as a printf style string with variable arguments.

Parameters
metric_nameFormat string (UTF-8) specifying the name of the metric.
metric_typeType of metric to send.
valueValue to send.
sample_ratePercentage of samples to send.

Example Usage:

ast_statsd_log_full_va(AST_STATSD_TIMER, rtt, 1.0, "endpoint.%s.rtt", endpoint_name);
#define AST_STATSD_TIMER
Definition: statsd.h:41
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:228

Definition at line 228 of file res_statsd.c.

230{
231 struct ast_str *buf;
232 va_list ap;
233 int res;
234
236 if (!buf) {
237 return;
238 }
239
240 va_start(ap, sample_rate);
241 res = ast_str_set_va(&buf, 0, metric_name, ap);
242 va_end(ap);
243
244 if (res == AST_DYNSTR_BUILD_FAILED) {
245 return;
246 }
247
248 ast_statsd_log_full(ast_str_buffer(buf), metric_type, value, sample_rate);
249}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
void AST_OPTIONAL_API_NAME() 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:193
static struct ast_threadstorage statsd_buf
Definition: res_statsd.c:203
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition: strings.h:1030
@ AST_DYNSTR_BUILD_FAILED
Definition: strings.h:943
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:909
Support for dynamic strings.
Definition: strings.h:623

References AST_DYNSTR_BUILD_FAILED, ast_statsd_log_full(), ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), buf, statsd_buf, and value.

Referenced by ast_sip_initialize_sorcery_location(), handle_endpoint_update(), and sip_options_contact_status_notify_task().

◆ ast_statsd_log_sample()

void AST_OPTIONAL_API_NAME() 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.

The type of sampled metrics is always AST_STATSD_COUNTER. The given sample_rate should be a percentage between 0.0 and 1.0. If it's <= 0.0, then no samples will be sent. If it's >= 1.0, then all samples will be sent.

Parameters
metric_nameString (UTF-8) name of the metric.
valueValue to send.
sample_ratePercentage of samples to send.
Since
12

Definition at line 260 of file res_statsd.c.

262{
263 char char_value[30];
264 snprintf(char_value, sizeof(char_value), "%jd", value);
265
266 ast_statsd_log_string(metric_name, AST_STATSD_COUNTER, char_value,
267 sample_rate);
268}
#define AST_STATSD_COUNTER
Definition: statsd.h:39

References AST_STATSD_COUNTER, ast_statsd_log_string(), and value.

◆ ast_statsd_log_string()

void AST_OPTIONAL_API_NAME() 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.

This function uses a character argument for value instead of an intmax_t argument. This is designed to be simpler to use for updating a current value rather than resetting it.

Parameters
metric_nameString (UTF-8) name of the metric.
metric_typeType of metric to send.
valueValue to send.
sample_ratePercentage of samples to send.
Since
13

Definition at line 136 of file res_statsd.c.

138{
139 struct conf *cfg;
140 struct ast_str *msg;
141 size_t len;
142 struct ast_sockaddr statsd_server;
143
144 if (socket_fd == -1) {
145 return;
146 }
147
148 /* Rates <= 0.0 never get logged.
149 * Rates >= 1.0 always get logged.
150 * All others leave it to chance.
151 */
152 if (sample_rate <= 0.0 ||
153 (sample_rate < 1.0 && sample_rate < ast_random_double())) {
154 return;
155 }
156
158 conf_server(cfg, &statsd_server);
159
160 msg = ast_str_create(40);
161 if (!msg) {
162 ao2_cleanup(cfg);
163 return;
164 }
165
166 if (!ast_strlen_zero(cfg->global->prefix)) {
167 ast_str_append(&msg, 0, "%s.", cfg->global->prefix);
168 }
169
170 if (!cfg->global->meter_support && strcmp(metric_type, AST_STATSD_METER)) {
171 ast_str_append(&msg, 0, "%s_meter:%s|%s", metric_name, value, AST_STATSD_COUNTER);
172 } else {
173 ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);
174 }
175
176 if (sample_rate < 1.0) {
177 ast_str_append(&msg, 0, "|@%.2f", sample_rate);
178 }
179
180 if (cfg->global->add_newline) {
181 ast_str_append(&msg, 0, "\n");
182 }
183
184 len = ast_str_strlen(msg);
185
186 ast_debug(6, "Sending statistic %s to StatsD server\n", ast_str_buffer(msg));
187 ast_sendto(socket_fd, ast_str_buffer(msg), len, 0, &statsd_server);
188
189 ao2_cleanup(cfg);
190 ast_free(msg);
191}
#define ast_free(a)
Definition: astmm.h:180
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_debug(level,...)
Log a DEBUG message.
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
Definition: netsock2.c:614
static void conf_server(const struct conf *cfg, struct ast_sockaddr *addr)
Definition: res_statsd.c:128
static int socket_fd
Definition: res_statsd.c:103
#define AST_STATSD_METER
Definition: statsd.h:48
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
Socket address structure.
Definition: netsock2.h:97
char prefix[MAX_PREFIX+1]
Definition: res_statsd.c:114
All configuration options for http media cache.
struct conf_global_options * global
Definition: res_statsd.c:122
#define ast_random_double()
Returns a random number between 0.0 and 1.0, inclusive.
Definition: utils.h:624

References conf_global_options::add_newline, ao2_cleanup, ao2_global_obj_ref, ast_debug, ast_free, ast_random_double, ast_sendto(), AST_STATSD_COUNTER, AST_STATSD_METER, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_strlen(), ast_strlen_zero(), conf_server(), conf::global, len(), conf_global_options::meter_support, conf_global_options::prefix, socket_fd, and value.

Referenced by ast_statsd_log(), ast_statsd_log_full(), ast_statsd_log_sample(), ast_statsd_log_string_va(), handle_endpoint_update(), sip_outbound_registration_client_state_destroy(), sip_outbound_registration_state_alloc(), statsd_exec(), update_endpoint_state(), and updates().

◆ ast_statsd_log_string_va()

void AST_OPTIONAL_API_NAME() 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.

Since
13.7.0

This is the most flexible function for sending a message to the statsd server. In addition to allowing the string value and sample rate to be specified, the metric_name can be formed as a printf style string with variable arguments.

Parameters
metric_nameFormat string (UTF-8) specifying the name of the metric.
metric_typeType of metric to send.
valueValue to send.
sample_ratePercentage of samples to send.

Example Usage:

ast_statsd_log_string_va(AST_STATSD_GAUGE, "+1", 1.0, "endpoints.states.%s", state_name);
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:205
#define AST_STATSD_GAUGE
Support for publishing to a statsd server.
Definition: statsd.h:32

Definition at line 205 of file res_statsd.c.

207{
208 struct ast_str *buf;
209 va_list ap;
210 int res;
211
213 if (!buf) {
214 return;
215 }
216
217 va_start(ap, sample_rate);
218 res = ast_str_set_va(&buf, 0, metric_name, ap);
219 va_end(ap);
220
221 if (res == AST_DYNSTR_BUILD_FAILED) {
222 return;
223 }
224
225 ast_statsd_log_string(ast_str_buffer(buf), metric_type, value, sample_rate);
226}

References AST_DYNSTR_BUILD_FAILED, ast_statsd_log_string(), ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), buf, statsd_buf, and value.

Referenced by ast_res_pjsip_find_or_create_contact_status(), sip_options_contact_status_notify_task(), sip_options_remove_contact_status(), sip_options_set_contact_status(), sip_outbound_registration_client_state_destroy(), sip_outbound_registration_state_alloc(), and update_client_state_status().

◆ conf_alloc()

static void * conf_alloc ( void  )
static

Creates the statis http conf object.

Definition at line 290 of file res_statsd.c.

291{
292 struct conf *cfg;
293
294 if (!(cfg = ao2_alloc(sizeof(*cfg), conf_destructor))) {
295 return NULL;
296 }
297
298 if (!(cfg->global = ao2_alloc(sizeof(*cfg->global), NULL))) {
299 ao2_ref(cfg, -1);
300 return NULL;
301 }
302 return cfg;
303}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static void conf_destructor(void *obj)
Disposes of the statsd conf object.
Definition: res_statsd.c:283
#define NULL
Definition: resample.c:96

References ao2_alloc, ao2_ref, conf_destructor(), conf::global, and NULL.

Referenced by load_module().

◆ conf_destructor()

static void conf_destructor ( void *  obj)
static

Disposes of the statsd conf object.

Definition at line 283 of file res_statsd.c.

284{
285 struct conf *cfg = obj;
286 ao2_cleanup(cfg->global);
287}

References ao2_cleanup, and conf::global.

Referenced by conf_alloc().

◆ conf_server()

static void conf_server ( const struct conf cfg,
struct ast_sockaddr addr 
)
static

Definition at line 128 of file res_statsd.c.

129{
130 *addr = cfg->global->statsd_server;
131 if (ast_sockaddr_port(addr) == 0) {
133 }
134}
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:517
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:532
#define DEFAULT_STATSD_PORT
Definition: res_statsd.c:98
struct ast_sockaddr statsd_server
Definition: res_statsd.c:112

References ast_sockaddr_port, ast_sockaddr_set_port, DEFAULT_STATSD_PORT, conf::global, and conf_global_options::statsd_server.

Referenced by ast_statsd_log_string(), and statsd_init().

◆ CONFIG_INFO_STANDARD()

CONFIG_INFO_STANDARD ( cfg_info  ,
confs  ,
conf_alloc  ,
files = ACO_FILES(&conf_file) 
)

◆ is_enabled()

static char is_enabled ( void  )
static

Helper function to check if module is enabled.

Definition at line 317 of file res_statsd.c.

318{
320 return cfg->global->enabled;
321}
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_cleanup, ao2_global_obj_ref, and RAII_VAR.

Referenced by load_module(), reload_module(), and statsd_init().

◆ load_module()

static int load_module ( void  )
static

Definition at line 369 of file res_statsd.c.

370{
371 if (aco_info_init(&cfg_info)) {
372 aco_info_destroy(&cfg_info);
374 }
375
376 aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options,
377 "no", OPT_BOOL_T, 1,
379
380 aco_option_register(&cfg_info, "add_newline", ACO_EXACT, global_options,
381 "no", OPT_BOOL_T, 1,
382 FLDSET(struct conf_global_options, add_newline));
383
384 aco_option_register(&cfg_info, "server", ACO_EXACT, global_options,
385 "127.0.0.1", OPT_SOCKADDR_T, 0,
386 FLDSET(struct conf_global_options, statsd_server));
387
388 aco_option_register(&cfg_info, "prefix", ACO_EXACT, global_options,
389 "", OPT_CHAR_ARRAY_T, 0,
391
392 aco_option_register(&cfg_info, "meter_support", ACO_EXACT, global_options,
393 "yes", OPT_BOOL_T, 1,
394 FLDSET(struct conf_global_options, meter_support));
395
396 if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
397 struct conf *cfg;
398
399 ast_log(LOG_NOTICE, "Could not load statsd config; using defaults\n");
400 cfg = conf_alloc();
401 if (!cfg) {
402 aco_info_destroy(&cfg_info);
404 }
405
406 if (aco_set_defaults(&global_option, "general", cfg->global)) {
407 ast_log(LOG_ERROR, "Failed to initialize statsd defaults.\n");
408 ao2_ref(cfg, -1);
409 aco_info_destroy(&cfg_info);
411 }
412
414 ao2_ref(cfg, -1);
415 }
416
417 if (!is_enabled()) {
419 }
420
421 if (statsd_init()) {
424 }
425
427}
#define ast_log
Definition: astobj2.c:42
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition: astobj2.h:901
@ ACO_EXACT
int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
Set all default options of obj.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define CHARFLDSET(type, field)
A helper macro to pass the appropriate arguments to aco_option_register for OPT_CHAR_ARRAY_T.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_CHAR_ARRAY_T
Type for default option handler for character array strings.
@ OPT_SOCKADDR_T
Type for default handler for ast_sockaddrs.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
static int enabled
Definition: dnsmgr.c:91
static char prefix[MAX_PREFIX]
Definition: http.c:144
#define LOG_ERROR
#define LOG_NOTICE
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct aco_type * global_options[]
Definition: res_statsd.c:280
static char is_enabled(void)
Helper function to check if module is enabled.
Definition: res_statsd.c:317
static void * conf_alloc(void)
Creates the statis http conf object.
Definition: res_statsd.c:290
static int unload_module(void)
Definition: res_statsd.c:361
static int statsd_init(void)
Definition: res_statsd.c:323
static struct aco_type global_option
Mapping of the statsd conf struct's globals to the general context in the config file.
Definition: res_statsd.c:272
Global configuration options for statsd client.
Definition: res_statsd.c:106

References ACO_EXACT, aco_info_destroy(), aco_info_init(), aco_option_register, aco_process_config(), ACO_PROCESS_ERROR, aco_set_defaults(), ao2_global_obj_replace_unref, ao2_ref, ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, CHARFLDSET, conf_alloc(), enabled, FLDSET, conf::global, global_option, global_options, is_enabled(), LOG_ERROR, LOG_NOTICE, OPT_BOOL_T, OPT_CHAR_ARRAY_T, OPT_SOCKADDR_T, prefix, statsd_init(), and unload_module().

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 429 of file res_statsd.c.

430{
431 switch (aco_process_config(&cfg_info, 1)) {
432 case ACO_PROCESS_OK:
433 break;
437 default:
439 }
440
441 if (is_enabled()) {
442 if (statsd_init()) {
444 }
445 } else {
447 }
449}
@ ACO_PROCESS_UNCHANGED
The config had not been edited and no changes applied.
@ ACO_PROCESS_OK
The config was processed and applied.
static void statsd_shutdown(void)
Definition: res_statsd.c:352

References aco_process_config(), ACO_PROCESS_ERROR, ACO_PROCESS_OK, ACO_PROCESS_UNCHANGED, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, is_enabled(), statsd_init(), and statsd_shutdown().

◆ statsd_init()

static int statsd_init ( void  )
static

Definition at line 323 of file res_statsd.c.

324{
326 char *server;
327 struct ast_sockaddr statsd_server;
328
330
331 ast_debug(3, "Configuring StatsD client.\n");
332
333 if (socket_fd == -1) {
334 ast_debug(3, "Creating StatsD socket.\n");
335 socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
336 if (socket_fd == -1) {
337 perror("Error creating StatsD socket");
338 return -1;
339 }
340 }
341
342 conf_server(cfg, &statsd_server);
343 server = ast_sockaddr_stringify_fmt(&statsd_server,
345 ast_debug(3, " StatsD server = %s.\n", server);
346 ast_debug(3, " add newline = %s\n", AST_YESNO(cfg->global->add_newline));
347 ast_debug(3, " prefix = %s\n", cfg->global->prefix);
348
349 return 0;
350}
char * ast_sockaddr_stringify_fmt(const struct ast_sockaddr *addr, int format)
Convert a socket address to a string.
Definition: netsock2.c:65
#define AST_SOCKADDR_STR_DEFAULT
Definition: netsock2.h:203
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:143
#define ast_assert(a)
Definition: utils.h:739

References ao2_cleanup, ao2_global_obj_ref, ast_assert, ast_debug, AST_SOCKADDR_STR_DEFAULT, ast_sockaddr_stringify_fmt(), AST_YESNO, conf_server(), is_enabled(), RAII_VAR, and socket_fd.

Referenced by load_module(), and reload_module().

◆ statsd_shutdown()

static void statsd_shutdown ( void  )
static

Definition at line 352 of file res_statsd.c.

353{
354 ast_debug(3, "Shutting down StatsD client.\n");
355 if (socket_fd != -1) {
356 close(socket_fd);
357 socket_fd = -1;
358 }
359}

References ast_debug, and socket_fd.

Referenced by reload_module(), and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 361 of file res_statsd.c.

362{
364 aco_info_destroy(&cfg_info);
366 return 0;
367}
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition: astobj2.h:859

References aco_info_destroy(), ao2_global_obj_release, and statsd_shutdown().

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "StatsD client support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_REALTIME_DRIVER + 5, }
static

Definition at line 460 of file res_statsd.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 460 of file res_statsd.c.

◆ conf_file

struct aco_file conf_file
static

The conf file that's processed for the module.

Definition at line 306 of file res_statsd.c.

◆ global_option

struct aco_type global_option
static

Mapping of the statsd conf struct's globals to the general context in the config file.

Definition at line 272 of file res_statsd.c.

Referenced by load_module().

◆ global_options

struct aco_type* global_options[] = ACO_TYPES(&global_option)
static

Definition at line 280 of file res_statsd.c.

Referenced by load_module().

◆ socket_fd

int socket_fd = -1
static

Socket for sending statd messages

Definition at line 103 of file res_statsd.c.

Referenced by ast_statsd_log_string(), statsd_init(), and statsd_shutdown().

◆ statsd_buf

struct ast_threadstorage statsd_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_statsd_buf , .custom_init = NULL , }
static

Definition at line 203 of file res_statsd.c.

Referenced by ast_statsd_log_full_va(), and ast_statsd_log_string_va().