Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
#include "asterisk.h"
#include "asterisk/config_options.h"
#include "asterisk/module.h"
#include "asterisk/netsock2.h"
#include "asterisk/statsd.h"
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_module * | AST_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_info * | ast_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_type * | global_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 , } |
#define AST_API_MODULE |
#define DEFAULT_STATSD_PORT 8125 |
Definition at line 79 of file res_statsd.c.
#define MAX_PREFIX 40 |
Definition at line 81 of file res_statsd.c.
|
static |
Definition at line 184 of file res_statsd.c.
|
static |
Definition at line 441 of file res_statsd.c.
|
static |
Definition at line 441 of file res_statsd.c.
|
static |
Locking container for safe configuration access.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 441 of file res_statsd.c.
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.
metric_name | String (UTF-8) name of the metric. |
metric_type | Type of metric to send. |
value | Value to send. |
Definition at line 232 of file res_statsd.c.
References ast_statsd_log_string(), and value.
Referenced by load_module(), statsmaker(), and updates().
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.
metric_name | String (UTF-8) name of the metric. |
metric_type | Type of metric to send. |
value | Value to send. |
sample_rate | Percentage of samples to send. |
Definition at line 174 of file res_statsd.c.
References ast_statsd_log_string(), and value.
Referenced by 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.
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.
metric_name | Format string (UTF-8) specifying the name of the metric. |
metric_type | Type of metric to send. |
value | Value to send. |
sample_rate | Percentage of samples to send. |
Example Usage:
Definition at line 209 of file res_statsd.c.
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().
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.
metric_name | String (UTF-8) name of the metric. |
value | Value to send. |
sample_rate | Percentage of samples to send. |
Definition at line 241 of file res_statsd.c.
References AST_STATSD_COUNTER, ast_statsd_log_string(), and value.
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.
metric_name | String (UTF-8) name of the metric. |
metric_type | Type of metric to send. |
value | Value to send. |
sample_rate | Percentage of samples to send. |
Definition at line 117 of file res_statsd.c.
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().
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.
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.
metric_name | Format string (UTF-8) specifying the name of the metric. |
metric_type | Type of metric to send. |
value | Value to send. |
sample_rate | Percentage of samples to send. |
Example Usage:
Definition at line 186 of file res_statsd.c.
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().
|
static |
Creates the statis http conf object.
Definition at line 271 of file res_statsd.c.
References ao2_alloc, ao2_ref, conf_destructor(), conf::global, and NULL.
Referenced by load_module().
|
static |
Disposes of the statsd conf object.
Definition at line 264 of file res_statsd.c.
References ao2_cleanup, and conf::global.
Referenced by conf_alloc().
|
static |
Definition at line 109 of file res_statsd.c.
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 | ( | cfg_info | , |
confs | , | ||
conf_alloc | , | ||
. | files = ACO_FILES(&conf_file) |
||
) |
|
static |
Helper function to check if module is enabled.
Definition at line 298 of file res_statsd.c.
References ao2_cleanup, ao2_global_obj_ref, and RAII_VAR.
Referenced by load_module(), reload_module(), and statsd_init().
|
static |
Definition at line 350 of file res_statsd.c.
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().
|
static |
Definition at line 410 of file res_statsd.c.
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().
|
static |
Definition at line 304 of file res_statsd.c.
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().
|
static |
Definition at line 333 of file res_statsd.c.
References ast_debug, and socket_fd.
Referenced by reload_module(), and unload_module().
|
static |
Definition at line 342 of file res_statsd.c.
References aco_info_destroy(), ao2_global_obj_release, and statsd_shutdown().
Referenced by load_module().
|
static |
Definition at line 441 of file res_statsd.c.
|
static |
Definition at line 441 of file res_statsd.c.
|
static |
The conf file that's processed for the module.
Definition at line 287 of file res_statsd.c.
|
static |
Mapping of the statsd conf struct's globals to the general context in the config file.
Definition at line 253 of file res_statsd.c.
Referenced by load_module().
|
static |
Definition at line 261 of file res_statsd.c.
Referenced by load_module().
|
static |
Socket for sending statd messages
Definition at line 84 of file res_statsd.c.
Referenced by ast_statsd_log_string(), statsd_init(), and statsd_shutdown().
|
static |
Definition at line 184 of file res_statsd.c.
Referenced by ast_statsd_log_full_va(), and ast_statsd_log_string_va().