summaryrefslogtreecommitdiff
path: root/src/fieldstat.cpp
diff options
context:
space:
mode:
authorfumingwei <[email protected]>2023-05-29 14:04:57 +0800
committerfumingwei <[email protected]>2023-06-02 10:41:12 +0800
commit2b6a1bfd1a6c41fb71b59dd50f62d2c3f4688fa8 (patch)
treea4bc90b8a752dee1f42bfda1b313cb824d1ed0ff /src/fieldstat.cpp
parentd5389fb9f1cf48f413eb6cd7baad27a57efe2274 (diff)
bugfix:新增historgam和summary line protocol输出
Diffstat (limited to 'src/fieldstat.cpp')
-rw-r--r--src/fieldstat.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/fieldstat.cpp b/src/fieldstat.cpp
index 4bdaa39..4be0ce2 100644
--- a/src/fieldstat.cpp
+++ b/src/fieldstat.cpp
@@ -170,6 +170,7 @@ struct metric * metric_new(enum field_type type, const char *field_name, const s
void metric_free(struct metric *metric)
{
int i = 0;
+ struct histogram_t *h = NULL;
free(metric->field_name);
metric->field_name = NULL;
@@ -188,6 +189,31 @@ void metric_free(struct metric *metric)
{
metric->table = NULL;
}
+ if(metric->field_type == FIELD_TYPE_SUMMARY ||
+ metric->field_type == FILED_TYPE_HISTOGRAM)
+ {
+ h = &metric->histogram;
+ if(h->changing != NULL)
+ {
+ hdr_close(h->changing);
+ h->changing = NULL;
+ }
+ if(h->accumulated != NULL)
+ {
+ hdr_close(h->accumulated);
+ h->accumulated = NULL;
+ }
+ if(h->previous_changed != NULL)
+ {
+ hdr_close(h->previous_changed);
+ h->previous_changed = NULL;
+ }
+ if(h->bins != NULL)
+ {
+ free(h->bins);
+ h->bins = NULL;
+ }
+ }
free(metric);
@@ -436,7 +462,8 @@ long long get_metric_unit_val(struct metric *metric,enum field_calc_algo calc_ty
target = &(metric->gauge);
break;
default:
- break;
+ assert(0);
+ return 0;
}
value = threadsafe_counter_read(&(target->changing));
@@ -715,6 +742,10 @@ void table_metric_free(struct table_metric *table)
{
return -1;
}
+ if(column_type[i] != FIELD_TYPE_GAUGE && column_type[i] != FIELD_TYPE_COUNTER)
+ {
+ return -1;
+ }
}
if(n_column <= 0 || n_column > TABLE_COLUMN_SIZE)