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";
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;
72 e->
command =
"prometheus show status";
74 "Usage: prometheus show status\n"
75 " Displays the status of metrics collection.\n";
87 ast_cli(
a->fd,
"Prometheus Metrics Status:\n");
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);
101 ast_cli(
a->fd,
"\tLast Scrape Duration: ");
103 if (scrape_duration < 0) {
106 ast_cli(
a->fd,
"%" PRIu64
" ms\n", scrape_duration);
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
static const char config[]
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Custom localtime functions for multiple timezones.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
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...
Prometheus Metric Internal API.
struct ast_str * prometheus_scrape_to_string(void)
Get the raw output of what a scrape would produce.
struct timeval prometheus_last_scrape_time_get(void)
Retrieve the timestamp when the last scrape occurred.
int64_t prometheus_last_scrape_duration_get(void)
Retrieve the amount of time it took to perform the last scrape.
static char * prometheus_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * prometheus_show_metrics(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int cli_init(void)
Initialize CLI command.
static void cli_unload_cb(void)
static struct ast_cli_entry cli_prometheus[]
static struct prometheus_metrics_provider provider
Asterisk Prometheus Metrics.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
struct prometheus_general_config * prometheus_general_config_get(void)
Retrieve the current configuration of the module.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
descriptor for a cli entry.
Support for dynamic strings.
Prometheus general configuration.
A function table for a metrics provider.
const char * name
Handy name of the provider for debugging purposes.