monMsg.c 25.2 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
  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;
105 106 107
  if (tEncodeI32(encoder, pInfo->dbs_total) < 0) return -1;
  if (tEncodeI32(encoder, pInfo->stbs_total) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->tbs_total) < 0) return -1;
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  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 已提交
130
int32_t tDecodeSMonClusterInfo(SDecoder *decoder, SMonClusterInfo *pInfo) {
131 132 133 134 135
  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;
136 137 138
  if (tDecodeI32(decoder, &pInfo->dbs_total) < 0) return -1;
  if (tDecodeI32(decoder, &pInfo->stbs_total) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->tbs_total) < 0) return -1;
139 140 141 142 143 144 145 146 147 148 149 150 151
  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));
152
  if (pInfo->dnodes == NULL || pInfo->mnodes == NULL) return -1;
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

  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 已提交
172
int32_t tEncodeSMonVgroupInfo(SEncoder *encoder, const SMonVgroupInfo *pInfo) {
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  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 已提交
189
int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) {
190 191 192 193
  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc));
194
  if (pInfo->vgroups == NULL) return -1;
195 196 197 198 199 200 201 202

  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) {
203 204 205
      SMonVnodeDesc *pVDesc = &desc.vnodes[j];
      if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1;
      if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1;
206 207 208 209 210 211
    }
    taosArrayPush(pInfo->vgroups, &desc);
  }
  return 0;
}

S
Shengliang Guan 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
int32_t tEncodeSMonStbInfo(SEncoder *encoder, const SMonStbInfo *pInfo) {
  if (tEncodeI32(encoder, taosArrayGetSize(pInfo->stbs)) < 0) return -1;
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) {
    SMonStbDesc *pDesc = taosArrayGet(pInfo->stbs, i);
    if (tEncodeCStr(encoder, pDesc->stb_name) < 0) return -1;
    if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1;
  }
  return 0;
}

int32_t tDecodeSMonStbInfo(SDecoder *decoder, SMonStbInfo *pInfo) {
  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->stbs = taosArrayInit(arraySize, sizeof(SMonStbDesc));
  if (pInfo->stbs == NULL) return -1;

  for (int32_t i = 0; i < arraySize; ++i) {
    SMonStbDesc desc = {0};
    if (tDecodeCStrTo(decoder, desc.stb_name) < 0) return -1;
    if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1;
    taosArrayPush(pInfo->stbs, &desc);
  }
  return 0;
}

H
Hongze Cheng 已提交
238
int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) {
239
  if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1;
240 241
  if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1;
  if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1;
242 243 244
  return 0;
}

H
Hongze Cheng 已提交
245
int32_t tDecodeSMonGrantInfo(SDecoder *decoder, SMonGrantInfo *pInfo) {
246
  if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1;
247 248
  if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1;
  if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1;
249 250 251 252
  return 0;
}

int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
H
Hongze Cheng 已提交
253 254
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
255 256 257 258

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1;
  if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1;
S
Shengliang Guan 已提交
259
  if (tEncodeSMonStbInfo(&encoder, &pInfo->stb) < 0) return -1;
260 261
  if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
262
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
263 264 265
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
266
  tEncoderClear(&encoder);
267 268 269 270
  return tlen;
}

int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) {
H
Hongze Cheng 已提交
271 272
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
273 274 275 276

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1;
  if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1;
S
Shengliang Guan 已提交
277
  if (tDecodeSMonStbInfo(&decoder, &pInfo->stb) < 0) return -1;
278 279
  if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
280
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
281 282
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
283
  tDecoderClear(&decoder);
284 285 286 287
  return 0;
}

void tFreeSMonMmInfo(SMonMmInfo *pInfo) {
288 289 290 291
  taosArrayDestroy(pInfo->log.logs);
  taosArrayDestroy(pInfo->cluster.mnodes);
  taosArrayDestroy(pInfo->cluster.dnodes);
  taosArrayDestroy(pInfo->vgroup.vgroups);
S
Shengliang Guan 已提交
292
  taosArrayDestroy(pInfo->stb.stbs);
293 294 295
  pInfo->cluster.mnodes = NULL;
  pInfo->cluster.dnodes = NULL;
  pInfo->vgroup.vgroups = NULL;
S
Shengliang Guan 已提交
296
  pInfo->stb.stbs = NULL;
297
  pInfo->log.logs = NULL;
298 299
}

H
Hongze Cheng 已提交
300
int32_t tEncodeSMonDiskDesc(SEncoder *encoder, const SMonDiskDesc *pDesc) {
301 302 303 304 305
  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 已提交
306
  return 0;
307 308
}

