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

#define _DEFAULT_SOURCE
#include "monInt.h"
S
monitor  
Shengliang Guan 已提交
18 19 20
#include "taoserror.h"
#include "thttp.h"
#include "tlog.h"
21
#include "ttime.h"
S
Shengliang Guan 已提交
22

S
monitor  
Shengliang Guan 已提交
23 24
static SMonitor tsMonitor = {0};

S
Shengliang Guan 已提交
25
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
S
Shengliang Guan 已提交
26
  pthread_mutex_lock(&tsMonitor.lock);
S
Shengliang Guan 已提交
27
  int32_t size = taosArrayGetSize(tsMonitor.logs);
S
Shengliang Guan 已提交
28
  if (size < tsMonitor.maxLogs) {
S
Shengliang Guan 已提交
29 30 31
    SMonLogItem  item = {.ts = ts, .level = level};
    SMonLogItem *pItem = taosArrayPush(tsMonitor.logs, &item);
    if (pItem != NULL) {
S
Shengliang Guan 已提交
32
      tstrncpy(pItem->content, content, MON_LOG_LEN);
S
Shengliang Guan 已提交
33 34
    }
  }
S
Shengliang Guan 已提交
35
  pthread_mutex_unlock(&tsMonitor.lock);
S
Shengliang Guan 已提交
36 37
}

S
monitor  
Shengliang Guan 已提交
38
int32_t monInit(const SMonCfg *pCfg) {
S
monitor  
Shengliang Guan 已提交
39
  tsMonitor.logs = taosArrayInit(16, sizeof(SMonLogItem));
S
monitor  
Shengliang Guan 已提交
40 41 42 43 44 45 46 47
  if (tsMonitor.logs == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

  tsMonitor.maxLogs = pCfg->maxLogs;
  tsMonitor.server = pCfg->server;
  tsMonitor.port = pCfg->port;
S
Shengliang Guan 已提交
48
  tsLogFp = monRecordLog;
S
monitor  
Shengliang Guan 已提交
49
  tsMonitor.state.time = taosGetTimestampMs();
S
Shengliang Guan 已提交
50
  pthread_mutex_init(&tsMonitor.lock, NULL);
S
monitor  
Shengliang Guan 已提交
51 52 53 54
  return 0;
}

void monCleanup() {
S
Shengliang Guan 已提交
55
  tsLogFp = NULL;
S
monitor  
Shengliang Guan 已提交
56 57
  taosArrayDestroy(tsMonitor.logs);
  tsMonitor.logs = NULL;
S
Shengliang Guan 已提交
58
  pthread_mutex_destroy(&tsMonitor.lock);
S
monitor  
Shengliang Guan 已提交
59 60 61 62
}

SMonInfo *monCreateMonitorInfo() {
  SMonInfo *pMonitor = calloc(1, sizeof(SMonInfo));
S
monitor  
Shengliang Guan 已提交
63 64 65 66
  if (pMonitor == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return NULL;
  }
S
monitor  
Shengliang Guan 已提交
67

S
Shengliang Guan 已提交
68
  pthread_mutex_lock(&tsMonitor.lock);
69
  pMonitor->logs = taosArrayDup(tsMonitor.logs);
S
monitor  
Shengliang Guan 已提交
70
  taosArrayClear(tsMonitor.logs);
S
Shengliang Guan 已提交
71
  pthread_mutex_unlock(&tsMonitor.lock);
S
monitor  
Shengliang Guan 已提交
72 73 74 75 76 77 78 79

  pMonitor->pJson = tjsonCreateObject();
  if (pMonitor->pJson == NULL || pMonitor->logs == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    monCleanupMonitorInfo(pMonitor);
    return NULL;
  }

S
monitor  
Shengliang Guan 已提交
80 81
  pMonitor->curTime = taosGetTimestampMs();
  pMonitor->lastState = tsMonitor.state;
S
monitor  
Shengliang Guan 已提交
82 83 84 85
  return pMonitor;
}

void monCleanupMonitorInfo(SMonInfo *pMonitor) {
S
monitor  
Shengliang Guan 已提交
86 87
  tsMonitor.state = pMonitor->lastState;
  tsMonitor.state.time = pMonitor->curTime;
S
monitor  
Shengliang Guan 已提交
88 89 90 91 92 93
  taosArrayDestroy(pMonitor->logs);
  tjsonDelete(pMonitor->pJson);
  free(pMonitor);
}

void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
94 95 96
  SJson *pJson = pMonitor->pJson;
  char   buf[40] = {0};
  taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI);
