dndMonitor.c 3.6 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
shm  
Shengliang Guan 已提交
17 18
#include "dndInt.h"

S
Shengliang Guan 已提交
19
static int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) {
S
Shengliang Guan 已提交
20 21 22 23 24
  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;

S
Shengliang Guan 已提交
25 26 27 28 29 30
  SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES);
  if (pWrapper != NULL) {
    vmMonitorTfsInfo(pWrapper, pInfo);
    dndReleaseWrapper(pWrapper);
  }
  return 0;
S
Shengliang Guan 已提交
31
}
S
Shengliang Guan 已提交
32 33 34

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

static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
S
shm  
Shengliang Guan 已提交
41
  pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f);
S
Shengliang Guan 已提交
42
  taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
S
Shengliang Guan 已提交
43
  taosGetCpuCores(&pInfo->cpu_cores);
S
Shengliang Guan 已提交
44 45 46 47 48 49 50 51 52
  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;
  taosGetCardInfo(&pInfo->net_in, &pInfo->net_out);
  taosGetProcIO(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);

S
Shengliang Guan 已提交
53 54 55 56 57 58 59 60 61 62 63
  SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES);
  if (pWrapper != NULL) {
    vmMonitorVnodeReqs(pWrapper, pInfo);
    dndReleaseWrapper(pWrapper);
  }

  pWrapper = dndAcquireWrapper(pDnode, MNODE);
  if (pWrapper != NULL) {
    pInfo->has_mnode = pWrapper->required;
    dndReleaseWrapper(pWrapper);
  }
S
Shengliang Guan 已提交
64 65 66 67
}

void dndSendMonitorReport(SDnode *pDnode) {
  if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
S
shm  
Shengliang Guan 已提交
68
  dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort);
S
Shengliang Guan 已提交
69 70 71 72 73 74 75

  SMonInfo *pMonitor = monCreateMonitorInfo();
  if (pMonitor == NULL) return;

  SMonBasicInfo basicInfo = {0};
  dndGetMonitorBasicInfo(pDnode, &basicInfo);
  monSetBasicInfo(pMonitor, &basicInfo);
S
shm  
Shengliang Guan 已提交
76

S
Shengliang Guan 已提交
77 78 79
  SMonClusterInfo clusterInfo = {0};
  SMonVgroupInfo  vgroupInfo = {0};
  SMonGrantInfo   grantInfo = {0};
S
Shengliang Guan 已提交
80 81 82 83 84 85 86 87 88

  SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE);
  if (pWrapper != NULL) {
    if (mmMonitorMnodeInfo(pWrapper, &clusterInfo, &vgroupInfo, &grantInfo) == 0) {
      monSetClusterInfo(pMonitor, &clusterInfo);
      monSetVgroupInfo(pMonitor, &vgroupInfo);
      monSetGrantInfo(pMonitor, &grantInfo);
    }
    dndReleaseWrapper(pWrapper);
S
Shengliang Guan 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  }

  SMonDnodeInfo dnodeInfo = {0};
  dndGetMonitorDnodeInfo(pDnode, &dnodeInfo);
  monSetDnodeInfo(pMonitor, &dnodeInfo);

  SMonDiskInfo diskInfo = {0};
  if (dndGetMonitorDiskInfo(pDnode, &diskInfo) == 0) {
    monSetDiskInfo(pMonitor, &diskInfo);
  }

  taosArrayDestroy(clusterInfo.dnodes);
  taosArrayDestroy(clusterInfo.mnodes);
  taosArrayDestroy(vgroupInfo.vgroups);
  taosArrayDestroy(diskInfo.datadirs);
S
shm  
Shengliang Guan 已提交
104

S
Shengliang Guan 已提交
105 106 107
  monSendReport(pMonitor);
  monCleanupMonitorInfo(pMonitor);
}