monMsg.c 23.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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"
#include "tcoding.h"
#include "tencode.h"

H
Hongze Cheng 已提交
21
static int32_t tEncodeSMonSysInfo(SEncoder *encoder, const SMonSysInfo *pInfo) {
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  if (tEncodeDouble(encoder, pInfo->cpu_engine) < 0) return -1;
  if (tEncodeDouble(encoder, pInfo->cpu_system) < 0) return -1;
  if (tEncodeFloat(encoder, pInfo->cpu_cores) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->mem_engine) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->mem_system) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->mem_total) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->disk_engine) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->disk_used) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->disk_total) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->net_in) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->net_out) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->io_read) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->io_write) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->io_read_disk) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->io_write_disk) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
40
static int32_t tDecodeSMonSysInfo(SDecoder *decoder, SMonSysInfo *pInfo) {
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  if (tDecodeDouble(decoder, &pInfo->cpu_engine) < 0) return -1;
  if (tDecodeDouble(decoder, &pInfo->cpu_system) < 0) return -1;
  if (tDecodeFloat(decoder, &pInfo->cpu_cores) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->mem_engine) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->mem_system) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->mem_total) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->disk_engine) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->disk_used) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->disk_total) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->net_in) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->net_out) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->io_read) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->io_write) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->io_read_disk) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->io_write_disk) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
59
int32_t tEncodeSMonLogs(SEncoder *encoder, const SMonLogs *pInfo) {
60 61 62 63 64 65 66 67 68 69 70 71 72 73
  if (tEncodeI32(encoder, pInfo->numOfErrorLogs) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->numOfInfoLogs) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->numOfDebugLogs) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->numOfTraceLogs) < 0) return -1;
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->logs)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->logs); ++i) {
    SMonLogItem *pLog = taosArrayGet(pInfo->logs, i);
    if (tEncodeI64(encoder, pLog->ts) < 0) return -1;
    if (tEncodeI8(encoder, pLog->level) < 0) return -1;
    if (tEncodeCStr(encoder, pLog->content) < 0) return -1;
  }
  return 0;
}

H
Hongze Cheng 已提交
74
static int32_t tDecodeSMonLogs(SDecoder *decoder, SMonLogs *pInfo) {
75 76 77 78 79 80 81 82 83
  if (tDecodeI32(decoder, &pInfo->numOfErrorLogs) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->numOfInfoLogs) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->numOfDebugLogs) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->numOfTraceLogs) < 0) return -1;

  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->logs = taosArrayInit(arraySize, sizeof(SMonLogItem));
84
  if (pInfo->logs == NULL) return -1;
85 86 87 88 89 90 91 92 93 94 95 96 97 98

  for (int32_t i = 0; i < arraySize; ++i) {
    SMonLogItem desc = {0};
    if (tDecodeI64(decoder, &desc.ts) < 0) return -1;
    int8_t level = 0;
    if (tDecodeI8(decoder, &level) < 0) return -1;
    desc.level = level;
    if (tDecodeCStrTo(decoder, desc.content) < 0) return -1;
    taosArrayPush(pInfo->logs, &desc);
  }

  return 0;
}

H
Hongze Cheng 已提交
99
int32_t tEncodeSMonClusterInfo(SEncoder *encoder, const SMonClusterInfo *pInfo) {
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  if (tEncodeCStr(encoder, pInfo->first_ep) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->first_ep_dnode_id) < 0) return -1;
  if (tEncodeCStr(encoder, pInfo->version) < 0) return -1;
  if (tEncodeFloat(encoder, pInfo->master_uptime) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->monitor_interval) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->vgroups_total) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->vgroups_alive) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->vnodes_total) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->vnodes_alive) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->connections_total) < 0) return -1;
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->dnodes)) < 0) return -1;
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->mnodes)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->dnodes); ++i) {
    SMonDnodeDesc *pDesc = taosArrayGet(pInfo->dnodes, i);
    if (tEncodeI32(encoder, pDesc->dnode_id) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->dnode_ep) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->status) < 0) return -1;
  }
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->mnodes); ++i) {
    SMonMnodeDesc *pDesc = taosArrayGet(pInfo->mnodes, i);
    if (tEncodeI32(encoder, pDesc->mnode_id) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->mnode_ep) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->role) < 0) return -1;
  }
  return 0;
}

