37 if (cmd == CLI_INIT) {
38 e->
command =
"prometheus show metrics";
40 "Usage: prometheus show metrics\n"
41 " Displays the current metrics and their values,\n"
42 " without counting as an actual scrape.\n";
44 }
else if (cmd == CLI_GENERATE) {
54 ast_cli(a->fd,
"Egads! An unknown error occurred getting the metrics\n");
67 struct ast_tm last_scrape_local;
68 struct timeval last_scrape_time;
69 int64_t scrape_duration;
71 if (cmd == CLI_INIT) {
72 e->
command =
"prometheus show status";
74 "Usage: prometheus show status\n"
75 " Displays the status of metrics collection.\n";
77 }
else if (cmd == CLI_GENERATE) {
87 ast_cli(a->fd,
"Prometheus Metrics Status:\n");
88 ast_cli(a->fd,
"\tEnabled: %s\n", config->
enabled ?
"Yes" :
"No");
89 ast_cli(a->fd,
"\tURI: %s\n", config->
uri);
90 ast_cli(a->fd,
"\tBasic Auth: %s\n", ast_strlen_zero(config->
auth_username) ?
"No":
"Yes");
91 ast_cli(a->fd,
"\tLast Scrape Time: ");
93 if (last_scrape_time.tv_sec == 0 && last_scrape_time.tv_usec == 0) {
94 snprintf(time_buffer,
sizeof(time_buffer),
"%s",
"(N/A)");
97 ast_strftime(time_buffer,
sizeof(time_buffer),
"%Y-%m-%d %H:%M:%S", &last_scrape_local);
99 ast_cli(a->fd,
"%s\n", time_buffer);
101 ast_cli(a->fd,
"\tLast Scrape Duration: ");
103 if (scrape_duration < 0) {
104 ast_cli(a->fd,
"(N/A)\n");
106 ast_cli(a->fd,
"%" PRIu64
" ms\n", scrape_duration);
115 AST_CLI_DEFINE(prometheus_show_metrics,
"Display the current metrics and their values"),
116 AST_CLI_DEFINE(prometheus_show_status,
"Display the status of Prometheus metrics collection"),
123 static void cli_unload_cb(
void)
134 .unload_cb = cli_unload_cb,
Asterisk main include file. File version handling, generic pbx functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Prometheus general configuration.
Prometheus Metric Internal API.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
#define ast_cli_register_multiple(e, len)
Register multiple commands.
int cli_init(void)
Initialize CLI command.
int64_t prometheus_last_scrape_duration_get(void)
Retrieve the amount of time it took to perform the last scrape.
Custom localtime functions for multiple timezones.
struct timeval prometheus_last_scrape_time_get(void)
Retrieve the timestamp when the last scrape occurred.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
Asterisk Prometheus Metrics.
Support for dynamic strings.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
const char * name
Handy name of the provider for debugging purposes.
const ast_string_field uri
The HTTP URI we register ourselves to.
struct ast_str * prometheus_scrape_to_string(void)
Get the raw output of what a scrape would produce.
Standard Command Line Interface.
A function table for a metrics provider.
struct prometheus_general_config * prometheus_general_config_get(void)
Retrieve the current configuration of the module.
const ast_string_field auth_username
Auth username for Basic Auth.
unsigned int enabled
Whether or not the module is enabled.