S
monitor  
Shengliang Guan 已提交
97

98
  tjsonAddStringToObject(pJson, "ts", buf);
S
monitor  
Shengliang Guan 已提交
99 100
  tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id);
  tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep);
S
monitor  
Shengliang Guan 已提交
101 102
}

S
monitor  
Shengliang Guan 已提交
103
void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
104 105
  SJson *pJson = tjsonCreateObject();
  if (pJson == NULL) return;
S
monitor  
Shengliang Guan 已提交
106 107 108 109
  if (tjsonAddItemToObject(pMonitor->pJson, "cluster_info", pJson) != 0) {
    tjsonDelete(pJson);
    return;
  }
S
monitor  
Shengliang Guan 已提交
110

S
monitor  
Shengliang Guan 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  tjsonAddStringToObject(pJson, "first_ep", pInfo->first_ep);
  tjsonAddDoubleToObject(pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id);
  tjsonAddStringToObject(pJson, "version", pInfo->version);
  tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime);
  tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval);
  tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total);
  tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive);
  tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total);
  tjsonAddDoubleToObject(pJson, "vnodes_alive", pInfo->vnodes_alive);
  tjsonAddDoubleToObject(pJson, "connections_total", pInfo->connections_total);

  SJson *pDnodesJson = tjsonAddArrayToObject(pJson, "dnodes");
  if (pDnodesJson == NULL) return;

  for (int32_t i = 0; i < taosArrayGetSize(pInfo->dnodes); ++i) {
    SJson *pDnodeJson = tjsonCreateObject();
    if (pDnodeJson == NULL) continue;

    SMonDnodeDesc *pDnodeDesc = taosArrayGet(pInfo->dnodes, i);
S
monitor  
Shengliang Guan 已提交
130 131 132
    tjsonAddDoubleToObject(pDnodeJson, "dnode_id", pDnodeDesc->dnode_id);
    tjsonAddStringToObject(pDnodeJson, "dnode_ep", pDnodeDesc->dnode_ep);
    tjsonAddStringToObject(pDnodeJson, "status", pDnodeDesc->status);
S
monitor  
Shengliang Guan 已提交
133 134 135 136 137 138 139

    if (tjsonAddItemToArray(pDnodesJson, pDnodeJson) != 0) tjsonDelete(pDnodeJson);
  }

  SJson *pMnodesJson = tjsonAddArrayToObject(pJson, "mnodes");
  if (pMnodesJson == NULL) return;

S
Shengliang Guan 已提交
140
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->mnodes); ++i) {
S
monitor  
Shengliang Guan 已提交
141 142 143
    SJson *pMnodeJson = tjsonCreateObject();
    if (pMnodeJson == NULL) continue;

S
Shengliang Guan 已提交
144
    SMonMnodeDesc *pMnodeDesc = taosArrayGet(pInfo->mnodes, i);
S
monitor  
Shengliang Guan 已提交
145 146 147
    tjsonAddDoubleToObject(pMnodeJson, "mnode_id", pMnodeDesc->mnode_id);
    tjsonAddStringToObject(pMnodeJson, "mnode_ep", pMnodeDesc->mnode_ep);
    tjsonAddStringToObject(pMnodeJson, "role", pMnodeDesc->role);
S
monitor  
Shengliang Guan 已提交
148 149 150

    if (tjsonAddItemToArray(pMnodesJson, pMnodeJson) != 0) tjsonDelete(pMnodeJson);
  }
S
monitor  
Shengliang Guan 已提交
151 152 153
}

void monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
154
  SJson *pJson = tjsonAddArrayToObject(pMonitor->pJson, "vgroup_infos");
S
monitor  
Shengliang Guan 已提交
155 156 157 158 159
  if (pJson == NULL) return;

  for (int32_t i = 0; i < taosArrayGetSize(pInfo->vgroups); ++i) {
    SJson *pVgroupJson = tjsonCreateObject();
    if (pVgroupJson == NULL) continue;
S
monitor  
Shengliang Guan 已提交
160 161 162 163
    if (tjsonAddItemToArray(pJson, pVgroupJson) != 0) {
      tjsonDelete(pVgroupJson);
      continue;
    }
S
monitor  
Shengliang Guan 已提交
164

S
monitor  
Shengliang Guan 已提交
165
    SMonVgroupDesc *pVgroupDesc = taosArrayGet(pInfo->vgroups, i);
S
monitor  
Shengliang Guan 已提交
166 167 168 169
    tjsonAddDoubleToObject(pVgroupJson, "vgroup_id", pVgroupDesc->vgroup_id);
    tjsonAddStringToObject(pVgroupJson, "database_name", pVgroupDesc->database_name);
    tjsonAddDoubleToObject(pVgroupJson, "tables_num", pVgroupDesc->tables_num);
    tjsonAddStringToObject(pVgroupJson, "status", pVgroupDesc->status);
S
monitor  
Shengliang Guan 已提交
170 171

    SJson *pVnodesJson = tjsonAddArrayToObject(pVgroupJson, "vnodes");
S
monitor  
Shengliang Guan 已提交
172
    if (pVnodesJson == NULL) continue;
S
monitor  
Shengliang Guan 已提交
173 174 175

    for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
      SMonVnodeDesc *pVnodeDesc = &pVgroupDesc->vnodes[j];
S
monitor  
Shengliang Guan 已提交
176
      if (pVnodeDesc->dnode_id <= 0) continue;
S
monitor  
Shengliang Guan 已提交
177 178 179 180

      SJson *pVnodeJson = tjsonCreateObject();
      if (pVnodeJson == NULL) continue;

S
monitor  
Shengliang Guan 已提交
181 182
      tjsonAddDoubleToObject(pVnodeJson, "dnode_id", pVnodeDesc->dnode_id);
      tjsonAddStringToObject(pVnodeJson, "vnode_role", pVnodeDesc->vnode_role);
S
monitor  
Shengliang Guan 已提交
183 184 185 186

      if (tjsonAddItemToArray(pVnodesJson, pVnodeJson) != 0) tjsonDelete(pVnodeJson);
    }
  }
S
monitor  
Shengliang Guan 已提交
187 188 189
}

void monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
190 191
  SJson *pJson = tjsonCreateObject();
  if (pJson == NULL) return;
S
monitor  
Shengliang Guan 已提交
192 193 194 195
  if (tjsonAddItemToObject(pMonitor->pJson, "grant_info", pJson) != 0) {
    tjsonDelete(pJson);
    return;
  }
S
monitor  
Shengliang Guan 已提交
196

S
monitor  
Shengliang Guan 已提交
197 198 199
  tjsonAddDoubleToObject(pJson, "expire_time", pInfo->expire_time);
  tjsonAddDoubleToObject(pJson, "timeseries_used", pInfo->timeseries_used);
  tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total);
S
monitor  
Shengliang Guan 已提交
200 201 202
}

void monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
203 204
  SJson *pJson = tjsonCreateObject();
  if (pJson == NULL) return;
S
monitor  
Shengliang Guan 已提交
205 206 207 208
  if (tjsonAddItemToObject(pMonitor->pJson, "dnode_info", pJson) != 0) {
    tjsonDelete(pJson);
    return;
  }
S
monitor  
Shengliang Guan 已提交
209

S
monitor  
Shengliang Guan 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
  SMonState *pLast = &pMonitor->lastState;
  double     interval = (pMonitor->curTime - pLast->time) / 1000.0;
  double     req_select_rate = (pInfo->req_select - pLast->req_select) / interval;
  double     req_insert_rate = (pInfo->req_insert - pLast->req_insert) / interval;
  double     req_insert_batch_rate = (pInfo->req_insert_batch - pLast->req_insert_batch) / interval;
  double     net_in_rate = (pInfo->net_in - pLast->net_in) / interval;
  double     net_out_rate = (pInfo->net_out - pLast->net_out) / interval;
  double     io_read_rate = (pInfo->io_read - pLast->io_read) / interval;
  double     io_write_rate = (pInfo->io_write - pLast->io_write) / interval;
  double     io_read_disk_rate = (pInfo->io_read_disk - pLast->io_read_disk) / interval;
  double     io_write_disk_rate = (pInfo->io_write_disk - pLast->io_write_disk) / interval;
  pLast->req_select = pInfo->req_select;
  pLast->req_insert = pInfo->req_insert;
  pLast->req_insert_batch = pInfo->req_insert_batch;
  pLast->net_in = pInfo->net_in;
  pLast->net_out = pInfo->net_out;
  pLast->io_read = pInfo->io_read;
  pLast->io_write = pInfo->io_write;
  pLast->io_read_disk = pInfo->io_read_disk;
  pLast->io_write_disk = pInfo->io_write_disk;

S
monitor  
Shengliang Guan 已提交
231 232 233 234 235 236 237 238 239 240
  tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime);
  tjsonAddDoubleToObject(pJson, "cpu_engine", pInfo->cpu_engine);
  tjsonAddDoubleToObject(pJson, "cpu_system", pInfo->cpu_system);
  tjsonAddDoubleToObject(pJson, "cpu_cores", pInfo->cpu_cores);
  tjsonAddDoubleToObject(pJson, "mem_engine", pInfo->mem_engine);
  tjsonAddDoubleToObject(pJson, "mem_system", pInfo->mem_system);
  tjsonAddDoubleToObject(pJson, "mem_total", pInfo->mem_total);
  tjsonAddDoubleToObject(pJson, "disk_engine", pInfo->disk_engine);
  tjsonAddDoubleToObject(pJson, "disk_used", pInfo->disk_used);
  tjsonAddDoubleToObject(pJson, "disk_total", pInfo->disk_total);
S
monitor  
Shengliang Guan 已提交
241 242 243 244 245 246
  tjsonAddDoubleToObject(pJson, "net_in", net_in_rate);
  tjsonAddDoubleToObject(pJson, "net_out", net_out_rate);
  tjsonAddDoubleToObject(pJson, "io_read", io_read_rate);
  tjsonAddDoubleToObject(pJson, "io_write", io_write_rate);
  tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate);
  tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate);
S
monitor  
Shengliang Guan 已提交
247
  tjsonAddDoubleToObject(pJson, "req_select", pInfo->req_select);
S
monitor  
Shengliang Guan 已提交
248
  tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate);
S
monitor  
Shengliang Guan 已提交
249 250
  tjsonAddDoubleToObject(pJson, "req_insert", pInfo->req_insert);
  tjsonAddDoubleToObject(pJson, "req_insert_success", pInfo->req_insert_success);
S
monitor  
Shengliang Guan 已提交
251
  tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate);
S
monitor  
Shengliang Guan 已提交
252 253
  tjsonAddDoubleToObject(pJson, "req_insert_batch", pInfo->req_insert_batch);
  tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pInfo->req_insert_batch_success);
S
monitor  
Shengliang Guan 已提交
254
  tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate);
S
monitor  
Shengliang Guan 已提交
255 256 257 258
  tjsonAddDoubleToObject(pJson, "errors", pInfo->errors);
  tjsonAddDoubleToObject(pJson, "vnodes_num", pInfo->vnodes_num);
  tjsonAddDoubleToObject(pJson, "masters", pInfo->masters);
  tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode);
S
monitor  
Shengliang Guan 已提交
259 260 261
}

void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) {
S
monitor  
Shengliang Guan 已提交
262 263
  SJson *pJson = tjsonCreateObject();
  if (pJson == NULL) return;
S
monitor  
Shengliang Guan 已提交
264
  if (tjsonAddItemToObject(pMonitor->pJson, "disk_infos", pJson) != 0) {
S
monitor  
Shengliang Guan 已提交
265 266 267
    tjsonDelete(pJson);
    return;
  }
S
monitor  
Shengliang Guan 已提交
268

S
monitor  
Shengliang Guan 已提交
269
  SJson *pDatadirsJson = tjsonAddArrayToObject(pJson, "datadir");
S
monitor  
Shengliang Guan 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
  if (pDatadirsJson == NULL) return;

  for (int32_t i = 0; i < taosArrayGetSize(pInfo->datadirs); ++i) {
    SJson *pDatadirJson = tjsonCreateObject();
    if (pDatadirJson == NULL) continue;

    SMonDiskDesc *pDatadirDesc = taosArrayGet(pInfo->datadirs, i);
    if (tjsonAddStringToObject(pDatadirJson, "name", pDatadirDesc->name) != 0) tjsonDelete(pDatadirJson);
    if (tjsonAddDoubleToObject(pDatadirJson, "level", pDatadirDesc->level) != 0) tjsonDelete(pDatadirJson);
    if (tjsonAddDoubleToObject(pDatadirJson, "avail", pDatadirDesc->size.avail) != 0) tjsonDelete(pDatadirJson);
    if (tjsonAddDoubleToObject(pDatadirJson, "used", pDatadirDesc->size.used) != 0) tjsonDelete(pDatadirJson);
    if (tjsonAddDoubleToObject(pDatadirJson, "total", pDatadirDesc->size.total) != 0) tjsonDelete(pDatadirJson);

    if (tjsonAddItemToArray(pDatadirsJson, pDatadirJson) != 0) tjsonDelete(pDatadirJson);
  }

  SJson *pLogdirJson = tjsonCreateObject();
  if (pLogdirJson == NULL) return;
  if (tjsonAddItemToObject(pJson, "logdir", pLogdirJson) != 0) return;
  tjsonAddStringToObject(pLogdirJson, "name", pInfo->logdir.name);
  tjsonAddDoubleToObject(pLogdirJson, "avail", pInfo->logdir.size.avail);
  tjsonAddDoubleToObject(pLogdirJson, "used", pInfo->logdir.size.used);
  tjsonAddDoubleToObject(pLogdirJson, "total", pInfo->logdir.size.total);

  SJson *pTempdirJson = tjsonCreateObject();
  if (pTempdirJson == NULL) return;
  if (tjsonAddItemToObject(pJson, "tempdir", pTempdirJson) != 0) return;
  tjsonAddStringToObject(pTempdirJson, "name", pInfo->tempdir.name);
  tjsonAddDoubleToObject(pTempdirJson, "avail", pInfo->tempdir.size.avail);
  tjsonAddDoubleToObject(pTempdirJson, "used", pInfo->tempdir.size.used);
  tjsonAddDoubleToObject(pTempdirJson, "total", pInfo->tempdir.size.total);
S
monitor  
Shengliang Guan 已提交
301
}
S
monitor  
Shengliang Guan 已提交
302

