79#define DEFAULT_STATSD_PORT 8125
118 const char *metric_type,
const char *
value,
double sample_rate)
133 if (sample_rate <= 0.0 ||
157 if (sample_rate < 1.0) {
175 const char *metric_type, intmax_t
value,
double sample_rate)
178 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
187 const char *metric_type,
const char *
value,
double sample_rate, ...)
198 va_start(ap, sample_rate);
210 const char *metric_type, intmax_t
value,
double sample_rate, ...)
221 va_start(ap, sample_rate);
233 const char *metric_type, intmax_t
value)
236 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
242 intmax_t
value,
double sample_rate)
245 snprintf(char_value,
sizeof(char_value),
"%jd",
value);
257 .category =
"general",
266 struct conf *cfg = obj;
301 return cfg->global->enabled;
312 ast_debug(3,
"Configuring StatsD client.\n");
315 ast_debug(3,
"Creating StatsD socket.\n");
316 socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
318 perror(
"Error creating StatsD socket");
326 ast_debug(3,
" StatsD server = %s.\n", server);
328 ast_debug(3,
" prefix = %s\n", cfg->global->prefix);
335 ast_debug(3,
"Shutting down StatsD client.\n");
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
#define ao2_alloc(data_size, destructor_fn)
Configuration option-handling.
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_UNCHANGED
The config had not been edited and no changes applied.
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
@ ACO_PROCESS_OK
The config was processed and 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.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char prefix[MAX_PREFIX]
#define ast_debug(level,...)
Log a DEBUG message.
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_REALTIME_DRIVER
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
char * ast_sockaddr_stringify_fmt(const struct ast_sockaddr *addr, int format)
Convert a socket address to a string.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
#define AST_SOCKADDR_STR_DEFAULT
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.
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
#define AST_OPTIONAL_API_NAME(name)
Expands to the name of the implementation function.
static struct aco_type * global_options[]
CONFIG_INFO_STANDARD(cfg_info, confs, conf_alloc,.files=ACO_FILES(&conf_file))
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.
static char is_enabled(void)
Helper function to check if module is enabled.
static void * conf_alloc(void)
Creates the statis http conf object.
static void statsd_shutdown(void)
static AO2_GLOBAL_OBJ_STATIC(confs)
Locking container for safe configuration access.
static struct aco_file conf_file
The conf file that's processed for the module.
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.
static int reload_module(void)
static void conf_destructor(void *obj)
Disposes of the statsd conf object.
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 void conf_server(const struct conf *cfg, struct ast_sockaddr *addr)
static struct ast_threadstorage statsd_buf
#define DEFAULT_STATSD_PORT
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.
static int load_module(void)
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.
static int unload_module(void)
static int statsd_init(void)
static struct aco_type global_option
Mapping of the statsd conf struct's globals to the general context in the config 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_STATSD_COUNTER
@ AST_DYNSTR_BUILD_FAILED
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define AST_YESNO(x)
return Yes or No depending on the argument.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
The representation of a single configuration file to be processed.
Type information about a category-level configurable object.
Socket address structure.
Support for dynamic strings.
Global configuration options for statsd client.
struct ast_sockaddr statsd_server
char prefix[MAX_PREFIX+1]
All configuration options for http media cache.
struct conf_global_options * global
static struct aco_type global
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_random_double()
Returns a random number between 0.0 and 1.0, inclusive.