H
Hongze Cheng 已提交
127
int32_t tDecodeSMonClusterInfo(SDecoder *decoder, SMonClusterInfo *pInfo) {
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  if (tDecodeCStrTo(decoder, pInfo->first_ep) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->first_ep_dnode_id) < 0) return -1;
  if (tDecodeCStrTo(decoder, pInfo->version) < 0) return -1;
  if (tDecodeFloat(decoder, &pInfo->master_uptime) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->monitor_interval) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->vgroups_total) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->vgroups_alive) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->vnodes_total) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->vnodes_alive) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->connections_total) < 0) return -1;

  int32_t dnodesSize = 0;
  int32_t mnodesSize = 0;
  if (tDecodeI32(decoder, &dnodesSize) < 0) return -1;
  if (tDecodeI32(decoder, &mnodesSize) < 0) return -1;

  pInfo->dnodes = taosArrayInit(dnodesSize, sizeof(SMonDnodeDesc));
  pInfo->mnodes = taosArrayInit(mnodesSize, sizeof(SMonMnodeDesc));
146
  if (pInfo->dnodes == NULL || pInfo->mnodes == NULL) return -1;
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

  for (int32_t i = 0; i < dnodesSize; ++i) {
    SMonDnodeDesc desc = {0};
    if (tDecodeI32(decoder, &desc.dnode_id) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.dnode_ep) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.status) < 0) return -1;
    taosArrayPush(pInfo->dnodes, &desc);
  }

  for (int32_t i = 0; i < mnodesSize; ++i) {
    SMonMnodeDesc desc = {0};
    if (tDecodeI32(decoder, &desc.mnode_id) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.mnode_ep) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.role) < 0) return -1;
    taosArrayPush(pInfo->mnodes, &desc);
  }
  return 0;
}

H
Hongze Cheng 已提交
166
int32_t tEncodeSMonVgroupInfo(SEncoder *encoder, const SMonVgroupInfo *pInfo) {
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->vgroups)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->vgroups); ++i) {
    SMonVgroupDesc *pDesc = taosArrayGet(pInfo->vgroups, i);
    if (tEncodeI32(encoder, pDesc->vgroup_id) < 0) return -1;
    if (tEncodeI32(encoder, pDesc->tables_num) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->status) < 0) return -1;
    for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
      SMonVnodeDesc *pVDesc = &pDesc->vnodes[j];
      if (tEncodeI32(encoder, pVDesc->dnode_id) < 0) return -1;
      if (tEncodeCStr(encoder, pVDesc->vnode_role) < 0) return -1;
    }
  }
  return 0;
}

H
Hongze Cheng 已提交
183
int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) {
184 185 186 187
  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc));
188
  if (pInfo->vgroups == NULL) return -1;
189 190 191 192 193 194 195 196

  for (int32_t i = 0; i < arraySize; ++i) {
    SMonVgroupDesc desc = {0};
    if (tDecodeI32(decoder, &desc.vgroup_id) < 0) return -1;
    if (tDecodeI32(decoder, &desc.tables_num) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.status) < 0) return -1;
    for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
197 198 199
      SMonVnodeDesc *pVDesc = &desc.vnodes[j];
      if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1;
      if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1;
200 201 202 203 204 205
    }
    taosArrayPush(pInfo->vgroups, &desc);
  }
  return 0;
}

H
Hongze Cheng 已提交
206
int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) {
207
  if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1;
208 209
  if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1;
210 211 212
  return 0;
}

H
Hongze Cheng 已提交
213
int32_t tDecodeSMonGrantInfo(SDecoder *decoder, SMonGrantInfo *pInfo) {
214
  if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1;
215 216
  if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1;
217 218 219 220
  return 0;
}

int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
H
Hongze Cheng 已提交
221 222
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
223 224 225 226 227 228

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1;
  if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1;
  if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
229
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
230 231 232
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
233
  tEncoderClear(&encoder);
234 235 236 237
  return tlen;
}

int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
H
Hongze Cheng 已提交
238 239
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
240 241 242 243 244 245

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1;
  if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1;
  if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
246
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
247 248
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
249
  tDecoderClear(&decoder);
250 251 252 253
  return 0;
}

void tFreeSMonMmInfo(SMonMmInfo *pInfo) {
254 255 256 257 258 259 260 261
  taosArrayDestroy(pInfo->log.logs);
  taosArrayDestroy(pInfo->cluster.mnodes);
  taosArrayDestroy(pInfo->cluster.dnodes);
  taosArrayDestroy(pInfo->vgroup.vgroups);
  pInfo->cluster.mnodes = NULL;
  pInfo->cluster.dnodes = NULL;
  pInfo->vgroup.vgroups = NULL;
  pInfo->log.logs = NULL;
262 263
}

H
Hongze Cheng 已提交
264
int32_t tEncodeSMonDiskDesc(SEncoder *encoder, const SMonDiskDesc *pDesc) {
265 266 267 268 269
  if (tEncodeCStr(encoder, pDesc->name) < 0) return -1;
  if (tEncodeI8(encoder, pDesc->level) < 0) return -1;
  if (tEncodeI64(encoder, pDesc->size.total) < 0) return -1;
  if (tEncodeI64(encoder, pDesc->size.used) < 0) return -1;
  if (tEncodeI64(encoder, pDesc->size.avail) < 0) return -1;
dengyihao's avatar
dengyihao 已提交
270
  return 0;
271 272
}

H
Hongze Cheng 已提交
273
static int32_t tDecodeSMonDiskDesc(SDecoder *decoder, SMonDiskDesc *pDesc) {
274 275 276 277 278 279 280 281
  if (tDecodeCStrTo(decoder, pDesc->name) < 0) return -1;
  if (tDecodeI8(decoder, &pDesc->level) < 0) return -1;
  if (tDecodeI64(decoder, &pDesc->size.total) < 0) return -1;
  if (tDecodeI64(decoder, &pDesc->size.used) < 0) return -1;
  if (tDecodeI64(decoder, &pDesc->size.avail) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
282
int32_t tEncodeSMonDiskInfo(SEncoder *encoder, const SMonDiskInfo *pInfo) {
283 284 285 286 287 288 289 290
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->datadirs)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->datadirs); ++i) {
    SMonDiskDesc *pDesc = taosArrayGet(pInfo->datadirs, i);
    if (tEncodeSMonDiskDesc(encoder, pDesc) < 0) return -1;
  }
  return 0;
}

H
Hongze Cheng 已提交
291
static int32_t tDecodeSMonDiskInfo(SDecoder *decoder, SMonDiskInfo *pInfo) {
292 293 294 295
  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc));
296
  if (pInfo->datadirs == NULL) return -1;
297 298 299 300 301 302 303 304 305 306

  for (int32_t i = 0; i < arraySize; ++i) {
    SMonDiskDesc desc = {0};
    if (tDecodeSMonDiskDesc(decoder, &desc) < 0) return -1;
    taosArrayPush(pInfo->datadirs, &desc);
  }

  return 0;
}

H
Hongze Cheng 已提交
307
int32_t tEncodeSVnodesStat(SEncoder *encoder, const SVnodesStat *pStat) {
308 309 310 311 312 313 314 315 316 317 318 319
  if (tEncodeI32(encoder, pStat->openVnodes) < 0) return -1;
  if (tEncodeI32(encoder, pStat->totalVnodes) < 0) return -1;
  if (tEncodeI32(encoder, pStat->masterNum) < 0) return -1;
  if (tEncodeI64(encoder, pStat->numOfSelectReqs) < 0) return -1;
  if (tEncodeI64(encoder, pStat->numOfInsertReqs) < 0) return -1;
  if (tEncodeI64(encoder, pStat->numOfInsertSuccessReqs) < 0) return -1;
  if (tEncodeI64(encoder, pStat->numOfBatchInsertReqs) < 0) return -1;
  if (tEncodeI64(encoder, pStat->numOfBatchInsertSuccessReqs) < 0) return -1;
  if (tEncodeI64(encoder, pStat->errors) < 0) return -1;
  return 0;
}

