This commit is contained in:
xiao77 2024-09-03 16:25:40 +08:00
parent d3518fbc89
commit 81615362c3
8 changed files with 74 additions and 78 deletions

View File

@ -99,7 +99,7 @@ int taos_counter_inc(taos_counter_t *self, const char **label_values);
*/ */
int taos_counter_add(taos_counter_t *self, double r_value, const char **label_values); int taos_counter_add(taos_counter_t *self, double r_value, const char **label_values);
int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys,int32_t **vgroup_ids); int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids);
int taos_counter_get_keys_size(taos_counter_t *self); int taos_counter_get_keys_size(taos_counter_t *self);
int taos_counter_delete(taos_counter_t *self, char *key); int taos_counter_delete(taos_counter_t *self, char *key);
#endif // TAOS_COUNTER_H #endif // TAOS_COUNTER_H

View File

@ -23,27 +23,27 @@ extern "C" {
#endif #endif
typedef struct SDnodeMgmt { typedef struct SDnodeMgmt {
SDnodeData *pData; SDnodeData *pData;
SMsgCb msgCb; SMsgCb msgCb;
const char *path; const char *path;
const char *name; const char *name;
TdThread statusThread; TdThread statusThread;
TdThread notifyThread; TdThread notifyThread;
TdThread monitorThread; TdThread monitorThread;
TdThread auditThread; TdThread auditThread;
TdThread crashReportThread; TdThread crashReportThread;
SSingleWorker mgmtWorker; SSingleWorker mgmtWorker;
ProcessCreateNodeFp processCreateNodeFp; ProcessCreateNodeFp processCreateNodeFp;
ProcessAlterNodeTypeFp processAlterNodeTypeFp; ProcessAlterNodeTypeFp processAlterNodeTypeFp;
ProcessDropNodeFp processDropNodeFp; ProcessDropNodeFp processDropNodeFp;
SendMonitorReportFp sendMonitorReportFp; SendMonitorReportFp sendMonitorReportFp;
MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp; MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp;
SendAuditRecordsFp sendAuditRecordsFp; SendAuditRecordsFp sendAuditRecordsFp;
GetVnodeLoadsFp getVnodeLoadsFp; GetVnodeLoadsFp getVnodeLoadsFp;
GetVnodeLoadsFp getVnodeLoadsLiteFp; GetVnodeLoadsFp getVnodeLoadsLiteFp;
GetMnodeLoadsFp getMnodeLoadsFp; GetMnodeLoadsFp getMnodeLoadsFp;
GetQnodeLoadsFp getQnodeLoadsFp; GetQnodeLoadsFp getQnodeLoadsFp;
int32_t statusSeq; int32_t statusSeq;
} SDnodeMgmt; } SDnodeMgmt;
// dmHandle.c // dmHandle.c

View File

@ -14,8 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "vmInt.h"
#include "taos_monitor.h" #include "taos_monitor.h"
#include "vmInt.h"
extern taos_counter_t *tsInsertCounter; extern taos_counter_t *tsInsertCounter;
@ -124,16 +124,16 @@ int vmCleanExpriedSamples(SVnodeMgmt *pMgmt) {
int list_size = taos_counter_get_keys_size(tsInsertCounter); int list_size = taos_counter_get_keys_size(tsInsertCounter);
if (list_size == 0) return 0; if (list_size == 0) return 0;
int32_t *vgroup_ids; int32_t *vgroup_ids;
char **keys; char **keys;
taos_counter_get_vgroup_ids(tsInsertCounter,&keys,&vgroup_ids); taos_counter_get_vgroup_ids(tsInsertCounter, &keys, &vgroup_ids);
int r = 0; int r = 0;
(void)taosThreadRwlockWrlock(&pMgmt->lock); (void)taosThreadRwlockWrlock(&pMgmt->lock);
for (int i = 0; i<list_size; i++) { for (int i = 0; i < list_size; i++) {
int32_t vgroup_id = vgroup_ids[i]; int32_t vgroup_id = vgroup_ids[i];
void *vnode = taosHashGet(pMgmt->hash, &vgroup_id, sizeof(int32_t)); void *vnode = taosHashGet(pMgmt->hash, &vgroup_id, sizeof(int32_t));
if (vnode == NULL) { if (vnode == NULL) {
r = taos_counter_delete(tsInsertCounter, keys[i]); r = taos_counter_delete(tsInsertCounter, keys[i]);
} }
} }
(void)taosThreadRwlockUnlock(&pMgmt->lock); (void)taosThreadRwlockUnlock(&pMgmt->lock);
taosMemoryFree(vgroup_ids); taosMemoryFree(vgroup_ids);

View File

@ -14,9 +14,9 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "audit.h"
#include "dmMgmt.h" #include "dmMgmt.h"
#include "dmNodes.h" #include "dmNodes.h"
#include "audit.h"
static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
pInfo->protocol = 1; pInfo->protocol = 1;
@ -33,8 +33,8 @@ static void dmGetMonitorBasicInfoBasic(SDnode *pDnode, SMonBasicInfo *pInfo) {
} }
static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
//pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f); // pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f);
pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) /1000.0f; pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / 1000.0f;
pInfo->has_mnode = pDnode->wrappers[MNODE].required; pInfo->has_mnode = pDnode->wrappers[MNODE].required;
pInfo->has_qnode = pDnode->wrappers[QNODE].required; pInfo->has_qnode = pDnode->wrappers[QNODE].required;
pInfo->has_snode = pDnode->wrappers[SNODE].required; pInfo->has_snode = pDnode->wrappers[SNODE].required;
@ -141,10 +141,8 @@ void dmMonitorCleanExpiredSamples() {
(void)dmCleanExpriedSamples(pDnode); (void)dmCleanExpriedSamples(pDnode);
} }
//Todo: put this in seperate file in the future // Todo: put this in seperate file in the future
void dmSendAuditRecords() { void dmSendAuditRecords() { auditSendRecordsInBatch(); }
auditSendRecordsInBatch();
}
void dmGetVnodeLoads(SMonVloadInfo *pInfo) { void dmGetVnodeLoads(SMonVloadInfo *pInfo) {
SDnode *pDnode = dmInstance(); SDnode *pDnode = dmInstance();

View File

@ -147,22 +147,22 @@ typedef struct {
} SDnodeData; } SDnodeData;
typedef struct { typedef struct {
const char *path; const char *path;
const char *name; const char *name;
STfs *pTfs; STfs *pTfs;
SDnodeData *pData; SDnodeData *pData;
SMsgCb msgCb; SMsgCb msgCb;
ProcessCreateNodeFp processCreateNodeFp; ProcessCreateNodeFp processCreateNodeFp;
ProcessAlterNodeTypeFp processAlterNodeTypeFp; ProcessAlterNodeTypeFp processAlterNodeTypeFp;
ProcessDropNodeFp processDropNodeFp; ProcessDropNodeFp processDropNodeFp;
SendMonitorReportFp sendMonitorReportFp; SendMonitorReportFp sendMonitorReportFp;
MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp; MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp;
SendAuditRecordsFp sendAuditRecordFp; SendAuditRecordsFp sendAuditRecordFp;
GetVnodeLoadsFp getVnodeLoadsFp; GetVnodeLoadsFp getVnodeLoadsFp;
GetVnodeLoadsFp getVnodeLoadsLiteFp; GetVnodeLoadsFp getVnodeLoadsLiteFp;
GetMnodeLoadsFp getMnodeLoadsFp; GetMnodeLoadsFp getMnodeLoadsFp;
GetQnodeLoadsFp getQnodeLoadsFp; GetQnodeLoadsFp getQnodeLoadsFp;
StopDnodeFp stopDnodeFp; StopDnodeFp stopDnodeFp;
} SMgmtInputOpt; } SMgmtInputOpt;
typedef struct { typedef struct {

View File

@ -57,8 +57,8 @@ int taos_metric_formatter_load_l_value(taos_metric_formatter_t *metric_formatter
/** /**
* @brief API PRIVATE Loads the formatter with a metric sample * @brief API PRIVATE Loads the formatter with a metric sample
*/ */
int taos_metric_formatter_load_sample(taos_metric_formatter_t *metric_formatter, taos_metric_sample_t *sample, int taos_metric_formatter_load_sample(taos_metric_formatter_t *metric_formatter, taos_metric_sample_t *sample, char *ts,
char *ts, char *format); char *format);
/** /**
* @brief API PRIVATE Loads a metric in the string exposition format * @brief API PRIVATE Loads a metric in the string exposition format

View File

@ -20,14 +20,14 @@
#include "taos_alloc.h" #include "taos_alloc.h"
// Private // Private
#include "taos_test.h"
#include "taos_errors.h" #include "taos_errors.h"
#include "taos_log.h" #include "taos_log.h"
#include "taos_metric_formatter_i.h"
#include "taos_metric_i.h" #include "taos_metric_i.h"
#include "taos_metric_sample_i.h" #include "taos_metric_sample_i.h"
#include "taos_metric_sample_t.h" #include "taos_metric_sample_t.h"
#include "taos_metric_t.h" #include "taos_metric_t.h"
#include "taos_metric_formatter_i.h" #include "taos_test.h"
taos_counter_t *taos_counter_new(const char *name, const char *help, size_t label_key_count, const char **label_keys) { taos_counter_t *taos_counter_new(const char *name, const char *help, size_t label_key_count, const char **label_keys) {
return (taos_counter_t *)taos_metric_new(TAOS_COUNTER, name, help, label_key_count, label_keys); return (taos_counter_t *)taos_metric_new(TAOS_COUNTER, name, help, label_key_count, label_keys);
@ -66,11 +66,9 @@ int taos_counter_add(taos_counter_t *self, double r_value, const char **label_va
return taos_metric_sample_add(sample, r_value); return taos_metric_sample_add(sample, r_value);
} }
int taos_counter_get_keys_size(taos_counter_t *self) { int taos_counter_get_keys_size(taos_counter_t *self) { return self->samples->keys->size; }
return self->samples->keys->size;
}
int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys,int32_t **vgroup_ids) { int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys, int32_t **vgroup_ids) {
TAOS_TEST_PARA(self != NULL); TAOS_TEST_PARA(self != NULL);
if (self == NULL) return 1; if (self == NULL) return 1;
if (self->type != TAOS_COUNTER) { if (self->type != TAOS_COUNTER) {
@ -79,12 +77,12 @@ int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys,int32_t **vgr
} }
if (self->samples == NULL) return 1; if (self->samples == NULL) return 1;
taos_linked_list_t *key_list = self->samples->keys; taos_linked_list_t *key_list = self->samples->keys;
int r = 0; int r = 0;
*vgroup_ids = (int32_t *)taos_malloc(key_list->size*sizeof(int32_t)); *vgroup_ids = (int32_t *)taos_malloc(key_list->size * sizeof(int32_t));
*keys = (char **)taos_malloc(key_list->size*sizeof(char *)); *keys = (char **)taos_malloc(key_list->size * sizeof(char *));
int index = 0; int index = 0;
for (taos_linked_list_node_t *current_key = key_list->head; current_key != NULL;current_key = current_key->next) { for (taos_linked_list_node_t *current_key = key_list->head; current_key != NULL; current_key = current_key->next) {
char *key = (char *)current_key->item; char *key = (char *)current_key->item;
int32_t vgroup_id = taos_metric_formatter_get_vgroup_id(key); int32_t vgroup_id = taos_metric_formatter_get_vgroup_id(key);
(*vgroup_ids)[index] = vgroup_id; (*vgroup_ids)[index] = vgroup_id;
(*keys)[index] = key; (*keys)[index] = key;
@ -100,5 +98,5 @@ int taos_counter_delete(taos_counter_t *self, char *key) {
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE); TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
return 1; return 1;
} }
return taos_map_delete(self->samples, key); return taos_map_delete(self->samples, key);
} }

View File

@ -157,19 +157,19 @@ int taos_metric_formatter_load_l_value(taos_metric_formatter_t *self, const char
return 0; return 0;
} }
int32_t taos_metric_formatter_get_vgroup_id(char *key) { int32_t taos_metric_formatter_get_vgroup_id(char *key) {
char *start,*end; char *start, *end;
char vgroupid[10]; char vgroupid[10];
start = strstr(key, "vgroup_id=\""); start = strstr(key, "vgroup_id=\"");
if (start) { if (start) {
start += strlen("vgroup_id=\""); start += strlen("vgroup_id=\"");
end = strchr(start, '\"'); end = strchr(start, '\"');
if (end) { if (end) {
strncpy(vgroupid, start, end - start); strncpy(vgroupid, start, end - start);
vgroupid[end - start] = '\0'; vgroupid[end - start] = '\0';
}
return strtol(vgroupid, NULL, 10);
} }
return 0; return strtol(vgroupid, NULL, 10);
}
return 0;
} }
/* /*
int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric_sample_t *sample, int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric_sample_t *sample,