monitor.h 6.2 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
  float   master_uptime;     // day
  int32_t monitor_interval;  // sec
112 113 114
  int32_t dbs_total;
  int32_t stbs_total;
  int64_t tbs_total;
S
Shengliang Guan 已提交
115 116 117 118 119 120 121 122 123
  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 已提交
124 125
typedef struct {
  int32_t dnode_id;
S
monitor  
Shengliang Guan 已提交
126
  char    vnode_role[MON_ROLE_LEN];
S
monitor  
Shengliang Guan 已提交
127 128 129 130
} SMonVnodeDesc;

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

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

typedef struct {
  int32_t expire_time;
143 144
  int64_t timeseries_used;
  int64_t timeseries_total;
S
monitor  
Shengliang Guan 已提交
145 146
} SMonGrantInfo;

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

155 156 157
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 已提交
158 159

typedef struct {
160
  SArray *datadirs;  // array of SMonDiskDesc
S
Shengliang Guan 已提交
161 162
} SMonDiskInfo;

163 164 165 166
typedef struct {
  SMonDiskInfo tfs;
  SVnodesStat  vstat;
  SMonSysInfo  sys;
167
  SMonLogs     log;
168 169 170
} SMonVmInfo;

int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
171
int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
172 173 174 175
void    tFreeSMonVmInfo(SMonVmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
176
  SMonLogs    log;
D
dapan1121 已提交
177
  SQnodeLoad  load;
178 179 180
} SMonQmInfo;

int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
181
int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
182 183 184 185
void    tFreeSMonQmInfo(SMonQmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
186
  SMonLogs    log;
187 188 189 190 191 192 193
} 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;
194
  SMonLogs    log;
195 196 197 198 199
} 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 已提交
200

201 202 203 204 205 206 207 208
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
Shengliang Guan 已提交
209 210 211 212 213 214 215 216
typedef struct {
  int8_t     isMnode;
  SMnodeLoad load;
} SMonMloadInfo;

int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo);
int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo);

D
dapan1121 已提交
217 218 219 220
int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo);
int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo);


S
monitor  
Shengliang Guan 已提交
221 222 223 224
typedef struct {
  const char *server;
  uint16_t    port;
  int32_t     maxLogs;
S
Shengliang Guan 已提交
225
  bool        comp;
S
monitor  
Shengliang Guan 已提交
226 227 228 229
} SMonCfg;

int32_t monInit(const SMonCfg *pCfg);
void    monCleanup();
S
Shengliang Guan 已提交
230
void    monRecordLog(int64_t ts, ELogLevel level, const char *content);
231 232 233 234 235 236 237 238
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 已提交
239

S
Shengliang Guan 已提交
240 241 242 243 244
#ifdef __cplusplus
}
#endif

#endif /*_TD_MONITOR_H_*/