monitor.h 5.6 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 81 82 83 84 85 86 87 88 89 90
typedef struct {
  float        uptime;  // day
  int8_t       has_mnode;
  SMonDiskDesc logdir;
  SMonDiskDesc tempdir;
} SMonDnodeInfo;

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

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

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

typedef struct {
  char    first_ep[TSDB_EP_LEN];
  int32_t first_ep_dnode_id;
S
monitor  
Shengliang Guan 已提交
106
  char    version[MON_VER_LEN];
S
Shengliang Guan 已提交
107 108 109 110 111 112 113 114 115 116 117
  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 已提交
118 119
typedef struct {
  int32_t dnode_id;
S
monitor  
Shengliang Guan 已提交
120
  char    vnode_role[MON_ROLE_LEN];
S
monitor  
Shengliang Guan 已提交
121 122 123 124
} SMonVnodeDesc;

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

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

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

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

149 150 151
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 已提交
152 153

typedef struct {
154
  SArray *datadirs;  // array of SMonDiskDesc
S
Shengliang Guan 已提交
155 156
} SMonDiskInfo;

157 158 159 160
typedef struct {
  SMonDiskInfo tfs;
  SVnodesStat  vstat;
  SMonSysInfo  sys;
161
  SMonLogs     log;
162 163 164
} SMonVmInfo;

int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
165
int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
166 167 168 169
void    tFreeSMonVmInfo(SMonVmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
170
  SMonLogs    log;
171 172 173
} SMonQmInfo;

int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
174
int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
175 176 177 178
void    tFreeSMonQmInfo(SMonQmInfo *pInfo);

typedef struct {
  SMonSysInfo sys;
179
  SMonLogs    log;
180 181 182 183 184 185 186
} 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;
187
  SMonLogs    log;
188 189 190 191 192
} 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 已提交
193

194 195 196 197 198 199 200 201
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 已提交
202 203 204 205
typedef struct {
  const char *server;
  uint16_t    port;
  int32_t     maxLogs;
S
Shengliang Guan 已提交
206
  bool        comp;
S
monitor  
Shengliang Guan 已提交
207 208 209 210
} SMonCfg;

int32_t monInit(const SMonCfg *pCfg);
void    monCleanup();
S
Shengliang Guan 已提交
211
void    monRecordLog(int64_t ts, ELogLevel level, const char *content);
212 213 214 215 216 217 218 219
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 已提交
220

S
Shengliang Guan 已提交
221 222 223 224 225
#ifdef __cplusplus
}
#endif

#endif /*_TD_MONITOR_H_*/