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

taosdata / TDengine / #4488

12 Jul 2025 07:47AM UTC coverage: 62.207% (-0.7%) from 62.948%
#4488

push

travis-ci

web-flow
docs: update stream docs (#31822)

157961 of 324087 branches covered (48.74%)

Branch coverage included in aggregate %.

244465 of 322830 relevant lines covered (75.73%)

6561668.76 hits per line

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

55.94
/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
typedef struct {
25
  int64_t numOfDnode;
26
  int64_t numOfMnode;
27
  int64_t numOfVgroup;
28
  int64_t numOfDatabase;
29
  int64_t numOfSuperTable;
30
  int64_t numOfChildTable;
31
  int64_t numOfNormalTable;
32
  int64_t numOfColumn;
33
  int64_t totalPoints;
34
  int64_t totalStorage;
35
  int64_t compStorage;
36
  int32_t numOfAnalysisAlgos;
37
} SMnodeStat;
38

39
static void mndGetStat(SMnode* pMnode, SMnodeStat* pStat) {
2✔
40
  memset(pStat, 0, sizeof(SMnodeStat));
2✔
41

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

49
  void* pIter = NULL;
2✔
50
  while (1) {
8✔
51
    SVgObj* pVgroup = NULL;
10✔
52
    pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
10✔
53
    if (pIter == NULL) break;
10✔
54

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

65
    sdbRelease(pSdb, pVgroup);
8✔
66
  }
67
}
2✔
68

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

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

82
  mndGetStat(pMnode, &mstat);
2✔
83

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

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

102
  mndRetrieveAlgoList(pMnode, pFcList, pAdList);
2✔
103

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

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

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

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

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

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

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

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

136
_OVER:
2✔
137
  taosArrayDestroy(pFcList);
2✔
138
  taosArrayDestroy(pAdList);
2✔
139

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

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

151
  SJson* pJson = tjsonCreateObject();
2✔
152
  if (pJson == NULL) return NULL;
2!
153

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

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

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

171
  snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
2✔
172
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), &lino, _OVER);
2!
173

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

179
  mndBuildRuntimeInfo(pMnode, pJson);
2✔
180

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

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

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

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

204
  TSDB_CHECK_NULL(pCont, code, line, _end, terrno);
2!
205

206
  code = taosSendTelemReport(&pMgmt->addrMgt, tsTelemUri, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT);
2✔
207
  taosMemoryFree(pCont);
2!
208
  return code;
2✔
209

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

218
int32_t mndInitTelem(SMnode* pMnode) {
2,467✔
219
  int32_t     code = 0;
2,467✔
220
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
2,467✔
221

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

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

233
  mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
2,467✔
234
  return 0;
2,467✔
235
}
236

237
void mndCleanupTelem(SMnode* pMnode) {
2,466✔
238
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
2,466✔
239
  taosTelemetryDestroy(&pMgmt->addrMgt);
2,466✔
240
  (void)taosThreadMutexDestroy(&pMgmt->lock);
2,466✔
241
}
2,466✔
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