H
Hongze Cheng 已提交
320
static int32_t tDecodeSVnodesStat(SDecoder *decoder, SVnodesStat *pStat) {
321 322 323 324 325 326 327 328 329 330 331 332 333
  if (tDecodeI32(decoder, &pStat->openVnodes) < 0) return -1;
  if (tDecodeI32(decoder, &pStat->totalVnodes) < 0) return -1;
  if (tDecodeI32(decoder, &pStat->masterNum) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->numOfSelectReqs) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->numOfInsertReqs) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->numOfInsertSuccessReqs) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->numOfBatchInsertReqs) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->numOfBatchInsertSuccessReqs) < 0) return -1;
  if (tDecodeI64(decoder, &pStat->errors) < 0) return -1;
  return 0;
}

int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) {
H
Hongze Cheng 已提交
334 335
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
336 337 338 339 340

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonDiskInfo(&encoder, &pInfo->tfs) < 0) return -1;
  if (tEncodeSVnodesStat(&encoder, &pInfo->vstat) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
341
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
342 343 344
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
345
  tEncoderClear(&encoder);
346 347 348 349
  return tlen;
}

int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) {
H
Hongze Cheng 已提交
350 351
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
352 353 354 355 356

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonDiskInfo(&decoder, &pInfo->tfs) < 0) return -1;
  if (tDecodeSVnodesStat(&decoder, &pInfo->vstat) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
357
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
358 359
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
360
  tDecoderClear(&decoder);
361 362 363 364
  return 0;
}

void tFreeSMonVmInfo(SMonVmInfo *pInfo) {
365 366 367 368
  taosArrayDestroy(pInfo->log.logs);
  taosArrayDestroy(pInfo->tfs.datadirs);
  pInfo->log.logs = NULL;
  pInfo->tfs.datadirs = NULL;
369 370
}

371
int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) {
H
Hongze Cheng 已提交
372 373
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
374 375 376

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
377
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
378 379 380
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
381
  tEncoderClear(&encoder);
382 383 384 385
  return tlen;
}

int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) {
H
Hongze Cheng 已提交
386 387
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
388 389 390

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
391
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
392 393
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
394
  tDecoderClear(&decoder);
395 396 397 398
  return 0;
}

void tFreeSMonQmInfo(SMonQmInfo *pInfo) {
399 400
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
401 402
}

403
int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) {
H
Hongze Cheng 已提交
404 405
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
406 407 408

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
409
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
410 411 412
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
413
  tEncoderClear(&encoder);
414 415 416 417
  return tlen;
}

int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) {
H
Hongze Cheng 已提交
418 419
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
420 421 422

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
423
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
424 425
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
426
  tDecoderClear(&decoder);
427 428 429 430
  return 0;
}

void tFreeSMonSmInfo(SMonSmInfo *pInfo) {
431 432
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
433 434
}

435
int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) {
H
Hongze Cheng 已提交
436 437
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
438 439 440

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
441
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
442 443 444
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
445
  tEncoderClear(&encoder);
446 447 448 449
  return tlen;
}

int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) {
H
Hongze Cheng 已提交
450 451
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
452 453 454

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
455
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
456 457
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
458
  tDecoderClear(&decoder);
459 460 461 462
  return 0;
}

void tFreeSMonBmInfo(SMonBmInfo *pInfo) {
463 464
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
465 466 467
}

int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) {
H
Hongze Cheng 已提交
468 469
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
470 471 472 473 474 475

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI32(&encoder, taosArrayGetSize(pInfo->pVloads)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->pVloads); ++i) {
    SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i);
    if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1;
