dmUtil.c 3.1 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
const char *dmNodeLogName(EDndNodeType ntype) {
  switch (ntype) {
    case VNODE:
      return "vnode";
    case QNODE:
      return "qnode";
    case SNODE:
      return "snode";
    case MNODE:
      return "mnode";
    case BNODE:
      return "bnode";
    default:
      return "taosd";
S
Shengliang Guan 已提交
46 47 48
  }
}

S
Shengliang 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62
const char *dmNodeProcName(EDndNodeType ntype) {
  switch (ntype) {
    case VNODE:
      return "taosv";
    case QNODE:
      return "taosq";
    case SNODE:
      return "taoss";
    case MNODE:
      return "taosm";
    case BNODE:
      return "taosb";
    default:
      return "taosd";
S
Shengliang Guan 已提交
63 64 65
  }
}

S
Shengliang 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
const char *dmNodeName(EDndNodeType ntype) {
  switch (ntype) {
    case VNODE:
      return "vnode";
    case QNODE:
      return "qnode";
    case SNODE:
      return "snode";
    case MNODE:
      return "mnode";
    case BNODE:
      return "bnode";
    default:
      return "dnode";
  }
}

S
Shengliang 已提交
83 84 85 86 87 88 89 90 91 92
const char *dmEventStr(EDndEvent ev) {
  switch (ev) {
    case DND_EVENT_START:
      return "start";
    case DND_EVENT_STOP:
      return "stop";
    case DND_EVENT_CHILD:
      return "child";
    default:
      return "UNKNOWN";
S
Shengliang Guan 已提交
93 94 95
  }
}

S
Shengliang 已提交
96 97 98 99 100 101 102 103 104 105 106 107
const char *dmProcStr(EDndProcType etype) {
  switch (etype) {
    case DND_PROC_SINGLE:
      return "start";
    case DND_PROC_CHILD:
      return "stop";
    case DND_PROC_PARENT:
      return "child";
    case DND_PROC_TEST:
      return "test";
    default:
      return "UNKNOWN";
108
  }
109 110
}

S
Shengliang 已提交
111
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId) {
S
Shengliang 已提交
112 113
  SMgmtHandle handle = {
      .msgType = msgType,
S
Shengliang 已提交
114
      .msgFp = (NodeMsgFp)nodeMsgFp,
S
Shengliang 已提交
115 116
      .needCheckVgId = needCheckVgId,
  };
S
Shengliang Guan 已提交
117

S
Shengliang 已提交
118
  return taosArrayPush(pArray, &handle);
S
Shengliang Guan 已提交
119
}
S
Shengliang Guan 已提交
120

S
Shengliang 已提交
121
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
S
Shengliang Guan 已提交
122 123 124 125 126 127 128 129 130 131 132
  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);
}