dmUtil.c 2.0 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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
S
Shengliang 已提交
17
#include "dmUtil.h"
S
Shengliang Guan 已提交
18

S
Shengliang 已提交
19 20 21 22 23 24 25 26 27 28
const char *dmStatStr(EDndRunStatus stype) {
  switch (stype) {
    case DND_STAT_INIT:
      return "init";
    case DND_STAT_RUNNING:
      return "running";
    case DND_STAT_STOPPED:
      return "stopped";
    default:
      return "UNKNOWN";
S
Shengliang Guan 已提交
29 30 31
  }
}

S
Shengliang 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
const char *dmNodeName(EDndNodeType ntype) {
  switch (ntype) {
    case VNODE:
      return "vnode";
    case QNODE:
      return "qnode";
    case SNODE:
      return "snode";
    case MNODE:
      return "mnode";
    default:
      return "dnode";
  }
}

S
Shengliang 已提交
47
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId) {
S
Shengliang 已提交
48 49
  SMgmtHandle handle = {
      .msgType = msgType,
S
Shengliang 已提交
50
      .msgFp = (NodeMsgFp)nodeMsgFp,
S
Shengliang 已提交
51 52
      .needCheckVgId = needCheckVgId,
  };
S
Shengliang Guan 已提交
53

S
Shengliang 已提交
54
  return taosArrayPush(pArray, &handle);
S
Shengliang Guan 已提交
55
}
S
Shengliang Guan 已提交
56

S
Shengliang 已提交
57
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
S
Shengliang Guan 已提交
58 59 60 61 62 63 64 65 66 67 68
  taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
  taosGetCpuCores(&pInfo->cpu_cores);
  taosGetProcMemory(&pInfo->mem_engine);
  taosGetSysMemory(&pInfo->mem_system);
  pInfo->mem_total = tsTotalMemoryKB;
  pInfo->disk_engine = 0;
  pInfo->disk_used = tsDataSpace.size.used;
  pInfo->disk_total = tsDataSpace.size.total;
  taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
  taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
}