fix/TD-31520-use-global-counter
This commit is contained in:
parent
17c941fc32
commit
bdabe66aab
|
@ -30,6 +30,8 @@ extern "C" {
|
|||
#define MON_VER_LEN 12
|
||||
#define MON_LOG_LEN 1024
|
||||
|
||||
#define VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS "inserted_rows"
|
||||
|
||||
typedef struct {
|
||||
int64_t ts;
|
||||
ELogLevel level;
|
||||
|
|
|
@ -101,20 +101,6 @@ typedef struct SQueryNode SQueryNode;
|
|||
#define VND_INFO_FNAME "vnode.json"
|
||||
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
|
||||
|
||||
#define VNODE_METRIC_SQL_COUNT "taosd_sql_req:count"
|
||||
|
||||
#define VNODE_METRIC_TAG_NAME_SQL_TYPE "sql_type"
|
||||
#define VNODE_METRIC_TAG_NAME_CLUSTER_ID "cluster_id"
|
||||
#define VNODE_METRIC_TAG_NAME_DNODE_ID "dnode_id"
|
||||
#define VNODE_METRIC_TAG_NAME_DNODE_EP "dnode_ep"
|
||||
#define VNODE_METRIC_TAG_NAME_VGROUP_ID "vgroup_id"
|
||||
#define VNODE_METRIC_TAG_NAME_USERNAME "username"
|
||||
#define VNODE_METRIC_TAG_NAME_RESULT "result"
|
||||
|
||||
#define VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS "inserted_rows"
|
||||
// #define VNODE_METRIC_TAG_VALUE_INSERT "insert"
|
||||
// #define VNODE_METRIC_TAG_VALUE_DELETE "delete"
|
||||
|
||||
// vnd.h
|
||||
typedef int32_t (*_query_reseek_func_t)(void* pQHandle);
|
||||
struct SQueryNode {
|
||||
|
@ -452,7 +438,6 @@ typedef struct SVMonitorObj {
|
|||
char strClusterId[TSDB_CLUSTER_ID_LEN];
|
||||
char strDnodeId[TSDB_NODE_ID_LEN];
|
||||
char strVgId[TSDB_VGROUP_ID_LEN];
|
||||
taos_counter_t* insertCounter;
|
||||
} SVMonitorObj;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -494,24 +494,6 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
snprintf(pVnode->monitor.strDnodeId, TSDB_NODE_ID_LEN, "%" PRId32, pVnode->config.syncCfg.nodeInfo[0].nodeId);
|
||||
snprintf(pVnode->monitor.strVgId, TSDB_VGROUP_ID_LEN, "%" PRId32, pVnode->config.vgId);
|
||||
|
||||
if (tsEnableMonitor && pVnode->monitor.insertCounter == NULL) {
|
||||
taos_counter_t *counter = NULL;
|
||||
int32_t label_count = 7;
|
||||
const char *sample_labels[] = {VNODE_METRIC_TAG_NAME_SQL_TYPE, VNODE_METRIC_TAG_NAME_CLUSTER_ID,
|
||||
VNODE_METRIC_TAG_NAME_DNODE_ID, VNODE_METRIC_TAG_NAME_DNODE_EP,
|
||||
VNODE_METRIC_TAG_NAME_VGROUP_ID, VNODE_METRIC_TAG_NAME_USERNAME,
|
||||
VNODE_METRIC_TAG_NAME_RESULT};
|
||||
counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", label_count, sample_labels);
|
||||
vInfo("vgId:%d, new metric:%p", TD_VID(pVnode), counter);
|
||||
if (taos_collector_registry_register_metric(counter) == 1) {
|
||||
(void)taos_counter_destroy(counter);
|
||||
counter = taos_collector_registry_get_metric(VNODE_METRIC_SQL_COUNT);
|
||||
vInfo("vgId:%d, get metric from registry:%p", TD_VID(pVnode), counter);
|
||||
}
|
||||
pVnode->monitor.insertCounter = counter;
|
||||
vInfo("vgId:%d, succeed to set metric:%p", TD_VID(pVnode), counter);
|
||||
}
|
||||
|
||||
return pVnode;
|
||||
|
||||
_err:
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "audit.h"
|
||||
#include "cos.h"
|
||||
#include "monitor.h"
|
||||
#include "tencode.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsg.h"
|
||||
|
@ -23,6 +24,8 @@
|
|||
#include "vnode.h"
|
||||
#include "vnodeInt.h"
|
||||
|
||||
extern taos_counter_t *tsInsertCounter;
|
||||
|
||||
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
@ -1901,7 +1904,8 @@ _exit:
|
|||
(void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
|
||||
(void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
|
||||
|
||||
if (tsEnableMonitor && pSubmitRsp->affectedRows > 0 && strlen(pOriginalMsg->info.conn.user) > 0) {
|
||||
if (tsEnableMonitor && pSubmitRsp->affectedRows > 0 && strlen(pOriginalMsg->info.conn.user) > 0 &&
|
||||
tsInsertCounter != NULL) {
|
||||
const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS,
|
||||
pVnode->monitor.strClusterId,
|
||||
pVnode->monitor.strDnodeId,
|
||||
|
@ -1909,7 +1913,7 @@ _exit:
|
|||
pVnode->monitor.strVgId,
|
||||
pOriginalMsg->info.conn.user,
|
||||
"Success"};
|
||||
(void)taos_counter_add(pVnode->monitor.insertCounter, pSubmitRsp->affectedRows, sample_labels);
|
||||
(void)taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels);
|
||||
}
|
||||
|
||||
if (code == 0) {
|
||||
|
|
|
@ -21,11 +21,25 @@
|
|||
#include "thttp.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#define VNODE_METRIC_SQL_COUNT "taosd_sql_req:count"
|
||||
|
||||
#define VNODE_METRIC_TAG_NAME_SQL_TYPE "sql_type"
|
||||
#define VNODE_METRIC_TAG_NAME_CLUSTER_ID "cluster_id"
|
||||
#define VNODE_METRIC_TAG_NAME_DNODE_ID "dnode_id"
|
||||
#define VNODE_METRIC_TAG_NAME_DNODE_EP "dnode_ep"
|
||||
#define VNODE_METRIC_TAG_NAME_VGROUP_ID "vgroup_id"
|
||||
#define VNODE_METRIC_TAG_NAME_USERNAME "username"
|
||||
#define VNODE_METRIC_TAG_NAME_RESULT "result"
|
||||
|
||||
// #define VNODE_METRIC_TAG_VALUE_INSERT "insert"
|
||||
// #define VNODE_METRIC_TAG_VALUE_DELETE "delete"
|
||||
|
||||
SMonitor tsMonitor = {0};
|
||||
char *tsMonUri = "/report";
|
||||
char *tsMonFwUri = "/general-metric";
|
||||
char *tsMonSlowLogUri = "/slow-sql-detail-batch";
|
||||
char *tsMonFwBasicUri = "/taosd-cluster-basic";
|
||||
taos_counter_t *tsInsertCounter = NULL;
|
||||
|
||||
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||
(void)taosThreadMutexLock(&tsMonitor.lock);
|
||||
|
@ -114,6 +128,26 @@ int32_t monInit(const SMonCfg *pCfg) {
|
|||
|
||||
monInitMonitorFW();
|
||||
|
||||
if (tsEnableMonitor && tsInsertCounter == NULL) {
|
||||
taos_counter_t *counter = NULL;
|
||||
int32_t label_count = 7;
|
||||
const char *sample_labels[] = {VNODE_METRIC_TAG_NAME_SQL_TYPE, VNODE_METRIC_TAG_NAME_CLUSTER_ID,
|
||||
VNODE_METRIC_TAG_NAME_DNODE_ID, VNODE_METRIC_TAG_NAME_DNODE_EP,
|
||||
VNODE_METRIC_TAG_NAME_VGROUP_ID, VNODE_METRIC_TAG_NAME_USERNAME,
|
||||
VNODE_METRIC_TAG_NAME_RESULT};
|
||||
counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", label_count, sample_labels);
|
||||
uDebug("new metric:%p", counter);
|
||||
if (taos_collector_registry_register_metric(counter) == 1) {
|
||||
(void)taos_counter_destroy(counter);
|
||||
uError("failed to register metric:%p", counter);
|
||||
} else {
|
||||
tsInsertCounter = counter;
|
||||
uInfo("succeed to set inserted row metric:%p", tsInsertCounter);
|
||||
}
|
||||
} else {
|
||||
uError("failed to set insert counter, already set");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue