monitor.h 3.9 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"
S
Shengliang Guan 已提交
22 23 24 25 26

#ifdef __cplusplus
extern "C" {
#endif

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

S
Shengliang Guan 已提交
32 33 34
typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
35 36
  int64_t cluster_id;
  int32_t protocol;
S
Shengliang Guan 已提交
37 38 39 40 41
} SMonBasicInfo;

typedef struct {
  int32_t dnode_id;
  char    dnode_ep[TSDB_EP_LEN];
S
monitor  
Shengliang Guan 已提交
42
  char    status[MON_STATUS_LEN];
S
Shengliang Guan 已提交
43 44 45 46 47
} SMonDnodeDesc;

typedef struct {
  int32_t mnode_id;
  char    mnode_ep[TSDB_EP_LEN];
S
monitor  
Shengliang Guan 已提交
48
  char    role[MON_ROLE_LEN];
S
Shengliang Guan 已提交
49 50 51 52 53
} SMonMnodeDesc;

typedef struct {
  char    first_ep[TSDB_EP_LEN];
  int32_t first_ep_dnode_id;
S
monitor  
Shengliang Guan 已提交
54
  char    version[MON_VER_LEN];
S
Shengliang Guan 已提交
55 56 57 58 59 60 61 62 63 64 65
  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 已提交
66 67
typedef struct {
  int32_t dnode_id;
S
monitor  
Shengliang Guan 已提交
68
  char    vnode_role[MON_ROLE_LEN];
S
monitor  
Shengliang Guan 已提交
69 70 71 72
} SMonVnodeDesc;

typedef struct {
  int32_t       vgroup_id;
S
monitor  
Shengliang Guan 已提交
73 74 75
  char          database_name[TSDB_DB_NAME_LEN];
  int32_t       tables_num;
  char          status[MON_STATUS_LEN];
S
monitor  
Shengliang Guan 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88
  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 已提交
89 90
typedef struct {
  float   uptime;  // day
S
Shengliang Guan 已提交
91 92
  double  cpu_engine;
  double  cpu_system;
S
Shengliang Guan 已提交
93
  float   cpu_cores;
S
Shengliang Guan 已提交
94 95 96 97 98 99
  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
S
monitor  
Shengliang Guan 已提交
100 101 102 103 104 105 106 107 108 109 110
  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
  int64_t req_select;
  int64_t req_insert;
  int64_t req_insert_success;
  int64_t req_insert_batch;
  int64_t req_insert_batch_success;
S
Shengliang Guan 已提交
111 112 113
  int32_t errors;
  int32_t vnodes_num;
  int32_t masters;
S
monitor  
Shengliang Guan 已提交
114
  int8_t  has_mnode;
S
Shengliang Guan 已提交
115 116 117 118
} SMonDnodeInfo;

typedef struct {
  char      name[TSDB_FILENAME_LEN];
S
Shengliang Guan 已提交
119
  int8_t    level;
S
Shengliang Guan 已提交
120 121 122 123
  SDiskSize size;
} SMonDiskDesc;

typedef struct {
S
monitor  
Shengliang Guan 已提交
124 125 126
  SArray      *datadirs;  // array of SMonDiskDesc
  SMonDiskDesc logdir;
  SMonDiskDesc tempdir;
S
Shengliang Guan 已提交
127 128
} SMonDiskInfo;

S
monitor  
Shengliang Guan 已提交
129 130 131 132 133 134
typedef struct SMonInfo SMonInfo;

typedef struct {
  const char *server;
  uint16_t    port;
  int32_t     maxLogs;
S
Shengliang Guan 已提交
135
  bool        comp;
S
monitor  
Shengliang Guan 已提交
136 137 138 139
} SMonCfg;

int32_t monInit(const SMonCfg *pCfg);
void    monCleanup();
S
Shengliang Guan 已提交
140
void    monRecordLog(int64_t ts, ELogLevel level, const char *content);
S
monitor  
Shengliang Guan 已提交
141 142 143 144

SMonInfo *monCreateMonitorInfo();
void      monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo);
void      monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo);
S
monitor  
Shengliang Guan 已提交
145 146
void      monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo);
void      monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo);
S
monitor  
Shengliang Guan 已提交
147 148 149 150 151
void      monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo);
void      monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo);
void      monSendReport(SMonInfo *pMonitor);
void      monCleanupMonitorInfo(SMonInfo *pMonitor);

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

#endif /*_TD_MONITOR_H_*/