monitor.h 3.8 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 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/*
 * 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/>.
 */

#ifndef _TD_MONITOR_H_
#define _TD_MONITOR_H_

#include "tarray.h"
#include "tdef.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
} SMonBasicInfo;

typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
  char    status[8];
} SMonDnodeDesc;

typedef struct {
  int32_t mnode_id;
  char    mnode_ep[TSDB_EP_LEN];
  char    role[8];
} SMonMnodeDesc;

typedef struct {
  char    first_ep[TSDB_EP_LEN];
  int32_t first_ep_dnode_id;
  char    version[12];
  float   master_uptime;     // day
  int32_t monitor_interval;  // sec
  int32_t vgroups_total;
  int32_t vgroups_alive;
  int32_t vnodes_total;
  int32_t vnodes_alive;
  int32_t connections_total;
  SArray *dnodes;  // array of SMonDnodeDesc
  SArray *mnodes;  // array of SMonMnodeDesc
} SMonClusterInfo;

typedef struct {
  float   uptime;  // day
  float   cpu_engine;
  float   cpu_system;
  float   cpu_cores;
  float   mem_engine;     // MB
  float   mem_system;     // MB
  float   mem_total;      // MB
  float   disk_engine;    // GB
  float   disk_used;      // GB
  float   disk_total;     // GB
  float   net_in;         // Kb/s
  float   net_out;        // Kb/s
  float   io_read;        // Mb/s
  float   io_write;       // Mb/s
  float   io_read_disk;   // Mb/s
  float   io_write_disk;  // Mb/s
  int32_t req_select;
  float   req_select_rate;
  int32_t req_insert;
  int32_t req_insert_success;
  float   req_insert_rate;
  int32_t req_insert_batch;
  int32_t req_insert_batch_success;
  float   req_insert_batch_rate;
  int32_t errors;
  int32_t vnodes_num;
  int32_t masters;
  int32_t has_mnode;
} SMonDnodeInfo;

typedef struct {
  char      name[TSDB_FILENAME_LEN];
  int32_t   level;
  SDiskSize size;
} SMonDiskDesc;

typedef struct {
  SArray *disks;  // array of SMonDiskDesc
} SMonDiskInfo;

typedef struct {
  int32_t dnode_id;
  int8_t  vnode_online;
  char    vnode_role[8];
} SMonVnodeDesc;

typedef struct {
  int32_t       vgroup_id;
  SMonVnodeDesc vnodes[TSDB_MAX_REPLICA];
} SMonVgroupDesc;

typedef struct {
  char    database_name[TSDB_DB_NAME_LEN];
  int32_t tables_num;
  int8_t  status;
  SArray *vgroups;  // array of SMonVgroupDesc
} SMonVgroupInfo;

typedef struct {
  int64_t ts;
  int8_t  level;
  char    content[1024];
} SMonLogItem;

typedef struct {
  int32_t expire_time;
  int32_t timeseries_used;
  int32_t timeseries_total;
} SMonGrantInfo;

S
monitor  
Shengliang Guan 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
typedef struct SMonInfo SMonInfo;

typedef struct {
  const char *server;
  uint16_t    port;
  int32_t     maxLogs;
} SMonCfg;

int32_t monInit(const SMonCfg *pCfg);
void    monCleanup();
void    monAddLogItem(SMonLogItem *pItem);

SMonInfo *monCreateMonitorInfo();
void      monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo);
void      monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo);
void      monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo);
void      monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo);
void      monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo);
void      monSetGrantInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo);
void      monSendReport(SMonInfo *pMonitor);
void      monCleanupMonitorInfo(SMonInfo *pMonitor);

S
Shengliang Guan 已提交
151 152 153 154 155
#ifdef __cplusplus
}
#endif

#endif /*_TD_MONITOR_H_*/