TDengine/include/libs/monitor/monitor.h

242 lines
5.4 KiB
C
Raw Normal View History

2022-03-02 06:00:56 +00:00
/*
* 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"
2022-03-04 06:34:35 +00:00
#include "tlog.h"
#include "tmsg.h"
2022-03-02 06:00:56 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-03-03 08:37:37 +00:00
#define MON_STATUS_LEN 8
#define MON_ROLE_LEN 9
#define MON_VER_LEN 12
#define MON_LOG_LEN 1024
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;
2022-03-02 06:00:56 +00:00
typedef struct {
int32_t dnode_id;
char dnode_ep[TSDB_EP_LEN];
2022-03-07 07:37:20 +00:00
int64_t cluster_id;
int32_t protocol;
2022-03-02 06:00:56 +00:00
} SMonBasicInfo;
typedef struct {
2024-02-22 02:00:33 +00:00
//float uptime; // day
int64_t uptime; // second
int8_t has_mnode;
int8_t has_qnode;
int8_t has_snode;
SMonDiskDesc logdir;
SMonDiskDesc tempdir;
} SMonDnodeInfo;
typedef struct {
SMonBasicInfo basic;
SMonDnodeInfo dnode;
SMonSysInfo sys;
} SMonDmInfo;
2022-03-02 06:00:56 +00:00
typedef struct {
int32_t dnode_id;
char dnode_ep[TSDB_EP_LEN];
2022-03-03 08:37:37 +00:00
char status[MON_STATUS_LEN];
2022-03-02 06:00:56 +00:00
} SMonDnodeDesc;
typedef struct {
int32_t mnode_id;
char mnode_ep[TSDB_EP_LEN];
2022-03-03 08:37:37 +00:00
char role[MON_ROLE_LEN];
2024-01-24 09:44:44 +00:00
int32_t syncState;
2022-03-02 06:00:56 +00:00
} SMonMnodeDesc;
typedef struct {
char first_ep[TSDB_EP_LEN];
int32_t first_ep_dnode_id;
2022-03-03 08:37:37 +00:00
char version[MON_VER_LEN];
2024-02-22 00:49:51 +00:00
//float master_uptime; // day
int64_t master_uptime; //second
2022-03-02 06:00:56 +00:00
int32_t monitor_interval; // sec
2022-06-23 10:23:51 +00:00
int32_t dbs_total;
int32_t stbs_total;
int64_t tbs_total;
2022-03-02 06:00:56 +00:00
int32_t vgroups_total;
int32_t vgroups_alive;
int32_t vnodes_total;
int32_t vnodes_alive;
int32_t connections_total;
int32_t topics_toal;
int32_t streams_total;
2022-03-02 06:00:56 +00:00
SArray *dnodes; // array of SMonDnodeDesc
SArray *mnodes; // array of SMonMnodeDesc
} SMonClusterInfo;
2022-03-02 09:48:39 +00:00
typedef struct {
int32_t dnode_id;
2022-03-03 08:37:37 +00:00
char vnode_role[MON_ROLE_LEN];
2024-01-24 09:44:44 +00:00
int32_t syncState;
2022-03-02 09:48:39 +00:00
} SMonVnodeDesc;
typedef struct {
int32_t vgroup_id;
2022-03-03 08:37:37 +00:00
char database_name[TSDB_DB_NAME_LEN];
int32_t tables_num;
char status[MON_STATUS_LEN];
2022-03-02 09:48:39 +00:00
SMonVnodeDesc vnodes[TSDB_MAX_REPLICA];
} SMonVgroupDesc;
typedef struct {
SArray *vgroups; // array of SMonVgroupDesc
} SMonVgroupInfo;
2022-06-23 13:09:50 +00:00
typedef struct {
char stb_name[TSDB_TABLE_NAME_LEN];
char database_name[TSDB_DB_NAME_LEN];
} SMonStbDesc;
typedef struct {
SArray *stbs; // array of SMonStbDesc
} SMonStbInfo;
2022-03-02 09:48:39 +00:00
typedef struct {
2024-02-22 04:55:54 +00:00
int64_t expire_time;
2023-03-22 08:08:16 +00:00
int64_t timeseries_used;
int64_t timeseries_total;
2022-03-02 09:48:39 +00:00
} SMonGrantInfo;
2022-03-02 06:00:56 +00:00
typedef struct {
SMonClusterInfo cluster;
SMonVgroupInfo vgroup;
2022-06-23 13:09:50 +00:00
SMonStbInfo stb;
SMonGrantInfo grant;
SMonSysInfo sys;
SMonLogs log;
} SMonMmInfo;
2022-03-02 06:00:56 +00:00
typedef struct {
SArray *datadirs; // array of SMonDiskDesc
2022-03-02 06:00:56 +00:00
} SMonDiskInfo;
typedef struct {
SMonDiskInfo tfs;
SVnodesStat vstat;
SMonSysInfo sys;
SMonLogs log;
} SMonVmInfo;
typedef struct {
SMonSysInfo sys;
SMonLogs log;
2022-05-31 06:03:47 +00:00
SQnodeLoad load;
} SMonQmInfo;
typedef struct {
SMonSysInfo sys;
SMonLogs log;
} SMonSmInfo;
typedef struct {
SMonSysInfo sys;
SMonLogs log;
} SMonBmInfo;
typedef struct {
SArray *pVloads; // SVnodeLoad/SVnodeLoadLite
} SMonVloadInfo;
2022-04-19 13:39:42 +00:00
typedef struct {
int8_t isMnode;
SMnodeLoad load;
} SMonMloadInfo;
2022-03-02 07:41:19 +00:00
typedef struct {
const char *server;
uint16_t port;
int32_t maxLogs;
2022-03-07 05:52:49 +00:00
bool comp;
2022-03-02 07:41:19 +00:00
} SMonCfg;
2023-10-05 13:35:57 +00:00
typedef struct {
int8_t state;
tsem_t sem;
} SDmNotifyHandle;
2022-03-02 07:41:19 +00:00
int32_t monInit(const SMonCfg *pCfg);
void monCleanup();
2022-03-04 07:15:29 +00:00
void monRecordLog(int64_t ts, ELogLevel level, const char *content);
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);
2024-01-24 09:44:44 +00:00
void monGenAndSendReport();
2024-06-19 10:54:26 +00:00
void monSendContent(char *pCont, const char* uri);
2022-03-02 07:41:19 +00:00
2022-10-20 03:07:33 +00:00
void tFreeSMonMmInfo(SMonMmInfo *pInfo);
void tFreeSMonVmInfo(SMonVmInfo *pInfo);
void tFreeSMonQmInfo(SMonQmInfo *pInfo);
void tFreeSMonSmInfo(SMonSmInfo *pInfo);
void tFreeSMonBmInfo(SMonBmInfo *pInfo);
2022-03-02 06:00:56 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_MONITOR_H_*/