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

19 20 21 22 23 24 25 26 27 28 29 30
#define dmSendLocalRecv(pMgmt, mtype, func, pInfo)           \
  if (!tsMultiProcess) {                                     \
    SRpcMsg rsp = {0};                                       \
    SRpcMsg req = {.msgType = mtype};                        \
    SEpSet  epset = {.inUse = 0, .numOfEps = 1};             \
    tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); \
    epset.eps[0].port = tsServerPort;                        \
    rpcSendRecv(pMgmt->msgCb.clientRpc, &epset, &req, &rsp); \
    if (rsp.code == 0 && rsp.contLen > 0) {                  \
      func(rsp.pCont, rsp.contLen, pInfo);                   \
    }                                                        \
    rpcFreeCont(rsp.pCont);                                  \
S
Shengliang Guan 已提交
31 32 33 34
  }

static void dmGetMonitorBasicInfo(SDnodeMgmt *pMgmt, SMonBasicInfo *pInfo) {
  pInfo->protocol = 1;
S
Shengliang Guan 已提交
35 36
  pInfo->dnode_id = pMgmt->pData->dnodeId;
  pInfo->cluster_id = pMgmt->pData->clusterId;
S
Shengliang Guan 已提交
37 38 39 40
  tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
}

static void dmGetMonitorDnodeInfo(SDnodeMgmt *pMgmt, SMonDnodeInfo *pInfo) {
S
Shengliang Guan 已提交
41
  pInfo->uptime = (taosGetTimestampMs() - pMgmt->pData->rebootTime) / (86400000.0f);
42 43 44 45
  pInfo->has_mnode = (*pMgmt->isNodeRequiredFp)(MNODE);
  pInfo->has_qnode = (*pMgmt->isNodeRequiredFp)(QNODE);
  pInfo->has_snode = (*pMgmt->isNodeRequiredFp)(SNODE);
  pInfo->has_bnode = (*pMgmt->isNodeRequiredFp)(BNODE);
S
Shengliang Guan 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name));
  pInfo->logdir.size = tsLogSpace.size;
  tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name));
  pInfo->tempdir.size = tsTempSpace.size;
}

static void dmGetMonitorInfo(SDnodeMgmt *pMgmt, SMonDmInfo *pInfo) {
  dmGetMonitorBasicInfo(pMgmt, &pInfo->basic);
  dmGetMonitorDnodeInfo(pMgmt, &pInfo->dnode);
  dmGetMonitorSystemInfo(&pInfo->sys);
}

void dmSendMonitorReport(SDnodeMgmt *pMgmt) {
  if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
  dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort);

  SMonDmInfo dmInfo = {0};
  SMonMmInfo mmInfo = {0};
  SMonVmInfo vmInfo = {0};
  SMonQmInfo qmInfo = {0};
  SMonSmInfo smInfo = {0};
  SMonBmInfo bmInfo = {0};

  dmGetMonitorInfo(pMgmt, &dmInfo);
  dmSendLocalRecv(pMgmt, TDMT_MON_VM_INFO, tDeserializeSMonVmInfo, &vmInfo);
  if (dmInfo.dnode.has_mnode) {
    dmSendLocalRecv(pMgmt, TDMT_MON_MM_INFO, tDeserializeSMonMmInfo, &mmInfo);
  }
  if (dmInfo.dnode.has_qnode) {
    dmSendLocalRecv(pMgmt, TDMT_MON_QM_INFO, tDeserializeSMonQmInfo, &qmInfo);
  }
  if (dmInfo.dnode.has_snode) {
    dmSendLocalRecv(pMgmt, TDMT_MON_SM_INFO, tDeserializeSMonSmInfo, &smInfo);
  }
  if (dmInfo.dnode.has_bnode) {
    dmSendLocalRecv(pMgmt, TDMT_MON_BM_INFO, tDeserializeSMonBmInfo, &bmInfo);
  }

  monSetDmInfo(&dmInfo);
  monSetMmInfo(&mmInfo);
  monSetVmInfo(&vmInfo);
  monSetQmInfo(&qmInfo);
  monSetSmInfo(&smInfo);
  monSetBmInfo(&bmInfo);
  tFreeSMonMmInfo(&mmInfo);
  tFreeSMonVmInfo(&vmInfo);
  tFreeSMonQmInfo(&qmInfo);
  tFreeSMonSmInfo(&smInfo);
  tFreeSMonBmInfo(&bmInfo);
  monSendReport();
}

void dmGetVnodeLoads(SDnodeMgmt *pMgmt, SMonVloadInfo *pInfo) {
  dmSendLocalRecv(pMgmt, TDMT_MON_VM_LOAD, tDeserializeSMonVloadInfo, pInfo);
}

void dmGetMnodeLoads(SDnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
  dmSendLocalRecv(pMgmt, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo);
}