From 2659b46e16ca5e24dbf6d3f0b77f6dab0c225433 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Mon, 9 Aug 2021 17:15:20 +0800 Subject: [PATCH] [TD-5861]:add uptime and dnodeId --- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 1 + src/dnode/src/dnodeMain.c | 1 + src/plugins/http/src/httpMetricsHandle.c | 15 +++++++++++++++ 4 files changed, 18 insertions(+) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 25d1c90ec5..62f369d987 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -41,6 +41,7 @@ extern char tsArbitrator[]; extern int8_t tsArbOnline; extern int64_t tsArbOnlineTimestamp; extern int32_t tsDnodeId; +extern int64_t tsDnodeStartTime; // common extern int tsRpcTimer; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index f9135605bb..d1b816f122 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -46,6 +46,7 @@ int8_t tsArbOnline = 0; int64_t tsArbOnlineTimestamp = TSDB_ARB_DUMMY_TIME; char tsEmail[TSDB_FQDN_LEN] = {0}; int32_t tsDnodeId = 0; +int64_t tsDnodeStartTime = 0; // common int32_t tsRpcTimer = 300; diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index eac04fe7bb..abbc99ac02 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -195,6 +195,7 @@ int32_t dnodeInitSystem() { dnodeSetRunStatus(TSDB_RUN_STATUS_RUNING); moduleStart(); + tsDnodeStartTime = taosGetTimestampMs(); dnodeReportStep("TDengine", "initialized successfully", 1); dInfo("TDengine is initialized successfully"); diff --git a/src/plugins/http/src/httpMetricsHandle.c b/src/plugins/http/src/httpMetricsHandle.c index 206ddb4291..787d5f2b0c 100644 --- a/src/plugins/http/src/httpMetricsHandle.c +++ b/src/plugins/http/src/httpMetricsHandle.c @@ -30,6 +30,21 @@ bool metricsProcessRequest(HttpContext* pContext) { httpWriteJsonBufHead(jsonBuf); httpJsonToken(jsonBuf, JsonObjStt); + { + int32_t dnodeId = dnodeGetDnodeId(); + char* keyDnodeId = "dnode_id"; + httpJsonPairIntVal(jsonBuf, keyDnodeId, strlen(keyDnodeId), dnodeId); + } + + { + if (tsDnodeStartTime != 0) { + int64_t now = taosGetTimestampMs(); + int64_t upTime = now-tsDnodeStartTime; + char* keyUpTime = "up_time"; + httpJsonPairInt64Val(jsonBuf, keyUpTime, strlen(keyUpTime), upTime); + } + } + { int32_t cpuCores = taosGetCpuCores(); char* keyCpuCores = "cpu_cores"; -- GitLab