dmMonitor.c 4.3 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/*
 * 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 "dmMgmt.h"
#include "dmNodes.h"

static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
  pInfo->protocol = 1;
  pInfo->dnode_id = pDnode->data.dnodeId;
  pInfo->cluster_id = pDnode->data.clusterId;
  tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
}

static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
  pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f);
  pInfo->has_mnode = pDnode->wrappers[MNODE].required;
  pInfo->has_qnode = pDnode->wrappers[QNODE].required;
  pInfo->has_snode = pDnode->wrappers[SNODE].required;
  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 dmGetDmMonitorInfo(SDnode *pDnode) {
  SMonDmInfo dmInfo = {0};
  dmGetMonitorBasicInfo(pDnode, &dmInfo.basic);
  dmGetMonitorDnodeInfo(pDnode, &dmInfo.dnode);
  dmGetMonitorSystemInfo(&dmInfo.sys);
  monSetDmInfo(&dmInfo);
}

static void dmGetMmMonitorInfo(SDnode *pDnode) {
47 48 49
  SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
    SMonMmInfo mmInfo = {0};
50
    if (pWrapper->pMgmt != NULL) {
S
Shengliang Guan 已提交
51 52
      mmGetMonitorInfo(pWrapper->pMgmt, &mmInfo);
    }
53 54 55
    dmReleaseWrapper(pWrapper);
    monSetMmInfo(&mmInfo);
    tFreeSMonMmInfo(&mmInfo);
S
Shengliang Guan 已提交
56 57 58 59
  }
}

static void dmGetVmMonitorInfo(SDnode *pDnode) {
60 61 62
  SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
    SMonVmInfo vmInfo = {0};
63
    if (pWrapper->pMgmt != NULL) {
S
Shengliang Guan 已提交
64 65
      vmGetMonitorInfo(pWrapper->pMgmt, &vmInfo);
    }
66 67 68
    dmReleaseWrapper(pWrapper);
    monSetVmInfo(&vmInfo);
    tFreeSMonVmInfo(&vmInfo);
S
Shengliang Guan 已提交
69 70 71 72
  }
}

static void dmGetQmMonitorInfo(SDnode *pDnode) {
73 74 75
  SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
    SMonQmInfo qmInfo = {0};
76
    if (pWrapper->pMgmt != NULL) {
S
Shengliang Guan 已提交
77 78
      qmGetMonitorInfo(pWrapper->pMgmt, &qmInfo);
    }
79 80 81
    dmReleaseWrapper(pWrapper);
    monSetQmInfo(&qmInfo);
    tFreeSMonQmInfo(&qmInfo);
S
Shengliang Guan 已提交
82 83 84 85
  }
}

static void dmGetSmMonitorInfo(SDnode *pDnode) {
86 87 88
  SMgmtWrapper *pWrapper = &pDnode->wrappers[SNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
    SMonSmInfo smInfo = {0};
89
    if (pWrapper->pMgmt != NULL) {
S
Shengliang Guan 已提交
90 91
      smGetMonitorInfo(pWrapper->pMgmt, &smInfo);
    }
92 93 94
    dmReleaseWrapper(pWrapper);
    monSetSmInfo(&smInfo);
    tFreeSMonSmInfo(&smInfo);
S
Shengliang Guan 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
  }
}

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

  SDnode *pDnode = dmInstance();
  dmGetDmMonitorInfo(pDnode);
  dmGetMmMonitorInfo(pDnode);
  dmGetVmMonitorInfo(pDnode);
  dmGetQmMonitorInfo(pDnode);
  dmGetSmMonitorInfo(pDnode);
  monSendReport();
}

void dmGetVnodeLoads(SMonVloadInfo *pInfo) {
  SDnode       *pDnode = dmInstance();
113 114
  SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
115
    if (pWrapper->pMgmt != NULL) {
C
Cary Xu 已提交
116
      vmGetVnodeLoads(pWrapper->pMgmt, pInfo, false);
S
Shengliang Guan 已提交
117
    }
118
    dmReleaseWrapper(pWrapper);
S
Shengliang Guan 已提交
119 120 121 122 123
  }
}

void dmGetMnodeLoads(SMonMloadInfo *pInfo) {
  SDnode       *pDnode = dmInstance();
124
  SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE];
S
Shengliang Guan 已提交
125
  if (dmMarkWrapper(pWrapper) == 0) {
126
    if (pWrapper->pMgmt != NULL) {
S
Shengliang Guan 已提交
127 128 129
      mmGetMnodeLoads(pWrapper->pMgmt, pInfo);
    }
    dmReleaseWrapper(pWrapper);
S
Shengliang Guan 已提交
130 131
  }
}
D
dapan1121 已提交
132 133 134 135 136

void dmGetQnodeLoads(SQnodeLoad *pInfo) {
  SDnode       *pDnode = dmInstance();
  SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE];
  if (dmMarkWrapper(pWrapper) == 0) {
137
    if (pWrapper->pMgmt != NULL) {
D
dapan1121 已提交
138 139 140 141 142
      qmGetQnodeLoads(pWrapper->pMgmt, pInfo);
    }
    dmReleaseWrapper(pWrapper);
  }
}