monitor.h 5.7 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
/*
 * 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"
21
#include "tlog.h"
22
#include "tmsg.h"
S
Shengliang Guan 已提交
23 24 25 26 27

#ifdef __cplusplus
extern "C" {
#endif

S
monitor  
Shengliang Guan 已提交
28 29 30 31 32
#define MON_STATUS_LEN 8
#define MON_ROLE_LEN   9
#define MON_VER_LEN    12
#define MON_LOG_LEN    1024

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
typedef struct {
  int64_t   ts;
  ELogLevel level;
  char      content[MON_LOG_LEN];
} SMonLogItem;

typedef struct {
  SArray *logs;  // array of SMonLogItem
  int32_t numOfErrorLogs;
  int32_t numOfInfoLogs;
  int32_t numOfDebugLogs;
  int32_t numOfTraceLogs;
} SMonLogs;

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

typedef struct {
  double  cpu_engine;
  double  cpu_system;
  float   cpu_cores;
  int64_t mem_engine;     // KB
  int64_t mem_system;     // KB
  int64_t mem_total;      // KB
  int64_t disk_engine;    // Byte
  int64_t disk_used;      // Byte
  int64_t disk_total;     // Byte
  int64_t net_in;         // bytes
  int64_t net_out;        // bytes
  int64_t io_read;        // bytes
  int64_t io_write;       // bytes
  int64_t io_read_disk;   // bytes
  int64_t io_write_disk;  // bytes
} SMonSysInfo;

S
Shengliang Guan 已提交
71 72 73
typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
74 75
  int64_t cluster_id;
  int32_t protocol;
S
Shengliang Guan 已提交
76 77
} SMonBasicInfo;

78 79 80
typedef struct {
  float        uptime;  // day
  int8_t       has_mnode;
81 82 83
  int8_t       has_qnode;
  int8_t       has_snode;
  int8_t       has_bnode;
84 85 86 87 88 89 90 91 92 93
  SMonDiskDesc logdir;
  SMonDiskDesc tempdir;
} SMonDnodeInfo;

typedef struct {
  SMonBasicInfo basic;
  SMonDnodeInfo dnode;
  SMonSysInfo   sys;
} SMonDmInfo;

S
Shengliang Guan 已提交
94 95 96
typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
S
monitor  
Shengliang Guan 已提交
97
  char    status[MON_STATUS_LEN];
S
Shengliang Guan 已提交
98 99 100 101 102
} SMonDnodeDesc;

typedef struct {
  int32_t mnode_id;
  char    mnode_ep[TSDB_EP_LEN];
S
monitor  
Shengliang Guan 已提交
103
  char    role[MON_ROLE_LEN];
S
Shengliang Guan 已提交
104 105 106 107 108
} SMonMnodeDesc;

typedef struct {
  char    first_ep[TSDB_EP_LEN];
  int32_t first_ep_dnode_id;
S
monitor  
Shengliang Guan 已提交
109
  char    version[MON_VER_LEN];
S
Shengliang Guan 已提交
110 111 112 113 114 115 116 117 118 119 120
  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;

S
monitor  
Shengliang Guan 已提交
121 122
typedef struct {
  int32_t dnode_id;
S
monitor  
Shengliang Guan 已提交
123
  char    vnode_role[MON_ROLE_LEN];
S
monitor  
Shengliang Guan 已提交
124 125 126 127
} SMonVnodeDesc;

typedef struct {
  int32_t       vgroup_id;
S
monitor  
Shengliang Guan 已提交
128 129 130
  char          database_name[TSDB_DB_NAME_LEN];
  int32_t       tables_num;
  char          status[MON_STATUS_LEN];
S
monitor  
Shengliang Guan 已提交
131 132 133 134 135 136 137 138 139
  SMonVnodeDesc vnodes[TSDB_MAX_REPLICA];
} SMonVgroupDesc;

typedef struct {
  SArray *vgroups;  // array of SMonVgroupDesc
} SMonVgroupInfo;

typedef struct {
  int32_t expire_time;
140 141
  int64_t timeseries_used;
  int64_t timeseries_total;
S
monitor  
Shengliang Guan 已提交
142 143
} SMonGrantInfo;

S
Shengliang Guan 已提交
144
typedef struct {
145 146 147 148
  SMonClusterInfo cluster;
  SMonVgroupInfo  vgroup;
  SMonGrantInfo   grant;
  SMonSysInfo     sys;
149
  SMonLogs        log;
150
} SMonMmInfo;
S
Shengliang Guan 已提交
151

152 153 154
int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo);
int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo);
void    tFreeSMonMmInfo(SMonMmInfo *pInfo);
S
Shengliang Guan 已提交
155 156

typedef struct {
157
  SArray *datadirs;  // array of SMonDiskDesc
S
Shengliang Guan 已提交
158 159
} SMonDiskInfo;

160 161 162 163
typedef struct {
  SMonDiskInfo tfs;
  SVnodesStat  vstat;
  SMonSysInfo  sys;
164
  SMonLogs     log;
165 166 167
} SMonVmInfo;

int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
168
int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
169 170 171 172
void    tFreeSMonVmInfo(SMonVmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
173
  SMonLogs    log;
174 175 176
} SMonQmInfo;

int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
177
int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
178 179 180 181
void    tFreeSMonQmInfo(SMonQmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
182
  SMonLogs    log;
183 184 185 186 187 188 189
} SMonSmInfo;

int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo);
int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo);
void    tFreeSMonSmInfo(SMonSmInfo *pInfo);
typedef struct {
  SMonSysInfo sys;
190
  SMonLogs    log;
191 192 193 194 195
} SMonBmInfo;

int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo);
int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo);
void    tFreeSMonBmInfo(SMonBmInfo *pInfo);
S
monitor  
Shengliang Guan 已提交
196

197 198 199 200 201 202 203 204
typedef struct {
  SArray *pVloads;  // SVnodeLoad
} SMonVloadInfo;

int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo);
int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo);
void    tFreeSMonVloadInfo(SMonVloadInfo *pInfo);

S
monitor  
Shengliang Guan 已提交
205 206 207 208
typedef struct {
  const char *server;
  uint16_t    port;
  int32_t     maxLogs;
S
Shengliang Guan 已提交
209
  bool        comp;
S
monitor  
Shengliang Guan 已提交
210 211 212 213
} SMonCfg;

int32_t monInit(const SMonCfg *pCfg);
void    monCleanup();
S
Shengliang Guan 已提交
214
void    monRecordLog(int64_t ts, ELogLevel level, const char *content);
215 216 217 218 219 220 221 222
int32_t monGetLogs(SMonLogs *logs);
void    monSetDmInfo(SMonDmInfo *pInfo);
void    monSetMmInfo(SMonMmInfo *pInfo);
void    monSetVmInfo(SMonVmInfo *pInfo);
void    monSetQmInfo(SMonQmInfo *pInfo);
void    monSetSmInfo(SMonSmInfo *pInfo);
void    monSetBmInfo(SMonBmInfo *pInfo);
void    monSendReport();
S
monitor  
Shengliang Guan 已提交
223

S
Shengliang Guan 已提交
224 225 226 227 228
#ifdef __cplusplus
}
#endif

#endif /*_TD_MONITOR_H_*/