S
Shengliang Guan 已提交
476
    if (tEncodeI32(&encoder, pLoad->syncState) < 0) return -1;
477 478 479 480 481 482 483 484 485 486 487 488 489 490
    if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->compStorage) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->pointsWritten) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfSelectReqs) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfInsertReqs) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfInsertSuccessReqs) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfBatchInsertReqs) < 0) return -1;
    if (tEncodeI64(&encoder, pLoad->numOfBatchInsertSuccessReqs) < 0) return -1;
  }
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
491
  tEncoderClear(&encoder);
492 493 494 495
  return tlen;
}

int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) {
H
Hongze Cheng 已提交
496 497
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
498 499 500 501 502 503 504

  if (tStartDecode(&decoder) < 0) return -1;

  int32_t arraySize = 0;
  if (tDecodeI32(&decoder, &arraySize) < 0) return -1;

  pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad));
505
  if (pInfo->pVloads == NULL) return -1;
506 507 508 509

  for (int32_t i = 0; i < arraySize; ++i) {
    SVnodeLoad load = {0};
    if (tDecodeI32(&decoder, &load.vgId) < 0) return -1;
S
Shengliang Guan 已提交
510
    if (tDecodeI32(&decoder, &load.syncState) < 0) return -1;
511 512 513 514 515 516 517 518 519 520 521 522 523 524
    if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1;
    if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1;
    if (tDecodeI64(&decoder, &load.compStorage) < 0) return -1;
    if (tDecodeI64(&decoder, &load.pointsWritten) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfSelectReqs) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfInsertReqs) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfInsertSuccessReqs) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfBatchInsertReqs) < 0) return -1;
    if (tDecodeI64(&decoder, &load.numOfBatchInsertSuccessReqs) < 0) return -1;
    taosArrayPush(pInfo->pVloads, &load);
  }

  tEndDecode(&decoder);
H
Hongze Cheng 已提交
525
  tDecoderClear(&decoder);
526 527 528 529 530 531
  return 0;
}

void tFreeSMonVloadInfo(SMonVloadInfo *pInfo) {
  taosArrayDestroy(pInfo->pVloads);
  pInfo->pVloads = NULL;
dengyihao's avatar
dengyihao 已提交
532
}
S
Shengliang Guan 已提交
533 534

int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) {
H
Hongze Cheng 已提交
535 536
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
537 538 539 540 541 542 543

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI8(&encoder, pInfo->isMnode) < 0) return -1;
  if (tEncodeI32(&encoder, pInfo->load.syncState) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
544
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
545 546 547 548
  return tlen;
}

int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) {
H
Hongze Cheng 已提交
549 550
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
551 552 553 554 555 556

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI8(&decoder, &pInfo->isMnode) < 0) return -1;
  if (tDecodeI32(&decoder, &pInfo->load.syncState) < 0) return -1;
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
557
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
558
  return 0;
D
dapan1121 已提交
559 560 561 562 563 564 565 566 567 568 569 570 571
}


int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfProcessedQuery) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfProcessedCQuery) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfProcessedFetch) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfProcessedDrop) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfProcessedHb) < 0) return -1;
D
dapan1121 已提交
572
  if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
  if (tEncodeI64(&encoder, pInfo->cacheDataSize) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfQueryInQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->numOfFetchInQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->timeInQueryQueue) < 0) return -1;
  if (tEncodeI64(&encoder, pInfo->timeInFetchQueue) < 0) return -1;
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
  tEncoderClear(&encoder);
  return tlen;
}

int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedQuery) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedCQuery) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedFetch) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedDrop) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedHb) < 0) return -1;
D
dapan1121 已提交
595
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
596 597 598 599 600 601 602 603 604 605 606 607
  if (tDecodeI64(&decoder, &pInfo->cacheDataSize) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfQueryInQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->numOfFetchInQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->timeInQueryQueue) < 0) return -1;
  if (tDecodeI64(&decoder, &pInfo->timeInFetchQueue) < 0) return -1;
  tEndDecode(&decoder);

  tDecoderClear(&decoder);
  return 0;
}