• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4800

16 Oct 2025 09:19AM UTC coverage: 53.935% (-7.1%) from 61.083%
#4800

push

travis-ci

web-flow
Merge b32e3a393 into a190048d5

134724 of 323629 branches covered (41.63%)

Branch coverage included in aggregate %.

184803 of 268802 relevant lines covered (68.75%)

69058627.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.59
/source/dnode/mnode/impl/src/mndTelem.c
1
/*
2
 * Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "mndTelem.h"
18
#include "mndCluster.h"
19
#include "mndSync.h"
20
#include "thttp.h"
21
#include "tjson.h"
22
#include "mndAnode.h"
23

24

25
typedef struct {
26
  int64_t numOfDnode;
27
  int64_t numOfMnode;
28
  int64_t numOfVgroup;
29
  int64_t numOfDatabase;
30
  int64_t numOfSuperTable;
31
  int64_t numOfChildTable;
32
  int64_t numOfNormalTable;
33
  int64_t numOfColumn;
34
  int64_t totalPoints;
35
  int64_t totalStorage;
36
  int64_t compStorage;
37
  int32_t numOfAnalysisAlgos;
38
} SMnodeStat;
39

40
static void mndGetStat(SMnode* pMnode, SMnodeStat* pStat) {
×
41
  memset(pStat, 0, sizeof(SMnodeStat));
×
42

43
  SSdb* pSdb = pMnode->pSdb;
×
44
  pStat->numOfDnode = sdbGetSize(pSdb, SDB_DNODE);
×
45
  pStat->numOfMnode = sdbGetSize(pSdb, SDB_MNODE);
×
46
  pStat->numOfVgroup = sdbGetSize(pSdb, SDB_VGROUP);
×
47
  pStat->numOfDatabase = sdbGetSize(pSdb, SDB_DB);
×
48
  pStat->numOfSuperTable = sdbGetSize(pSdb, SDB_STB);
×
49

50
  void* pIter = NULL;
×
51
  while (1) {
×
52
    SVgObj* pVgroup = NULL;
×
53
    pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
×
54
    if (pIter == NULL) break;
×
55

56
    if (pVgroup->mountVgId) {
×
57
      sdbRelease(pSdb, pVgroup);
×
58
      continue;
×
59
    }
60
    pStat->numOfChildTable += pVgroup->numOfTables;
×
61
    pStat->numOfColumn += pVgroup->numOfTimeSeries;
×
62
    pStat->totalPoints += pVgroup->pointsWritten;
×
63
    pStat->totalStorage += pVgroup->totalStorage;
×
64
    pStat->compStorage += pVgroup->compStorage;
×
65

66
    sdbRelease(pSdb, pVgroup);
×
67
  }
68
}
×
69

70
static int32_t algoToJson(const void* pObj, SJson* pJson) {
×
71
  const SAnodeAlgo* pNode = (const SAnodeAlgo*)pObj;
×
72
  int32_t code = tjsonAddStringToObject(pJson, "name", pNode->name);
×
73
  return code;
×
74
}
75

76
static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) {
×
77
  SMnodeStat mstat = {0};
×
78
  int32_t    code = 0;
×
79
  int32_t    lino = 0;
×
80
  SArray*    pFcList = NULL;
×
81
  SArray*    pAdList = NULL;
×
82

83
  mndGetStat(pMnode, &mstat);
×
84

85
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfDnode", mstat.numOfDnode), &lino, _OVER);
×
86
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfMnode", mstat.numOfMnode), &lino, _OVER);
×
87
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfVgroup", mstat.numOfVgroup), &lino, _OVER);
×
88
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfDatabase", mstat.numOfDatabase), &lino, _OVER);
×
89
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfSuperTable", mstat.numOfSuperTable), &lino, _OVER);
×
90
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfChildTable", mstat.numOfChildTable), &lino, _OVER);
×
91
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfColumn", mstat.numOfColumn), &lino, _OVER);
×
92
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfPoint", mstat.totalPoints), &lino, _OVER);
×
93
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "totalStorage", mstat.totalStorage), &lino, _OVER);
×
94
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "compStorage", mstat.compStorage), &lino, _OVER);
×
95

96
  pFcList = taosArrayInit(4, sizeof(SAnodeAlgo));
×
97
  pAdList = taosArrayInit(4, sizeof(SAnodeAlgo));
×
98
  if (pFcList == NULL || pAdList == NULL) {
×
99
    lino = __LINE__;
×
100
    goto _OVER;
×
101
  }
102

103
  mndRetrieveAlgoList(pMnode, pFcList, pAdList);
×
104

105
  if (taosArrayGetSize(pFcList) > 0) {
×
106
    SJson* items = tjsonAddArrayToObject(pJson, "forecast");
×
107
    TSDB_CHECK_NULL(items, code, lino, _OVER, terrno);
×
108

109
    for (int32_t i = 0; i < taosArrayGetSize(pFcList); ++i) {
×
110
      SJson* item = tjsonCreateObject();
×
111

112
      TSDB_CHECK_NULL(item, code, lino, _OVER, terrno);
×
113
      TAOS_CHECK_GOTO(tjsonAddItemToArray(items, item), &lino, _OVER);
×
114

115
      SAnodeAlgo* p = taosArrayGet(pFcList, i);
×
116
      TSDB_CHECK_NULL(p, code, lino, _OVER, terrno);
×
117
      TAOS_CHECK_GOTO(tjsonAddStringToObject(item, "name", p->name), &lino, _OVER);
×
118
    }
119
  }
120

121
  if (taosArrayGetSize(pAdList) > 0) {
×
122
    SJson* items1 = tjsonAddArrayToObject(pJson, "anomaly_detection");
×
123
    TSDB_CHECK_NULL(items1, code, lino, _OVER, terrno);
×
124

125
    for (int32_t i = 0; i < taosArrayGetSize(pAdList); ++i) {
×
126
      SJson* item = tjsonCreateObject();
×
127

128
      TSDB_CHECK_NULL(item, code, lino, _OVER, terrno);
×
129
      TAOS_CHECK_GOTO(tjsonAddItemToArray(items1, item), &lino, _OVER);
×
130

131
      SAnodeAlgo* p = taosArrayGet(pAdList, i);
×
132
      TSDB_CHECK_NULL(p, code, lino, _OVER, terrno);
×
133
      TAOS_CHECK_GOTO(tjsonAddStringToObject(item, "name", p->name), &lino, _OVER);
×
134
    }
135
  }
136

137
_OVER:
×
138
  taosArrayDestroy(pFcList);
×
139
  taosArrayDestroy(pAdList);
×
140

141
  if (code != 0) {
×
142
    mError("failed to mndBuildRuntimeInfo at line:%d since %s", lino, tstrerror(code));
×
143
  }
144
}
×
145

146
static char* mndBuildTelemetryReport(SMnode* pMnode) {
×
147
  char        tmp[4096] = {0};
×
148
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
×
149
  int32_t     code = 0;
×
150
  int32_t     lino = 0;
×
151

152
  SJson* pJson = tjsonCreateObject();
×
153
  if (pJson == NULL) return NULL;
×
154

155
  char clusterName[64] = {0};
×
156
  if ((terrno = mndGetClusterName(pMnode, clusterName, sizeof(clusterName))) != 0) return NULL;
×
157
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "instanceId", clusterName), &lino, _OVER);
×
158
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "reportVersion", 1), &lino, _OVER);
×
159

160
  if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) {
×
161
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "os", tmp), &lino, _OVER);
×
162
  }
163

164
  float numOfCores = 0;
×
165
  if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
×
166
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "cpuModel", tmp), &lino, _OVER);
×
167
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores), &lino, _OVER);
×
168
  } else {
169
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores), &lino, _OVER);
×
170
  }
171

172
  snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
×
173
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), &lino, _OVER);
×
174

175
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), &lino, _OVER);
×
176
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), &lino, _OVER);
×
177
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), &lino, _OVER);
×
178
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "email", pMgmt->email), &lino, _OVER);
×
179

180
  mndBuildRuntimeInfo(pMnode, pJson);
×
181

182
_OVER:
×
183
  if (code != 0) {
×
184
    mError("failed to build telemetry report at lino:%d, since %s", lino, tstrerror(code));
×
185
  }
186
  char* pCont = tjsonToString(pJson);
×
187
  tjsonDelete(pJson);
×
188
  return pCont;
×
189
}
190

191
static int32_t mndProcessTelemTimer(SRpcMsg* pReq) {
×
192
  int32_t     code = 0;
×
193
  int32_t     line = 0;
×
194
  SMnode*     pMnode = pReq->info.node;
×
195
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
×
196

197
  if (!tsEnableTelem) {
×
198
    return 0;
×
199
  }
200

201
  (void)taosThreadMutexLock(&pMgmt->lock);
×
202
  char* pCont = mndBuildTelemetryReport(pMnode);
×
203
  (void)taosThreadMutexUnlock(&pMgmt->lock);
×
204

205
  TSDB_CHECK_NULL(pCont, code, line, _end, terrno);
×
206

207
  code = taosSendTelemReport(&pMgmt->addrMgt, tsTelemUri, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT);
×
208
  taosMemoryFree(pCont);
×
209
  return code;
×
210

211
_end:
×
212
  if (code != 0) {
×
213
    mError("%s failed to send telemetry report, line %d since %s", __func__, line, tstrerror(code));
×
214
  }
215
  taosMemoryFree(pCont);
×
216
  return code;
×
217
}
218

219
int32_t mndInitTelem(SMnode* pMnode) {
164,691✔
220
  int32_t     code = 0;
164,691✔
221
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
164,691✔
222

223
  (void)taosThreadMutexInit(&pMgmt->lock, NULL);
164,691✔
224
  if ((code = taosGetEmail(pMgmt->email, sizeof(pMgmt->email))) != 0) {
164,691!
225
    mWarn("failed to get email since %s", tstrerror(code));
164,691!
226
  }
227

228
  code = taosTelemetryMgtInit(&pMgmt->addrMgt, tsTelemServer);
164,691✔
229
  if (code != 0) {
164,691!
230
    mError("failed to init telemetry management since %s", tstrerror(code));
×
231
    return code;
×
232
  }
233

234
  mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
164,691✔
235
  return 0;
164,691✔
236
}
237

238
void mndCleanupTelem(SMnode* pMnode) {
164,647✔
239
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
164,647✔
240
  taosTelemetryDestroy(&pMgmt->addrMgt);
164,647✔
241
  (void)taosThreadMutexDestroy(&pMgmt->lock);
164,647✔
242
}
164,647✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc