72 #define AST_API_MODULE 75 #define DEFAULT_STATSD_PORT 8125 112 const char *metric_type,
const char *
value,
double sample_rate)
127 if (sample_rate <= 0.0 ||
147 if (sample_rate < 1.0) {
165 const char *metric_type, intmax_t
value,
double sample_rate)
168 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
177 const char *metric_type,
const char *
value,
double sample_rate, ...)
188 va_start(ap, sample_rate);
200 const char *metric_type, intmax_t
value,
double sample_rate, ...)
211 va_start(ap, sample_rate);
223 const char *metric_type, intmax_t
value)
226 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
232 intmax_t
value,
double sample_rate)
235 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
247 .category =
"general",
256 struct conf *cfg = obj;
291 return cfg->global->enabled;
302 ast_debug(3,
"Configuring StatsD client.\n");
305 ast_debug(3,
"Creating StatsD socket.\n");
306 socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
308 perror(
"Error creating StatsD socket");
316 ast_debug(3,
" StatsD server = %s.\n", server);
318 ast_debug(3,
" prefix = %s\n", cfg->global->prefix);
325 ast_debug(3,
"Shutting down StatsD client.\n");
Type for default handler for ast_sockaddrs.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
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.
Asterisk main include file. File version handling, generic pbx functions.
static void * conf_alloc(void)
Creates the statis http conf object.
static struct aco_type global
struct conf_global_options * global
static void statsd_shutdown(void)
static char is_enabled(void)
Helper function to check if module is enabled.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
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.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
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.
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.
#define CHARFLDSET(type, field)
A helper macro to pass the appropriate arguments to aco_option_register for OPT_CHAR_ARRAY_T.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
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 unload_module(void)
#define ao2_global_obj_ref(holder)
static void conf_destructor(void *obj)
Disposes of the statsd conf object.
The representation of a single configuration file to be processed.
Socket address structure.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
static struct aco_file conf_file
The conf file that's processed for the module.
#define AST_SOCKADDR_STR_DEFAULT
struct ast_sockaddr statsd_server
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.
#define ast_strlen_zero(foo)
All configuration options for statsd client.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Type for default option handler for character array strings.
#define ast_debug(level,...)
Log a DEBUG message.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ao2_ref(o, delta)
static int reload_module(void)
The config had not been edited and no changes applied.
Their was an error and no changes were applied.
static struct aco_type * global_options[]
Configuration option-handling.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
Type for default option handler for bools (ast_true/ast_false)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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.
#define ao2_alloc(data_size, destructor_fn)
char * ast_sockaddr_stringify_fmt(const struct ast_sockaddr *addr, int format)
Convert a socket address to a string.
int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
Set all default options of obj.
static AO2_GLOBAL_OBJ_STATIC(confs)
Locking container for safe configuration access.
The config was processed and applied.
Module has failed to load, may be in an inconsistent state.
Global configuration options for statsd client.
static struct ast_threadstorage statsd_buf
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static int load_module(void)
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.
static struct aco_type global_option
Mapping of the statsd conf struct's globals to the general context in the config file.
#define AST_YESNO(x)
return Yes or No depending on the argument.
#define ao2_global_obj_replace_unref(holder, obj)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
char prefix[MAX_PREFIX+1]
Type information about a category-level configurable object.
static int statsd_init(void)
#define ast_random_double()
Returns a random number between 0.0 and 1.0, inclusive.
#define AST_OPTIONAL_API_NAME(name)
Expands to the name of the implementation function.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
#define ASTERISK_GPL_KEY
The text the key() function should return.
static void conf_server(const struct conf *cfg, struct ast_sockaddr *addr)
Asterisk module definitions.
#define AST_STATSD_COUNTER
#define DEFAULT_STATSD_PORT
CONFIG_INFO_STANDARD(cfg_info, confs, conf_alloc,.files=ACO_FILES(&conf_file))
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.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.