H
Hongze Cheng 已提交
309
static int32_t tDecodeSMonDiskDesc(SDecoder *decoder, SMonDiskDesc *pDesc) {
310 311 312 313 314 315 316 317
  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 已提交
318
int32_t tEncodeSMonDiskInfo(SEncoder *encoder, const SMonDiskInfo *pInfo) {
319 320 321 322 323 324 325 326
  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 已提交
327
static int32_t tDecodeSMonDiskInfo(SDecoder *decoder, SMonDiskInfo *pInfo) {
328 329 330 331
  int32_t arraySize = 0;
  if (tDecodeI32(decoder, &arraySize) < 0) return -1;

  pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc));
332
  if (pInfo->datadirs == NULL) return -1;
333 334 335 336 337 338 339 340 341 342

  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 已提交
343
int32_t tEncodeSVnodesStat(SEncoder *encoder, const SVnodesStat *pStat) {
344 345 346 347 348 349 350 351 352 353 354 355
  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 已提交
356
static int32_t tDecodeSVnodesStat(SDecoder *decoder, SVnodesStat *pStat) {
357 358 359 360 361 362 363 364 365 366 367 368 369
  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 已提交
370 371
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
372 373 374 375 376

  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;
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 tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) {
H
Hongze Cheng 已提交
386 387
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
388 389 390 391 392

  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;
393
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
394 395
  tEndDecode(&decoder);

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

void tFreeSMonVmInfo(SMonVmInfo *pInfo) {
401 402 403 404
  taosArrayDestroy(pInfo->log.logs);
  taosArrayDestroy(pInfo->tfs.datadirs);
  pInfo->log.logs = NULL;
  pInfo->tfs.datadirs = NULL;
405 406
}

407
int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) {
H
Hongze Cheng 已提交
408 409
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
410 411 412

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
413
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
414 415 416
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
417
  tEncoderClear(&encoder);
418 419 420 421
  return tlen;
}

int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) {
H
Hongze Cheng 已提交
422 423
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
424 425 426

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
427
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
428 429
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
430
  tDecoderClear(&decoder);
431 432 433 434
  return 0;
}

void tFreeSMonQmInfo(SMonQmInfo *pInfo) {
435 436
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
437 438
}

439
int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) {
H
Hongze Cheng 已提交
440 441
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
442 443 444

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
445
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
446 447 448
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
449
  tEncoderClear(&encoder);
450 451 452 453
  return tlen;
}

int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) {
H
Hongze Cheng 已提交
454 455
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
456 457 458

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
459
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
460 461
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
462
  tDecoderClear(&decoder);
463 464 465 466
  return 0;
}

void tFreeSMonSmInfo(SMonSmInfo *pInfo) {
467 468
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
469 470
}

471
int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) {
H
Hongze Cheng 已提交
472 473
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
474 475 476

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1;
477
  if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1;
478 479 480
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
481
  tEncoderClear(&encoder);
482 483 484 485
  return tlen;
}

int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) {
H
Hongze Cheng 已提交
486 487
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
488 489 490

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1;
491
  if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1;
492 493
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
494
  tDecoderClear(&decoder);
495 496 497 498
  return 0;
}

void tFreeSMonBmInfo(SMonBmInfo *pInfo) {
499 500
  taosArrayDestroy(pInfo->log.logs);
  pInfo->log.logs = NULL;
501 502 503
}

int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) {
H
Hongze Cheng 已提交
504 505
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
506 507 508 509 510 511

  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;
512 513
    if (tEncodeI8(&encoder, pLoad->syncState) < 0) return -1;
    if (tEncodeI8(&encoder, pLoad->syncRestore) < 0) return -1;
514
    if (tEncodeI64(&encoder, pLoad->cacheUsage) < 0) return -1;
515 516 517 518 519 520 521 522 523 524 525 526 527 528
    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 已提交
529
  tEncoderClear(&encoder);
530 531 532 533
  return tlen;
}

int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) {
H
Hongze Cheng 已提交
534 535
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
536 537 538 539 540 541 542

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

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

  pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad));
543
  if (pInfo->pVloads == NULL) return -1;
544 545 546 547

  for (int32_t i = 0; i < arraySize; ++i) {
    SVnodeLoad load = {0};
    if (tDecodeI32(&decoder, &load.vgId) < 0) return -1;
548 549
    if (tDecodeI8(&decoder, &load.syncState) < 0) return -1;
    if (tDecodeI8(&decoder, &load.syncRestore) < 0) return -1;
550
    if (tDecodeI64(&decoder, &load.cacheUsage) < 0) return -1;
551 552 553 554 555 556 557 558 559 560 561 562 563 564
    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 已提交
565
  tDecoderClear(&decoder);
566 567 568 569 570 571
  return 0;
}

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

int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) {
H
Hongze Cheng 已提交
575 576
  SEncoder encoder = {0};
  tEncoderInit(&encoder, buf, bufLen);
S
Shengliang Guan 已提交
577 578 579

  if (tStartEncode(&encoder) < 0) return -1;
  if (tEncodeI8(&encoder, pInfo->isMnode) < 0) return -1;
580 581
  if (tEncodeI8(&encoder, pInfo->load.syncState) < 0) return -1;
  if (tEncodeI8(&encoder, pInfo->load.syncRestore) < 0) return -1;
S
Shengliang Guan 已提交
582 583 584
  tEndEncode(&encoder);

  int32_t tlen = encoder.pos;
H
Hongze Cheng 已提交
585
  tEncoderClear(&encoder);
S
Shengliang Guan 已提交
586 587 588 589
  return tlen;
}

int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) {
H
Hongze Cheng 已提交
590 591
  SDecoder decoder = {0};
  tDecoderInit(&decoder, buf, bufLen);
S
Shengliang Guan 已提交
592 593 594

  if (tStartDecode(&decoder) < 0) return -1;
  if (tDecodeI8(&decoder, &pInfo->isMnode) < 0) return -1;
595 596
  if (tDecodeI8(&decoder, &pInfo->load.syncState) < 0) return -1;
  if (tDecodeI8(&decoder, &pInfo->load.syncRestore) < 0) return -1;
S
Shengliang Guan 已提交
597 598
  tEndDecode(&decoder);

H
Hongze Cheng 已提交
599
  tDecoderClear(&decoder);
S
Shengliang Guan 已提交
600
  return 0;
D
dapan1121 已提交
601 602 603 604 605 606 607 608 609 610 611 612
}

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 已提交
613
  if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  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 已提交
636
  if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1;
D
dapan1121 已提交
637 638 639 640 641 642 643 644 645 646
  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;
}