303
static const char *monLogLevelStr(ELogLevel level) {
S
Shengliang Guan 已提交
304
  switch (level) {
305
    case DEBUG_ERROR:
S
Shengliang Guan 已提交
306
      return "error";
307
    case DEBUG_INFO:
S
Shengliang Guan 已提交
308
      return "info";
309
    case DEBUG_DEBUG:
S
Shengliang Guan 已提交
310
      return "debug";
311
    case DEBUG_TRACE:
S
Shengliang Guan 已提交
312 313 314 315 316 317
      return "trace";
    default:
      return "undefine";
  }
}

S
monitor  
Shengliang Guan 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
static void monSetLogInfo(SMonInfo *pMonitor) {
  SJson *pJson = tjsonCreateObject();
  if (pJson == NULL) return;
  if (tjsonAddItemToObject(pMonitor->pJson, "log_infos", pJson) != 0) {
    tjsonDelete(pJson);
    return;
  }

  SJson *pLogsJson = tjsonAddArrayToObject(pJson, "logs");
  if (pLogsJson == NULL) return;

  for (int32_t i = 0; i < taosArrayGetSize(pMonitor->logs); ++i) {
    SJson *pLogJson = tjsonCreateObject();
    if (pLogJson == NULL) continue;

    SMonLogItem *pLogItem = taosArrayGet(pMonitor->logs, i);

    char buf[40] = {0};
    taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI);

S
monitor  
Shengliang Guan 已提交
338
    tjsonAddStringToObject(pLogJson, "ts", buf);
S
Shengliang Guan 已提交
339
    tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level));
S
monitor  
Shengliang Guan 已提交
340
    tjsonAddStringToObject(pLogJson, "content", pLogItem->content);
S
monitor  
Shengliang Guan 已提交
341 342 343 344 345 346 347 348 349 350

    if (tjsonAddItemToArray(pLogsJson, pLogJson) != 0) tjsonDelete(pLogJson);
  }

  SJson *pSummaryJson = tjsonAddArrayToObject(pJson, "summary");
  if (pSummaryJson == NULL) return;

  SJson *pLogError = tjsonCreateObject();
  if (pLogError == NULL) return;
  tjsonAddStringToObject(pLogError, "level", "error");
351
  tjsonAddDoubleToObject(pLogError, "total", tsNumOfErrorLogs);
S
monitor  
Shengliang Guan 已提交
352 353 354 355 356
  if (tjsonAddItemToArray(pSummaryJson, pLogError) != 0) tjsonDelete(pLogError);

  SJson *pLogInfo = tjsonCreateObject();
  if (pLogInfo == NULL) return;
  tjsonAddStringToObject(pLogInfo, "level", "info");
357
  tjsonAddDoubleToObject(pLogInfo, "total", tsNumOfInfoLogs);
S
monitor  
Shengliang Guan 已提交
358 359 360 361 362
  if (tjsonAddItemToArray(pSummaryJson, pLogInfo) != 0) tjsonDelete(pLogInfo);

  SJson *pLogDebug = tjsonCreateObject();
  if (pLogDebug == NULL) return;
  tjsonAddStringToObject(pLogDebug, "level", "debug");
363
  tjsonAddDoubleToObject(pLogDebug, "total", tsNumOfDebugLogs);
S
monitor  
Shengliang Guan 已提交
364 365 366 367 368
  if (tjsonAddItemToArray(pSummaryJson, pLogDebug) != 0) tjsonDelete(pLogDebug);

  SJson *pLogTrace = tjsonCreateObject();
  if (pLogTrace == NULL) return;
  tjsonAddStringToObject(pLogTrace, "level", "trace");
369
  tjsonAddDoubleToObject(pLogTrace, "total", tsNumOfTraceLogs);
S
monitor  
Shengliang Guan 已提交
370 371 372 373 374 375 376 377 378 379 380 381
  if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace);
}

void monSendReport(SMonInfo *pMonitor) {
  monSetLogInfo(pMonitor);

  char *pCont = tjsonToString(pMonitor->pJson);
  if (pCont != NULL) {
    taosSendHttpReport(tsMonitor.server, tsMonitor.port, pCont, strlen(pCont));
    free(pCont);
  }
}