Merge pull request #14185 from taosdata/fix/mnode
enh: add stbinfo to minotor
This commit is contained in:
commit
4a30efdf7d
|
@ -73,10 +73,12 @@ void mndStop(SMnode *pMnode);
|
|||
* @param pMnode The mnode object.
|
||||
* @param pCluster
|
||||
* @param pVgroup
|
||||
* @param pStbInfo
|
||||
* @param pGrant
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||
SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo);
|
||||
|
||||
/**
|
||||
* @brief Get mnode loads for status msg.
|
||||
|
|
|
@ -138,6 +138,15 @@ typedef struct {
|
|||
SArray *vgroups; // array of SMonVgroupDesc
|
||||
} SMonVgroupInfo;
|
||||
|
||||
typedef struct {
|
||||
char stb_name[TSDB_TABLE_NAME_LEN];
|
||||
char database_name[TSDB_DB_NAME_LEN];
|
||||
} SMonStbDesc;
|
||||
|
||||
typedef struct {
|
||||
SArray *stbs; // array of SMonStbDesc
|
||||
} SMonStbInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t expire_time;
|
||||
int64_t timeseries_used;
|
||||
|
@ -147,6 +156,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
SMonClusterInfo cluster;
|
||||
SMonVgroupInfo vgroup;
|
||||
SMonStbInfo stb;
|
||||
SMonGrantInfo grant;
|
||||
SMonSysInfo sys;
|
||||
SMonLogs log;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "mmInt.h"
|
||||
|
||||
void mmGetMonitorInfo(SMnodeMgmt *pMgmt, SMonMmInfo *pInfo) {
|
||||
mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->grant);
|
||||
mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant);
|
||||
}
|
||||
|
||||
int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
|
|
|
@ -614,7 +614,7 @@ int64_t mndGenerateUid(char *name, int32_t len) {
|
|||
}
|
||||
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||
SMonGrantInfo *pGrantInfo) {
|
||||
SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo) {
|
||||
if (mndAcquireRpcRef(pMnode) != 0) return -1;
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -623,7 +623,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
pClusterInfo->dnodes = taosArrayInit(sdbGetSize(pSdb, SDB_DNODE), sizeof(SMonDnodeDesc));
|
||||
pClusterInfo->mnodes = taosArrayInit(sdbGetSize(pSdb, SDB_MNODE), sizeof(SMonMnodeDesc));
|
||||
pVgroupInfo->vgroups = taosArrayInit(sdbGetSize(pSdb, SDB_VGROUP), sizeof(SMonVgroupDesc));
|
||||
if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL) {
|
||||
pStbInfo->stbs = taosArrayInit(sdbGetSize(pSdb, SDB_STB), sizeof(SMonStbDesc));
|
||||
if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL ||
|
||||
pStbInfo->stbs == NULL) {
|
||||
mndReleaseRpcRef(pMnode);
|
||||
return -1;
|
||||
}
|
||||
|
@ -714,6 +716,27 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
// stb info
|
||||
pIter = NULL;
|
||||
while (1) {
|
||||
SStbObj *pStb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SMonStbDesc desc = {0};
|
||||
|
||||
SName name1 = {0};
|
||||
tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
tNameGetDbName(&name1, desc.database_name);
|
||||
|
||||
SName name2 = {0};
|
||||
tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
tstrncpy(desc.stb_name, tNameGetTableName(&name2), TSDB_TABLE_NAME_LEN);
|
||||
|
||||
taosArrayPush(pStbInfo->stbs, &desc);
|
||||
sdbRelease(pSdb, pStb);
|
||||
}
|
||||
|
||||
// grant info
|
||||
pGrantInfo->expire_time = (pMnode->grant.expireTimeMS - ms) / 86400000.0f;
|
||||
pGrantInfo->timeseries_total = pMnode->grant.timeseriesAllowed;
|
||||
|
|
|
@ -280,6 +280,27 @@ static void monGenVgroupJson(SMonInfo *pMonitor) {
|
|||
}
|
||||
}
|
||||
|
||||
static void monGenStbJson(SMonInfo *pMonitor) {
|
||||
SMonStbInfo *pInfo = &pMonitor->mmInfo.stb;
|
||||
if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return;
|
||||
|
||||
SJson *pJson = tjsonAddArrayToObject(pMonitor->pJson, "stb_infos");
|
||||
if (pJson == NULL) return;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) {
|
||||
SJson *pStbJson = tjsonCreateObject();
|
||||
if (pStbJson == NULL) continue;
|
||||
if (tjsonAddItemToArray(pJson, pStbJson) != 0) {
|
||||
tjsonDelete(pStbJson);
|
||||
continue;
|
||||
}
|
||||
|
||||
SMonStbDesc *pStbDesc = taosArrayGet(pInfo->stbs, i);
|
||||
tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name);
|
||||
tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void monGenGrantJson(SMonInfo *pMonitor) {
|
||||
SMonGrantInfo *pInfo = &pMonitor->mmInfo.grant;
|
||||
if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return;
|
||||
|
@ -527,6 +548,7 @@ void monSendReport() {
|
|||
monGenBasicJson(pMonitor);
|
||||
monGenClusterJson(pMonitor);
|
||||
monGenVgroupJson(pMonitor);
|
||||
monGenStbJson(pMonitor);
|
||||
monGenGrantJson(pMonitor);
|
||||
monGenDnodeJson(pMonitor);
|
||||
monGenDiskJson(pMonitor);
|
||||
|
|
|
@ -209,6 +209,32 @@ int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSMonStbInfo(SEncoder *encoder, const SMonStbInfo *pInfo) {
|
||||
if (tEncodeI32(encoder, taosArrayGetSize(pInfo->stbs)) < 0) return -1;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) {
|
||||
SMonStbDesc *pDesc = taosArrayGet(pInfo->stbs, i);
|
||||
if (tEncodeCStr(encoder, pDesc->stb_name) < 0) return -1;
|
||||
if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSMonStbInfo(SDecoder *decoder, SMonStbInfo *pInfo) {
|
||||
int32_t arraySize = 0;
|
||||
if (tDecodeI32(decoder, &arraySize) < 0) return -1;
|
||||
|
||||
pInfo->stbs = taosArrayInit(arraySize, sizeof(SMonStbDesc));
|
||||
if (pInfo->stbs == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SMonStbDesc desc = {0};
|
||||
if (tDecodeCStrTo(decoder, desc.stb_name) < 0) return -1;
|
||||
if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1;
|
||||
taosArrayPush(pInfo->stbs, &desc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) {
|
||||
if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1;
|
||||
if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1;
|
||||
|
@ -230,6 +256,7 @@ int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
|
|||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1;
|
||||
if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1;
|
||||
if (tEncodeSMonStbInfo(&encoder, &pInfo->stb) < 0) return -1;
|
||||
if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1;
|
||||
if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
|
||||
if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
|
||||
|
@ -247,6 +274,7 @@ int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
|
|||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1;
|
||||
if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1;
|
||||
if (tDecodeSMonStbInfo(&decoder, &pInfo->stb) < 0) return -1;
|
||||
if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1;
|
||||
if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
|
||||
if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
|
||||
|
@ -261,9 +289,11 @@ void tFreeSMonMmInfo(SMonMmInfo *pInfo) {
|
|||
taosArrayDestroy(pInfo->cluster.mnodes);
|
||||
taosArrayDestroy(pInfo->cluster.dnodes);
|
||||
taosArrayDestroy(pInfo->vgroup.vgroups);
|
||||
taosArrayDestroy(pInfo->stb.stbs);
|
||||
pInfo->cluster.mnodes = NULL;
|
||||
pInfo->cluster.dnodes = NULL;
|
||||
pInfo->vgroup.vgroups = NULL;
|
||||
pInfo->stb.stbs = NULL;
|
||||
pInfo->log.logs = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ sql connect
|
|||
print =============== show dnodes
|
||||
sleep 2000
|
||||
sql create database db vgroups 2;
|
||||
sql use db;
|
||||
sql create table db.stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 binary(16)) comment "abd";
|
||||
sleep 2000
|
||||
|
||||
print =============== create drop qnode 1
|
||||
|
|
Loading…
Reference in New Issue