add remove metric
This commit is contained in:
parent
3233f2dee0
commit
a164e36b6d
|
@ -76,6 +76,8 @@ int taos_collector_destroy_generic(void *gen);
|
|||
*/
|
||||
int taos_collector_add_metric(taos_collector_t *self, taos_metric_t *metric);
|
||||
|
||||
int taos_collector_remove_metric(taos_collector_t *self, const char* key);
|
||||
|
||||
taos_metric_t* taos_collector_get_metric(taos_collector_t *self, char *metric_name);
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,6 +86,8 @@ taos_metric_t *taos_collector_registry_must_register_metric(taos_metric_t *metri
|
|||
*/
|
||||
int taos_collector_registry_register_metric(taos_metric_t *metric);
|
||||
|
||||
int taos_collector_registry_deregister_metric(const char *key);
|
||||
|
||||
taos_metric_t *taos_collector_registry_get_metric(char* metric_name);
|
||||
|
||||
/**
|
||||
|
|
|
@ -120,17 +120,6 @@ void monInitMonitorFW(){
|
|||
taosHashPut(tsMonitor.metrics, metric[i], strlen(metric[i]), &gauge, sizeof(taos_gauge_t *));
|
||||
}
|
||||
|
||||
int32_t vgroup_label_count = 3;
|
||||
const char *vgroup_sample_labels[] = {"cluster_id", "vgroup_id", "database_name"};
|
||||
char *vgroup_metrics[] = {TABLES_NUM, STATUS};
|
||||
for(int32_t i = 0; i < 2; i++){
|
||||
gauge= taos_gauge_new(vgroup_metrics[i], "", vgroup_label_count, vgroup_sample_labels);
|
||||
if(taos_collector_registry_register_metric(gauge) == 1){
|
||||
taos_counter_destroy(gauge);
|
||||
}
|
||||
taosHashPut(tsMonitor.metrics, vgroup_metrics[i], strlen(vgroup_metrics[i]), &gauge, sizeof(taos_gauge_t *));
|
||||
}
|
||||
|
||||
int32_t dnodes_label_count = 3;
|
||||
const char *dnodes_sample_labels[] = {"cluster_id", "dnode_id", "dnode_ep"};
|
||||
char *dnodes_gauges[] = {UPTIME, CPU_ENGINE, CPU_SYSTEM, CPU_CORE, MEM_ENGINE, MEM_SYSTEM,
|
||||
|
@ -316,6 +305,27 @@ void monGenVgroupInfoTable(SMonInfo *pMonitor){
|
|||
SMonVgroupInfo *pInfo = &pMonitor->mmInfo.vgroup;
|
||||
if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return;
|
||||
|
||||
int32_t vgroup_label_count = 3;
|
||||
const char *vgroup_sample_labels[] = {"cluster_id", "vgroup_id", "database_name"};
|
||||
|
||||
if(taos_collector_registry_deregister_metric(TABLES_NUM) != 0){
|
||||
uError("failed to delete metric "TABLES_NUM);
|
||||
}
|
||||
|
||||
taos_gauge_t *tableNumGauge = taos_gauge_new(TABLES_NUM, "", vgroup_label_count, vgroup_sample_labels);
|
||||
if(taos_collector_registry_register_metric(tableNumGauge) == 1){
|
||||
taos_counter_destroy(tableNumGauge);
|
||||
}
|
||||
|
||||
if(taos_collector_registry_deregister_metric(STATUS) != 0){
|
||||
uError("failed to delete metric "STATUS);
|
||||
}
|
||||
|
||||
taos_gauge_t *statusGauge = taos_gauge_new(STATUS, "", vgroup_label_count, vgroup_sample_labels);
|
||||
if(taos_collector_registry_register_metric(statusGauge) == 1){
|
||||
taos_counter_destroy(statusGauge);
|
||||
}
|
||||
|
||||
char cluster_id[TSDB_CLUSTER_ID_LEN] = {0};
|
||||
snprintf(cluster_id, TSDB_CLUSTER_ID_LEN, "%"PRId64, pMonitor->dmInfo.basic.cluster_id);
|
||||
|
||||
|
@ -329,15 +339,13 @@ void monGenVgroupInfoTable(SMonInfo *pMonitor){
|
|||
|
||||
taos_gauge_t **metric = NULL;
|
||||
|
||||
metric = taosHashGet(tsMonitor.metrics, TABLES_NUM, strlen(TABLES_NUM));
|
||||
taos_gauge_set(*metric, pVgroupDesc->tables_num, sample_labels);
|
||||
taos_gauge_set(tableNumGauge, pVgroupDesc->tables_num, sample_labels);
|
||||
|
||||
metric = taosHashGet(tsMonitor.metrics, STATUS, strlen(STATUS));
|
||||
int32_t status = 0;
|
||||
if(strcmp(pVgroupDesc->status, "ready") == 0){
|
||||
status = 1;
|
||||
}
|
||||
taos_gauge_set(*metric, status, sample_labels);
|
||||
taos_gauge_set(statusGauge, status, sample_labels);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
#ifndef TAOS_LOG_H
|
||||
#define TAOS_LOG_H
|
||||
|
||||
//#define TAOS_LOG_ENABLE
|
||||
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
#define TAOS_LOG(msg) printf("%s %s %s %s %d %s\n", __DATE__, __TIME__, __FILE__, __FUNCTION__, __LINE__, msg);
|
||||
#define TAOS_LOG(msg) printf("monitor_log %s %s %s %s %d %s\n", __DATE__, __TIME__, __FILE__, __FUNCTION__, __LINE__, msg);
|
||||
#else
|
||||
#define TAOS_LOG(msg)
|
||||
#endif // TAOS_LOG_ENABLE
|
||||
|
|
|
@ -24,6 +24,8 @@ int taos_map_set_free_value_fn(taos_map_t *self, taos_map_node_free_value_fn fre
|
|||
|
||||
void *taos_map_get(taos_map_t *self, const char *key);
|
||||
|
||||
void *taos_map_get_withoutlock(taos_map_t *self, const char *key);
|
||||
|
||||
int taos_map_set(taos_map_t *self, const char *key, void *value);
|
||||
|
||||
int taos_map_delete(taos_map_t *self, const char *key);
|
||||
|
|
|
@ -108,6 +108,12 @@ int taos_collector_add_metric(taos_collector_t *self, taos_metric_t *metric) {
|
|||
return taos_map_set(self->metrics, metric->name, metric);
|
||||
}
|
||||
|
||||
int taos_collector_remove_metric(taos_collector_t *self, const char* key){
|
||||
TAOS_ASSERT(self != NULL);
|
||||
if (self == NULL) return 1;
|
||||
return taos_map_delete(self->metrics, key);
|
||||
}
|
||||
|
||||
taos_metric_t* taos_collector_get_metric(taos_collector_t *self, char *metric_name){
|
||||
TAOS_ASSERT(self != NULL);
|
||||
if (self == NULL) return NULL;
|
||||
|
|
|
@ -123,6 +123,19 @@ int taos_collector_registry_register_metric(taos_metric_t *metric) {
|
|||
return taos_collector_add_metric(default_collector, metric);
|
||||
}
|
||||
|
||||
int taos_collector_registry_deregister_metric(const char *key) {
|
||||
TAOS_ASSERT(metric != NULL);
|
||||
|
||||
taos_collector_t *default_collector =
|
||||
(taos_collector_t *)taos_map_get(TAOS_COLLECTOR_REGISTRY_DEFAULT->collectors, "default");
|
||||
|
||||
if (default_collector == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return taos_collector_remove_metric(default_collector, key);
|
||||
}
|
||||
|
||||
taos_metric_t *taos_collector_registry_get_metric(char* metric_name){
|
||||
TAOS_ASSERT(metric != NULL);
|
||||
|
||||
|
@ -232,7 +245,11 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self,
|
|||
SJson* array = tjsonCreateArray();
|
||||
tjsonAddItemToObject(item, "tables", array);
|
||||
|
||||
taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array);
|
||||
if(taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array) != 0){
|
||||
TAOS_LOG("failed to load metrics");
|
||||
tjsonDelete(pJson);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(tjsonGetArraySize(array) == 0){
|
||||
tjsonDelete(pJson);
|
||||
|
|
|
@ -147,9 +147,26 @@ int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
|
|||
if (self == NULL) return 1;
|
||||
taos_linked_list_node_t *node;
|
||||
taos_linked_list_node_t *prev_node = NULL;
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
int32_t count = 0;
|
||||
char tmp[200] = {0};
|
||||
|
||||
count = 0;
|
||||
for (node = self->head; node != NULL; node = node->next) {
|
||||
count++;
|
||||
}
|
||||
sprintf(tmp, "list count:%d", count);
|
||||
TAOS_LOG(tmp);
|
||||
#endif
|
||||
|
||||
// Locate the node
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
count = 0;
|
||||
#endif
|
||||
for (node = self->head; node != NULL; node = node->next) {
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
count++;
|
||||
#endif
|
||||
if (self->compare_fn) {
|
||||
if ((*self->compare_fn)(node->item, item) == TAOS_EQUAL) {
|
||||
break;
|
||||
|
@ -162,6 +179,11 @@ int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
|
|||
prev_node = node;
|
||||
}
|
||||
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
sprintf(tmp, "remove item:%d", count);
|
||||
TAOS_LOG(tmp);
|
||||
#endif
|
||||
|
||||
if (node == NULL) return 0;
|
||||
|
||||
if (prev_node) {
|
||||
|
@ -185,6 +207,17 @@ int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
|
|||
taos_free(node);
|
||||
node = NULL;
|
||||
self->size--;
|
||||
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
count = 0;
|
||||
for (node = self->head; node != NULL; node = node->next) {
|
||||
count++;
|
||||
}
|
||||
|
||||
sprintf(tmp, "list count:%d", count);
|
||||
TAOS_LOG(tmp);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -215,6 +215,14 @@ void *taos_map_get(taos_map_t *self, const char *key) {
|
|||
return payload;
|
||||
}
|
||||
|
||||
void *taos_map_get_withoutlock(taos_map_t *self, const char *key) {
|
||||
TAOS_ASSERT(self != NULL);
|
||||
int r = 0;
|
||||
void *payload =
|
||||
taos_map_get_internal(key, &self->size, &self->max_size, self->keys, self->addrs, self->free_value_fn);
|
||||
return payload;
|
||||
}
|
||||
|
||||
static int taos_map_set_internal(const char *key, void *value, size_t *size, size_t *max_size, taos_linked_list_t *keys,
|
||||
taos_linked_list_t **addrs, taos_map_node_free_value_fn free_value_fn,
|
||||
bool destroy_current_value) {
|
||||
|
@ -368,10 +376,10 @@ static int taos_map_delete_internal(const char *key, size_t *size, size_t *max_s
|
|||
taos_map_node_t *current_map_node = (taos_map_node_t *)current_node->item;
|
||||
taos_linked_list_compare_t result = taos_linked_list_compare(list, current_map_node, temp_map_node);
|
||||
if (result == TAOS_EQUAL) {
|
||||
r = taos_linked_list_remove(list, current_node);
|
||||
r = taos_linked_list_remove(keys, (char*)current_map_node->key);
|
||||
if (r) return r;
|
||||
|
||||
r = taos_linked_list_remove(keys, (char *)current_map_node->key);
|
||||
r = taos_linked_list_remove(list, current_node->item);
|
||||
if (r) return r;
|
||||
|
||||
(*size)--;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "taos_assert.h"
|
||||
#include "tdef.h"
|
||||
#include "taos_collector_t.h"
|
||||
#include "taos_log.h"
|
||||
|
||||
int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_metric_sample_t *sample,
|
||||
char *ts, char *format, char *metricName, int32_t metric_type,
|
||||
|
@ -207,18 +208,50 @@ int taos_metric_formatter_load_metrics_new(taos_metric_formatter_t *self, taos_m
|
|||
|
||||
//if(strcmp(collector->name, "custom") != 0 ){
|
||||
|
||||
r = pthread_rwlock_wrlock(metrics->rwlock);
|
||||
if (r) {
|
||||
TAOS_LOG("failed to lock");
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
int32_t count = 0;
|
||||
#endif
|
||||
for (taos_linked_list_node_t *current_node = metrics->keys->head; current_node != NULL;
|
||||
current_node = current_node->next) {
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
count++;
|
||||
#endif
|
||||
const char *metric_name = (const char *)current_node->item;
|
||||
taos_metric_t *metric = (taos_metric_t *)taos_map_get(metrics, metric_name);
|
||||
if (metric == NULL) return 1;
|
||||
taos_metric_t *metric = (taos_metric_t *)taos_map_get_withoutlock(metrics, metric_name);
|
||||
if (metric == NULL) {
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
char tmp[200] = {0};
|
||||
sprintf(tmp, "fail to get metric(%d):%s", count, metric_name);
|
||||
TAOS_LOG(tmp);
|
||||
#endif
|
||||
continue;;
|
||||
}
|
||||
r = taos_metric_formatter_load_metric_new(self, metric, ts, format, tableArray);
|
||||
if (r) return r;
|
||||
if (r) {
|
||||
TAOS_LOG("failed to load metric");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TAOS_LOG_ENABLE
|
||||
char tmp[20] = {0};
|
||||
sprintf(tmp, "list count:%d", count);
|
||||
TAOS_LOG(tmp);
|
||||
#endif
|
||||
r = pthread_rwlock_unlock(metrics->rwlock);
|
||||
if (r) {
|
||||
TAOS_LOG("failed to unlock");
|
||||
return r;
|
||||
}
|
||||
|
||||
//}
|
||||
//else{
|
||||
|
||||
/*
|
||||
for (taos_linked_list_node_t *current_node = metrics->keys->head; current_node != NULL;
|
||||
current_node = current_node->next) {
|
||||
const char *metric_name = (const char *)current_node->item;
|
||||
|
@ -227,7 +260,7 @@ int taos_metric_formatter_load_metrics_new(taos_metric_formatter_t *self, taos_m
|
|||
r = taos_metric_formatter_load_metric(self, metric, ts, format);
|
||||
if (r) return r;
|
||||
}
|
||||
|
||||
*/
|
||||
//}
|
||||
}
|
||||
return r;
|
||||
|
|
Loading…
Reference in New Issue