From 666234f661f5426630aa07554a67a47656bde656 Mon Sep 17 00:00:00 2001 From: fumingwei Date: Wed, 15 Mar 2023 14:18:08 +0800 Subject: feature:review后修改 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fieldstat.cpp | 167 ++++++++++++++++++++++++------------------- src/fieldstat_internal.h | 21 +++--- src/file_output.cpp | 18 ++--- src/line_protocol_output.cpp | 4 +- src/prometheus_output.cpp | 18 ++--- 5 files changed, 124 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/fieldstat.cpp b/src/fieldstat.cpp index a50cb03..e6c62c4 100644 --- a/src/fieldstat.cpp +++ b/src/fieldstat.cpp @@ -61,12 +61,12 @@ void get_current_table_line_cnt(struct fieldstat_instance *instance, int n_table } } -struct metric_t * get_metric(struct fieldstat_instance *instance, int metric_id) +struct metric * get_metric(struct fieldstat_instance *instance, int metric_id) { int block_index = 0; int block_in_index = 0; - struct metric_t ** metrics_array = NULL; - struct metric_t * metric = NULL; + struct metric ** metrics_array = NULL; + struct metric * metric = NULL; if(instance == NULL) { @@ -81,26 +81,54 @@ struct metric_t * get_metric(struct fieldstat_instance *instance, int metric_id) return metric; } - -struct metric_t* metric_new(enum field_type type, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag) +void add_tags_to_metric(const struct fieldstat_tag tags[], size_t n_tag, char *tag_key[], char *tag_value[]) { int i = 0; - struct metric_t* metric=(struct metric_t*)calloc(sizeof(struct metric_t),1); - metric->field_name =__str_dup(field_name); + struct fieldstat_tag *tag = NULL; + char str_longlong[32] = {0}; + char str_double[32] = {0}; + + for(i = 0; i < (int)n_tag; i++) + { + tag = (struct fieldstat_tag *)&tags[i]; + tag_key[i] = __str_dup(tag->key); + switch(tag->value_type) + { + case 0: + memset(str_longlong, 0, sizeof(str_longlong)); + snprintf(str_longlong, sizeof(str_longlong), "%lld", tag->value_int); + tag_value[i] = __str_dup((const char *)str_longlong); + break; + case 1: + memset(str_double, 0, sizeof(str_double)); + snprintf(str_double, sizeof(str_double), "%lf", tag->value_double); + tag_value[i] = __str_dup((const char *)str_double); + break; + case 2: + tag_value[i] = __str_dup(tag->value_str); + break; + default: + assert(0); + break; + } + } +} + +struct metric * metric_new(enum field_type type, const char *field_name, const struct fieldstat_tag tags[], size_t n_tag) +{ + struct metric *metric = (struct metric*)calloc(sizeof(struct metric),1); + metric->field_name = __str_dup(field_name); metric->field_type = type; metric->is_ratio = 0; metric->output_scaling = 1; metric->n_tag = n_tag; - for(i = 0; i < (int)n_tag; i++) - { - metric->tag_key[i] = __str_dup(tag_key[i]); - metric->tag_value[i] = __str_dup(tag_value[i]); - } + add_tags_to_metric(tags, n_tag, metric->tag_key, metric->tag_value); + return metric; } -void metric_free(struct metric_t* metric) +void metric_free(struct metric *metric) { int i = 0; @@ -122,11 +150,11 @@ void metric_free(struct metric_t* metric) return; } -struct metric_t ** read_metric_slot(struct fieldstat_instance *instance, int metric_id) +struct metric ** read_metric_slot(struct fieldstat_instance *instance, int metric_id) { int block_index = 0; int in_block_index = 0; - struct metric_t ** metrics_block = NULL; + struct metric ** metrics_block = NULL; if(instance == NULL) { @@ -137,15 +165,15 @@ struct metric_t ** read_metric_slot(struct fieldstat_instance *instance, int met if(in_block_index == 0) { assert(instance->metric_block_list[block_index] == NULL); - instance->metric_block_list[block_index] = (struct metric_t **)calloc(sizeof(struct metric *), NUM_INIT_METRICS); + instance->metric_block_list[block_index] = (struct metric **)calloc(sizeof(struct metric *), NUM_INIT_METRICS); } else { while (instance->metric_block_list[block_index] == NULL); } - metrics_block = (struct metric_t **)instance->metric_block_list[block_index]; + metrics_block = (struct metric **)instance->metric_block_list[block_index]; - return (struct metric_t **)&(metrics_block[in_block_index]); + return (struct metric **)&(metrics_block[in_block_index]); } @@ -227,17 +255,17 @@ int send_udp(int sd, unsigned int dest_ip, unsigned short dest_port, const char return 0; } -int fieldstat_set_output_interval(struct fieldstat_instance *instance, int seconds) +int fieldstat_set_output_interval(struct fieldstat_instance *instance, int milliseconds) { - if(instance->running == 1 || seconds <= 0 ) + if(instance->running == 1 || milliseconds <= 0 ) { return -1; } - instance->output_interval_s = seconds; + instance->output_interval_ms = milliseconds; return 0; } -int fieldstat_background_thread_disable(struct fieldstat_instance *instance) +int fieldstat_disable_background_thread(struct fieldstat_instance *instance) { if(instance->running == 1) { @@ -311,11 +339,11 @@ int fieldstat_set_statsd_server(struct fieldstat_instance *instance, const char return 0; } -int fieldstat_register(struct fieldstat_instance *instance, enum field_type type, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag) +int fieldstat_register(struct fieldstat_instance *instance, enum field_type type, const char *field_name, const struct fieldstat_tag tags[], size_t n_tag) { int metric_id = 0; - struct metric_t * metric = NULL; - struct metric_t **metric_slot = NULL; + struct metric *metric = NULL; + struct metric **metric_slot = NULL; if(!is_valid_field_name(field_name)) { return -1; @@ -327,7 +355,7 @@ int fieldstat_register(struct fieldstat_instance *instance, enum field_type type metric_id = atomic_inc(&instance->metric_cnt) - 1; metric_slot = read_metric_slot(instance, metric_id); - metric = metric_new(type,field_name,tag_key,tag_value,n_tag); + metric = metric_new(type, field_name, tags, n_tag); switch(type) { @@ -344,7 +372,7 @@ int fieldstat_register(struct fieldstat_instance *instance, enum field_type type return metric_id; } -long long get_metric_unit_val(struct metric_t *metric,enum field_calc_algo calc_type,int is_refer) +long long get_metric_unit_val(struct metric *metric,enum field_calc_algo calc_type,int is_refer) { stat_unit_t* target = NULL; long long value = 0; @@ -437,7 +465,7 @@ void *fieldstat_thread_schema_output(void *arg) while(instance->background_thread_disable == 0) { fieldstat_passive_output(instance); - sleep(instance->output_interval_s); + usleep(instance->output_interval_ms * 1000); } return NULL; } @@ -454,7 +482,7 @@ void fieldstat_instance_start(struct fieldstat_instance *instance) //append instance to prometheus output } -struct fieldstat_instance * fieldstat_instance_create(const char *name) +struct fieldstat_instance * fieldstat_instance_new(const char *name) { struct fieldstat_instance *instance = NULL; @@ -466,7 +494,7 @@ struct fieldstat_instance * fieldstat_instance_create(const char *name) instance = (struct fieldstat_instance *)calloc(sizeof(struct fieldstat_instance),1); strcpy(instance->name, name); instance->running = 0; - instance->output_interval_s = 2; + instance->output_interval_ms = 2000; instance->background_thread_disable = 0; return instance; @@ -488,7 +516,7 @@ struct table_metric* table_metric_new(const char *name, const char *column_name[ return table_metric; } - int fieldstat_register_table(struct fieldstat_instance *instance, const char *name, const char *column_name[], enum field_type column_type[], size_t n_column) + int fieldstat_register_table(struct fieldstat_instance *instance, const char *table_name, const char *column_name[], enum field_type column_type[], size_t n_column) { int table_id = 0; @@ -505,7 +533,7 @@ struct table_metric* table_metric_new(const char *name, const char *column_name[ } table_id = atomic_inc(&instance->table_num) - 1; - table_metric = table_metric_new(name, column_name, column_type, n_column); + table_metric = table_metric_new(table_name, column_name, column_type, n_column); instance->table_metrics[table_id] = table_metric; return table_id; @@ -533,27 +561,23 @@ static struct table_line ** read_table_line_slot(struct table_metric *table, int return (struct table_line **)&(line[in_block_index]); } -static struct table_line *table_line_new(const char *name, const char *tag_key[], const char *tag_value[],size_t n_tag) +static struct table_line *table_line_new(const char *name, const struct fieldstat_tag tags[],size_t n_tag) { - int i = 0; struct table_line *table_line = (struct table_line *)calloc(sizeof(struct table_line), 1); table_line->name = __str_dup(name); table_line->n_tag = n_tag; - for(i = 0; i < (int)n_tag; i++) - { - table_line->tag_key[i] = __str_dup(tag_key[i]); - table_line->tag_value[i] = __str_dup(tag_value[i]); - } + add_tags_to_metric(tags, n_tag, table_line->tag_key, table_line->tag_value); + return table_line; } -struct metric_id_list fieldstat_register_table_metrics(struct fieldstat_instance * instance, int table_id, const char *line_name, const char *tag_key[], const char *tag_value[],size_t n_tag) +int fieldstat_register_table_row(struct fieldstat_instance * instance, int table_id, const char *row_name, const struct fieldstat_tag tags[], size_t n_tag, int output_metric_ids[], int *output_metric_ids_cnt) { int metric_id = 0; - struct metric_t *metric = NULL; + struct metric *metric = NULL; int line_id = 0; int i = 0; @@ -561,27 +585,24 @@ struct metric_id_list fieldstat_register_table_metrics(struct fieldstat_instance struct table_metric *table = NULL; struct table_line **line_slot = NULL; struct table_line *table_line = NULL; - struct metric_id_list ret_metric_id_list; - memset(&ret_metric_id_list, 0, sizeof(struct metric_id_list)); - if(table_id < 0 || table_id >= TABLE_MAX_NUM) { - return ret_metric_id_list; + return -1; } - if(!is_valid_field_name(line_name) || n_tag > N_TAG_MAX) + if(!is_valid_field_name(row_name) || n_tag > N_TAG_MAX) { - return ret_metric_id_list; + return -1; } table = instance->table_metrics[table_id]; line_id = atomic_inc(&(table->line_cnt)) - 1; - line_slot = read_table_line_slot(table,line_id); - table_line = table_line_new(line_name, tag_key, tag_value, n_tag); + line_slot = read_table_line_slot(table, line_id); + table_line = table_line_new(row_name, tags, n_tag); for(i = 0; i < table->column_cnt; i++) { - metric_id = fieldstat_register(instance, table->column_type[i], line_name,tag_key, tag_value, n_tag); + metric_id = fieldstat_register(instance, table->column_type[i], row_name, tags, n_tag); table_line->metric_id_belong_to_line[i] = metric_id; @@ -590,25 +611,25 @@ struct metric_id_list fieldstat_register_table_metrics(struct fieldstat_instance metric->table_column_name = __str_dup(table->column_name[i]); metric->table_name = __str_dup(table->name); metric->belong_to_table = 1; - ret_metric_id_list.id[ret_metric_id_list.count ++] = metric_id; + output_metric_ids[(*output_metric_ids_cnt)++] = metric_id; } *line_slot = table_line; - return ret_metric_id_list; + return 0; } -static int fieldstat_value_operate(struct fieldstat_instance *instance, int field_id, enum field_op op, long long value) +static int fieldstat_value_operate(struct fieldstat_instance *instance, int metric_id, enum field_op op, long long value) { - struct metric_t * metric = NULL; + struct metric * metric = NULL; struct stat_unit_t *target = NULL; - if(field_id >= instance->metric_cnt) + if(metric_id >= instance->metric_cnt) { return -1; } - metric = get_metric(instance, field_id); + metric = get_metric(instance, metric_id); switch(metric->field_type) { @@ -646,24 +667,24 @@ static int fieldstat_value_operate(struct fieldstat_instance *instance, int fiel } -int fieldstat_value_incrby(struct fieldstat_instance *instance, int field_id, long long increment) +int fieldstat_value_incrby(struct fieldstat_instance *instance, int metric_id, long long increment) { int ret = 0; - ret = fieldstat_value_operate(instance, field_id, FS_OP_ADD, increment); + ret = fieldstat_value_operate(instance, metric_id, FS_OP_ADD, increment); return ret; } -int fieldstat_value_set(struct fieldstat_instance *instance, int field_id, long long retain) +int fieldstat_value_set(struct fieldstat_instance *instance, int metric_id, long long retain) { int ret = 0; - ret = fieldstat_value_operate(instance, field_id, FS_OP_SET, retain); + ret = fieldstat_value_operate(instance, metric_id, FS_OP_SET, retain); return ret; } -int fieldstat_value_decrby(struct fieldstat_instance *instance, int field_id, long long decrment) +int fieldstat_value_decrby(struct fieldstat_instance *instance, int metric_id, long long decrment) { int ret = 0; - ret = fieldstat_value_operate(instance, field_id, FS_OP_SUB, decrment); + ret = fieldstat_value_operate(instance, metric_id, FS_OP_SUB, decrment); return ret; } @@ -710,11 +731,11 @@ error_out: } -static int fieldstat_register_histogram_and_summary(struct fieldstat_instance *instance, enum field_type type, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag, - const char * bins, long long lowest_trackable_value,long long highest_trackable_value,int significant_figures) +static int fieldstat_register_histogram_and_summary(struct fieldstat_instance *instance, enum field_type type, const char *field_name, const struct fieldstat_tag tags[], size_t n_tag, + const char * bins, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) { - struct metric_t *metric = NULL; - struct metric_t **metric_slot = NULL; + struct metric *metric = NULL; + struct metric **metric_slot = NULL; int metric_id = -1; int ret; @@ -739,7 +760,7 @@ static int fieldstat_register_histogram_and_summary(struct fieldstat_instance *i metric_id = atomic_inc(&instance->metric_cnt) - 1; metric_slot = read_metric_slot(instance, metric_id); - metric = metric_new(type,field_name,tag_key,tag_value,n_tag); + metric = metric_new(type, field_name, tags, n_tag); metric->histogram.highest_trackable_value = (int64_t)highest_trackable_value; metric->histogram.lowest_trackable_value = (int64_t)lowest_trackable_value; @@ -767,17 +788,17 @@ static int fieldstat_register_histogram_and_summary(struct fieldstat_instance *i } -int fieldstat_register_histogram(struct fieldstat_instance *instance, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag, - const char * bins, long long lowest_trackable_value,long long highest_trackable_value,int significant_figures) +int fieldstat_register_histogram(struct fieldstat_instance *instance, const char *field_name,const struct fieldstat_tag tags[], size_t n_tag, + const char * bins, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) { - return fieldstat_register_histogram_and_summary(instance, FILED_TYPE_HISTOGRAM, field_name, tag_key, tag_value, n_tag, + return fieldstat_register_histogram_and_summary(instance, FILED_TYPE_HISTOGRAM, field_name, tags, n_tag, bins, lowest_trackable_value, highest_trackable_value, significant_figures); } -int fieldstat_register_summary(struct fieldstat_instance *instance, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag, - const char * bins,long long lowest_trackable_value,long long highest_trackable_value,int significant_figures) +int fieldstat_register_summary(struct fieldstat_instance *instance, const char *field_name, const struct fieldstat_tag tags[], size_t n_tag, + const char * bins, long long lowest_trackable_value, long long highest_trackable_value, int significant_figures) { - return fieldstat_register_histogram_and_summary(instance, FIELD_TYPE_SUMMARY, field_name, tag_key, tag_value, n_tag, + return fieldstat_register_histogram_and_summary(instance, FIELD_TYPE_SUMMARY, field_name, tags, n_tag, bins, lowest_trackable_value, highest_trackable_value, significant_figures); } diff --git a/src/fieldstat_internal.h b/src/fieldstat_internal.h index bce5bbe..8c2753f 100644 --- a/src/fieldstat_internal.h +++ b/src/fieldstat_internal.h @@ -100,7 +100,7 @@ struct histogram_t }; -struct metric_t +struct metric { char *field_name; enum field_type field_type; @@ -170,19 +170,18 @@ struct fieldstat_instance char local_output_format[LEN_FORMAT_MAX]; int local_output_enable; - int background_thread_disable; //default:1 - int output_interval_s; //default:2 + int background_thread_disable; + int output_interval_ms; int running; - struct metric_t **metric_block_list[BLOCK_LIST_SIZE]; + struct metric **metric_block_list[BLOCK_LIST_SIZE]; int metric_cnt; - //struct metric_t **metric; + //struct metric **metric; struct table_metric *table_metrics[TABLE_MAX_NUM]; int *index_table[TABLE_MAX_NUM][TABLE_COLUMN_SIZE]; - int per_table_line_number[TABLE_MAX_NUM]; int table_num; int line_seq; @@ -220,13 +219,13 @@ void prometheus_endpoint_instance_output(struct http_request_s* request); char* __str_dup(const char* str); long long hdr_count_le_value(const struct hdr_histogram* h, long long value); -struct metric_t * get_metric(struct fieldstat_instance *instance, int metric_id); -long long get_metric_unit_val(struct metric_t *metric,enum field_calc_algo calc_type,int is_refer); +struct metric * get_metric(struct fieldstat_instance *instance, int metric_id); +long long get_metric_unit_val(struct metric *metric,enum field_calc_algo calc_type,int is_refer); int is_valid_field_name(const char* name); -struct metric_t ** read_metric_slot(struct fieldstat_instance *instance, int metric_id); -struct metric_t* metric_new(enum field_type type, const char *field_name, const char *tag_key[], const char *tag_value[], size_t n_tag); +struct metric ** read_metric_slot(struct fieldstat_instance *instance, int metric_id); +struct metric * metric_new(enum field_type type, const char *field_name, struct fieldstat_tag tags[], size_t n_tag); int fieldstat_output_file(struct fieldstat_instance *instance,long long interval_ms); struct table_line * read_table_line(struct table_metric *table, int line_id); int send_udp(int sd, unsigned int dest_ip, unsigned short dest_port, const char * data, int len); int line_protocol_output(struct fieldstat_instance *instance); -void get_current_table_line_cnt(struct fieldstat_instance *instance, int n_table, int *table_line_cnt); \ No newline at end of file +void get_current_table_line_cnt(struct fieldstat_instance *instance, int n_table, int *table_line_cnt); diff --git a/src/file_output.cpp b/src/file_output.cpp index dceb370..3c4c921 100644 --- a/src/file_output.cpp +++ b/src/file_output.cpp @@ -45,7 +45,7 @@ static int output_file_format_default_type_gauge(struct fieldstat_instance *inst { int i = 0, j = 0; //display_manifest_t* p = NULL; - metric_t *metric = NULL; + struct metric *metric = NULL; long long value = 0; //double ratio = 0.0; //char* pos=print_buf; @@ -116,7 +116,7 @@ static int output_file_format_default_type_counter(struct fieldstat_instance *in { int i=0,j=0; //display_manifest_t* p=NULL; - metric_t *metric = NULL; + struct metric *metric = NULL; long long value = 0; //double ratio = 0.0; char* append_pos = print_buf; @@ -225,7 +225,7 @@ static int output_file_format_default_table(struct fieldstat_instance *instance, struct table_metric *table = NULL; struct table_line *line = NULL; int metric_id = 0; - struct metric_t *metric = NULL; + struct metric *metric = NULL; long long value = 0; char* append_pos = print_buf; @@ -293,7 +293,7 @@ static int output_file_format_default_table(struct fieldstat_instance *instance, return append_pos - print_buf; } -static int output_file_print_hdr_head(struct metric_t *metric, char *print_buf, size_t size) +static int output_file_print_hdr_head(struct metric *metric, char *print_buf, size_t size) { char * pos = print_buf; char bin_format[STR_LEN_256], str_format[STR_LEN_256]; @@ -339,15 +339,15 @@ static int output_file_print_hdr_head(struct metric_t *metric, char *print_buf, return pos-print_buf; } -static int output_file_print_hdr_unit(struct metric_t *metric, char*print_buf, size_t size) +static int output_file_print_hdr_unit(struct metric *metric, char *print_buf, size_t size) { double * bins = metric->histogram.bins; int bins_num = metric->histogram.bins_num; char* pos=print_buf; long long value=0; int i=0; - struct histogram_t* h=&(metric->histogram); - struct hdr_histogram* h_out=NULL, *h_tmp=NULL; + struct histogram_t *h=&(metric->histogram); + struct hdr_histogram *h_out=NULL, *h_tmp=NULL; char int_format[STR_LEN_256], double_format[STR_LEN_256]; snprintf(int_format, sizeof(int_format), "%%%dlld",HISTOGRAM_WIDTH); snprintf(double_format, sizeof(double_format), "%%%d.2lf",HISTOGRAM_WIDTH); @@ -402,8 +402,8 @@ static int output_file_format_default_type_histogram_and_summary(struct fieldsta int i = 0, j = 0, metric_num = 0; char *pos = print_buf; //display_manifest_t* p=NULL; - struct metric_t *metric = NULL; - struct metric_t *metric_array[current_metric_cnt] = {NULL}; + struct metric *metric = NULL; + struct metric *metric_array[current_metric_cnt] = {NULL}; int metric_is_print[current_metric_cnt] = {0}; if(instance->histogram_cnt == 0 diff --git a/src/line_protocol_output.cpp b/src/line_protocol_output.cpp index f8b3108..56876fe 100644 --- a/src/line_protocol_output.cpp +++ b/src/line_protocol_output.cpp @@ -59,7 +59,7 @@ static int output_line_protocol_tag_set_buf(char *tag_key[], char *tag_value[], static void output_line_protocol_table(struct fieldstat_instance *instance,int tables_line_cnt[], int current_table_cnt) { int i = 0, j = 0, k = 0; - metric_t *metric = NULL; + struct metric *metric = NULL; long long value = 0; //double ratio = 0.0; char field_set_buff[UDP_PAYLOAD_SIZE]; @@ -135,7 +135,7 @@ static void output_line_protocol_table(struct fieldstat_instance *instance,int t int line_protocol_output(struct fieldstat_instance *instance) { - metric_t *metric = NULL; + struct metric *metric = NULL; long long value=0; int i=0; char field_set_buff[UDP_PAYLOAD_SIZE]; diff --git a/src/prometheus_output.cpp b/src/prometheus_output.cpp index 1d4fbfd..151bfba 100644 --- a/src/prometheus_output.cpp +++ b/src/prometheus_output.cpp @@ -120,7 +120,7 @@ static void prometheus_output_uri_list(struct prometheus_endpoint_instance *prom return; } -static int prometheus_output_read_metric_tags(struct metric_t *metric, char *instance_name, char *tags_buff, unsigned int size) +static int prometheus_output_read_metric_tags(struct metric *metric, char *instance_name, char *tags_buff, unsigned int size) { int i = 0;//used_len = 0; char unescape[STR_LEN_256] = {0}; @@ -145,7 +145,7 @@ static int prometheus_output_read_metric_tags(struct metric_t *metric, char *ins } -static int prometheus_output_read_metric_name(struct metric_t *metric, char *instance_app_name, char *name_buff, unsigned int size) +static int prometheus_output_read_metric_name(struct metric *metric, char *instance_app_name, char *name_buff, unsigned int size) { char unescape[256] = {0}; char *append_pos = name_buff; @@ -163,7 +163,7 @@ static int prometheus_output_read_metric_name(struct metric_t *metric, char *ins } -static int prometheus_output_histogram_and_summary(struct metric_t *metric, char *payload, int payload_len, char *instance_app_name, char *metric_name, char *metric_tags) +static int prometheus_output_histogram_and_summary(struct metric *metric, char *payload, int payload_len, char *instance_app_name, char *metric_name, char *metric_tags) { long long value=0; long long sum = 0; @@ -241,7 +241,7 @@ static int prometheus_output_histogram_and_summary(struct metric_t *metric, char return used_len; } -static int is_output_prometheus(struct metric_t *metric) +static int is_output_prometheus(struct metric *metric) { int i = 0, ret = 0; for(i = 0; i < (int)metric->n_tag; i++) @@ -260,7 +260,7 @@ static int is_output_prometheus(struct metric_t *metric) static int prometheus_get_instance_metric_playload(struct fieldstat_instance *instance, char **payload, int *payload_size, int offset) { int i = 0; - struct metric_t *metric = NULL; + struct metric *metric = NULL; long long value = 0; char metric_name[256] = {0}; //match the regex [a-zA-Z_:][a-zA-Z0-9_:]* char instance_name[256] = {0}; @@ -385,7 +385,7 @@ void prometheus_endpoint_instance_output(struct http_request_s* request) { int fs_instance_idx = -1; struct http_string_s uri; - struct prometheus_endpoint_instance *prometheus_endpoint_instance = &g_prometheus_endpoint_instance;; + struct prometheus_endpoint_instance *prometheus_endpoint_instance = &g_prometheus_endpoint_instance; uri = http_request_target(request); fs_instance_idx = prometheus_get_fs_instance_id(prometheus_endpoint_instance, (char *)uri.buf, uri.len); @@ -405,7 +405,7 @@ void *prometheus_endpoint_listen_thread_entry(void *arg) return NULL; } -int fieldstat_global_enable_prometheus_endpoint(unsigned short listen_port, const char *url) +int fieldstat_global_enable_prometheus_endpoint(unsigned short listen_port, const char *url_path) { g_prometheus_endpoint_instance.server_handle = http_server_init(listen_port, prometheus_endpoint_instance_output); if(g_prometheus_endpoint_instance.server_handle == NULL) @@ -413,7 +413,7 @@ int fieldstat_global_enable_prometheus_endpoint(unsigned short listen_port, cons return -1; } - g_prometheus_endpoint_instance.url_path = url == NULL ? strdup(PROMETHEUS_ENDPOINT_DEFAULT_URL):strdup(url); + g_prometheus_endpoint_instance.url_path = url_path == NULL ? strdup(PROMETHEUS_ENDPOINT_DEFAULT_URL):strdup(url_path); g_prometheus_endpoint_instance.port = listen_port; g_prometheus_endpoint_instance.running = 1; g_prometheus_endpoint_instance.fs_instance = (struct fieldstat_instance **)calloc( sizeof(struct fieldstat_instance *), g_prometheus_endpoint_instance.fs_instance_size); @@ -423,7 +423,7 @@ int fieldstat_global_enable_prometheus_endpoint(unsigned short listen_port, cons return 0; } -int fieldstat_set_prometheus_output(struct fieldstat_instance *instance) +int fieldstat_enable_prometheus_output(struct fieldstat_instance *instance) { int fs_instance_id = 0; -- cgit v1.2.3