diff --git a/src/dnode/src/dnodeTelemetry.c b/src/dnode/src/dnodeTelemetry.c index 22287f71fd10350cc5dcf80ccc32bed3c4f09822..892fd1d903b501733cd98bd54407ae852e74c2a6 100644 --- a/src/dnode/src/dnodeTelemetry.c +++ b/src/dnode/src/dnodeTelemetry.c @@ -22,8 +22,16 @@ #include "tsocket.h" #include "tbuffer.h" #include "mnode.h" +#include "mnodeDef.h" +#include "mnodeDb.h" +#include "mnodeDnode.h" #include "mnodeCluster.h" +#include "mnodeDnode.h" +#include "mnodeVgroup.h" +#include "mnodeMnode.h" +#include "mnodeTable.h" #include "mnodeSdb.h" +#include "mnodeAcct.h" #include "dnode.h" #include "dnodeInt.h" #include "dnodeTelemetry.h" @@ -170,18 +178,23 @@ static void addVersionInfo(SBufferWriter* bw) { addStringField(bw, "version", version); addStringField(bw, "buildInfo", buildinfo); addStringField(bw, "gitInfo", gitinfo); - //addStringField(&bw, "installAt", "2020-08-01T00:00:00Z"); } static void addRuntimeInfo(SBufferWriter* bw) { - // addIntField(&bw, "numOfDnode", 1); - // addIntField(&bw, "numOfVnode", 1); - // addIntField(&bw, "numOfStable", 1); - // addIntField(&bw, "numOfTable", 1); - // addIntField(&bw, "numOfRows", 1); - // addStringField(&bw, "startAt", "2020-08-01T00:00:00Z"); - // addStringField(&bw, "memoryUsage", "10240 kB"); - // addStringField(&bw, "diskUsage", "10240 MB"); + addIntField(bw, "numOfDnode", mnodeGetDnodesNum()); + addIntField(bw, "numOfMnode", mnodeGetMnodesNum()); + addIntField(bw, "numOfVgroup", mnodeGetVgroupNum()); + addIntField(bw, "numOfDatabase", mnodeGetDbNum()); + addIntField(bw, "numOfSuperTable", mnodeGetSuperTableNum()); + addIntField(bw, "numOfChildTable", mnodeGetChildTableNum()); + + SAcctInfo info; + mnodeGetStatOfAllAcct(&info); + addIntField(bw, "numOfColumn", info.numOfTimeSeries); + addIntField(bw, "numOfPoint", info.totalPoints); + addIntField(bw, "totalStorage", info.totalStorage); + addIntField(bw, "compStorage", info.compStorage); + // addStringField(bw, "installTime", "2020-08-01T00:00:00Z"); } static void sendTelemetryReport() { @@ -230,18 +243,13 @@ static void sendTelemetryReport() { static void* telemetryThread(void* param) { struct timespec end = {0}; clock_gettime(CLOCK_REALTIME, &end); - end.tv_sec += 300; // wait 5 minutes to send first report + end.tv_sec += 300; // wait 5 minutes before send first report while (1) { - while (1) { - if (sem_timedwait(&tsExitSem, &end) == 0) { - return NULL; - } - struct timespec now = {0}; - clock_gettime(CLOCK_REALTIME, &now); - if (now.tv_sec > end.tv_sec || (now.tv_sec == end.tv_sec && now.tv_nsec >= end.tv_nsec)) { - break; - } + if (sem_timedwait(&tsExitSem, &end) == 0) { + break; + } else if (errno != ETIMEDOUT) { + continue; } if (sdbIsMaster()) { diff --git a/src/mnode/inc/mnodeAcct.h b/src/mnode/inc/mnodeAcct.h index 44c3fc3cb8144c9e341e52819f67244dde1f2950..744a62f948dae7174eb782fa788c2276c99efd01 100644 --- a/src/mnode/inc/mnodeAcct.h +++ b/src/mnode/inc/mnodeAcct.h @@ -24,6 +24,7 @@ extern "C" { int32_t mnodeInitAccts(); void mnodeCleanupAccts(); +void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo); void * mnodeGetAcct(char *acctName); void * mnodeGetNextAcct(void *pIter, SAcctObj **pAcct); void mnodeIncAcctRef(SAcctObj *pAcct); diff --git a/src/mnode/inc/mnodeDb.h b/src/mnode/inc/mnodeDb.h index ca6c2a86a255b93a7d7af55d3bf01f126a6bc6ba..7cbd08ed92bc42e165469d60e3fb25e724415981 100644 --- a/src/mnode/inc/mnodeDb.h +++ b/src/mnode/inc/mnodeDb.h @@ -30,6 +30,7 @@ enum _TSDB_DB_STATUS { // api int32_t mnodeInitDbs(); void mnodeCleanupDbs(); +int64_t mnodeGetDbNum(); SDbObj *mnodeGetDb(char *db); SDbObj *mnodeGetDbByTableId(char *db); void * mnodeGetNextDb(void *pIter, SDbObj **pDb); diff --git a/src/mnode/inc/mnodeTable.h b/src/mnode/inc/mnodeTable.h index 78ef0e37e8a870a01b687235cb355794a906ef06..ed0dbe4ecfc4b344052c70487c3b740d81eaa0f3 100644 --- a/src/mnode/inc/mnodeTable.h +++ b/src/mnode/inc/mnodeTable.h @@ -24,6 +24,8 @@ extern "C" { int32_t mnodeInitTables(); void mnodeCleanupTables(); +int64_t mnodeGetSuperTableNum(); +int64_t mnodeGetChildTableNum(); void * mnodeGetTable(char *tableId); void mnodeIncTableRef(void *pTable); void mnodeDecTableRef(void *pTable); diff --git a/src/mnode/inc/mnodeVgroup.h b/src/mnode/inc/mnodeVgroup.h index 9c5b201e937e15888ff7498d2d9a7df8dc24eaeb..7aa662b81cc08c90d6453ff5c73191ad81416073 100644 --- a/src/mnode/inc/mnodeVgroup.h +++ b/src/mnode/inc/mnodeVgroup.h @@ -24,6 +24,7 @@ struct SMnodeMsg; int32_t mnodeInitVgroups(); void mnodeCleanupVgroups(); +int64_t mnodeGetVgroupNum(); SVgObj *mnodeGetVgroup(int32_t vgId); void mnodeIncVgroupRef(SVgObj *pVgroup); void mnodeDecVgroupRef(SVgObj *pVgroup); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 5244bc3e85152fd866273d61a1a862fa66be7615..b0a12979cd48f00739143ff6e8dce9b0ce5de4d2 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -23,6 +23,7 @@ #include "mnodeDb.h" #include "mnodeSdb.h" #include "mnodeUser.h" +#include "mnodeVgroup.h" #include "tglobal.h" @@ -130,6 +131,37 @@ void mnodeCleanupAccts() { tsAcctSdb = NULL; } +void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo) { + memset(pAcctInfo, 0, sizeof(*pAcctInfo)); + + void *pIter = NULL; + SAcctObj *pAcct = NULL; + while (1) { + pIter = mnodeGetNextAcct(pIter, &pAcct); + if (pAcct == NULL) { + break; + } + pAcctInfo->numOfDbs += pAcct->acctInfo.numOfDbs; + pAcctInfo->numOfTimeSeries += pAcct->acctInfo.numOfTimeSeries; + mnodeDecAcctRef(pAcct); + } + sdbFreeIter(pIter); + + SVgObj *pVgroup = NULL; + pIter = NULL; + while (1) { + pIter = mnodeGetNextVgroup(pIter, &pVgroup); + if (pVgroup == NULL) { + break; + } + pAcctInfo->totalStorage += pVgroup->totalStorage; + pAcctInfo->compStorage += pVgroup->compStorage; + pAcctInfo->totalPoints += pVgroup->pointsWritten; + mnodeDecVgroupRef(pVgroup); + } + sdbFreeIter(pIter); +} + void *mnodeGetAcct(char *name) { return sdbGetRow(tsAcctSdb, name); } diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 48acc6787c0d601a1efceb182ea0da48da407a13..7f9be7eb544b68cead9a524f874ce47030f6e4a9 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -61,6 +61,10 @@ static int32_t mnodeDbActionDestroy(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } +int64_t mnodeGetDbNum() { + return sdbGetNumOfRows(tsDbSdb); +} + static int32_t mnodeDbActionInsert(SSdbOper *pOper) { SDbObj *pDb = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index ac7d44b1a6cb4294ae76788adf56fca1396b9ee9..7b928fe885bd0c21cf823230d3d1fb987a848684 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -375,6 +375,14 @@ static void mnodeCleanupChildTables() { tsChildTableSdb = NULL; } +int64_t mnodeGetSuperTableNum() { + return sdbGetNumOfRows(tsSuperTableSdb); +} + +int64_t mnodeGetChildTableNum() { + return sdbGetNumOfRows(tsChildTableSdb); +} + static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { atomic_add_fetch_32(&pStable->numOfTables, 1); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index bfeff1f4cbecdadc967854c1da58039749a481a0..e1c81db0ac83c03bf6f310c7191e0342c6a4e3db 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -605,6 +605,10 @@ void mnodeCleanupVgroups() { tsVgroupSdb = NULL; } +int64_t mnodeGetVgroupNum() { + return sdbGetNumOfRows(tsVgroupSdb); +} + static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) {