Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f492ae74
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f492ae74
编写于
4月 07, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: send monitor information in multi-process mode
上级
18446454
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
654 addition
and
265 deletion
+654
-265
include/common/tmsg.h
include/common/tmsg.h
+12
-0
include/common/tmsgdef.h
include/common/tmsgdef.h
+9
-0
include/libs/monitor/monitor.h
include/libs/monitor/monitor.h
+106
-45
include/os/osSysinfo.h
include/os/osSysinfo.h
+2
-2
source/dnode/mgmt/dm/dmHandle.c
source/dnode/mgmt/dm/dmHandle.c
+3
-0
source/dnode/mgmt/dm/dmMonitor.c
source/dnode/mgmt/dm/dmMonitor.c
+33
-1
source/dnode/mgmt/dm/dmWorker.c
source/dnode/mgmt/dm/dmWorker.c
+3
-0
source/dnode/mgmt/inc/dmInt.h
source/dnode/mgmt/inc/dmInt.h
+9
-1
source/libs/monitor/inc/monInt.h
source/libs/monitor/inc/monInt.h
+19
-30
source/libs/monitor/src/monMsg.c
source/libs/monitor/src/monMsg.c
+54
-0
source/libs/monitor/src/monitor.c
source/libs/monitor/src/monitor.c
+237
-89
source/libs/monitor/test/CMakeLists.txt
source/libs/monitor/test/CMakeLists.txt
+4
-4
source/libs/monitor/test/monTest.cpp
source/libs/monitor/test/monTest.cpp
+121
-83
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+42
-10
未找到文件。
include/common/tmsg.h
浏览文件 @
f492ae74
...
...
@@ -679,6 +679,18 @@ typedef struct {
char
charset
[
TD_LOCALE_LEN
];
// tsCharset
}
SClusterCfg
;
typedef
struct
{
int32_t
openVnodes
;
int32_t
totalVnodes
;
int32_t
masterNum
;
int64_t
numOfSelectReqs
;
int64_t
numOfInsertReqs
;
int64_t
numOfInsertSuccessReqs
;
int64_t
numOfBatchInsertReqs
;
int64_t
numOfBatchInsertSuccessReqs
;
int64_t
errors
;
}
SVnodesStat
;
typedef
struct
{
int32_t
vgId
;
int8_t
role
;
...
...
include/common/tmsgdef.h
浏览文件 @
f492ae74
...
...
@@ -216,6 +216,15 @@ enum {
TD_NEW_MSG_SEG
(
TDMT_SCH_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_LINK_BROKEN
,
"scheduler-link-broken"
,
NULL
,
NULL
)
// Monitor info exchange between processes
TD_NEW_MSG_SEG
(
TDMT_MON_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MM_INFO
,
"monitor-minfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_VM_INFO
,
"monitor-vinfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_QM_INFO
,
"monitor-qinfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_SM_INFO
,
"monitor-sinfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_BM_INFO
,
"monitor-binfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_VM_LOAD
,
"monitor-vload"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
TDMT_MAX
#endif
...
...
include/libs/monitor/monitor.h
浏览文件 @
f492ae74
...
...
@@ -19,6 +19,7 @@
#include "tarray.h"
#include "tdef.h"
#include "tlog.h"
#include "tmsg.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -29,6 +30,44 @@ extern "C" {
#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
;
typedef
struct
{
int32_t
dnode_id
;
char
dnode_ep
[
TSDB_EP_LEN
];
...
...
@@ -36,6 +75,19 @@ typedef struct {
int32_t
protocol
;
}
SMonBasicInfo
;
typedef
struct
{
float
uptime
;
// day
int8_t
has_mnode
;
SMonDiskDesc
logdir
;
SMonDiskDesc
tempdir
;
}
SMonDnodeInfo
;
typedef
struct
{
SMonBasicInfo
basic
;
SMonDnodeInfo
dnode
;
SMonSysInfo
sys
;
}
SMonDmInfo
;
typedef
struct
{
int32_t
dnode_id
;
char
dnode_ep
[
TSDB_EP_LEN
];
...
...
@@ -87,46 +139,57 @@ typedef struct {
}
SMonGrantInfo
;
typedef
struct
{
float
uptime
;
// day
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
int64_t
req_select
;
int64_t
req_insert
;
int64_t
req_insert_success
;
int64_t
req_insert_batch
;
int64_t
req_insert_batch_success
;
int32_t
errors
;
int32_t
vnodes_num
;
int32_t
masters
;
int8_t
has_mnode
;
}
SMonDnodeInfo
;
SMonClusterInfo
cluster
;
SMonVgroupInfo
vgroup
;
SMonGrantInfo
grant
;
SMonSysInfo
sys
;
SMonLogs
logs
;
}
SMonMmInfo
;
typedef
struct
{
char
name
[
TSDB_FILENAME_LEN
];
int8_t
level
;
SDiskSize
size
;
}
SMonDiskDesc
;
int32_t
tSerializeSMonMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonMmInfo
*
pInfo
);
int32_t
tDeserializeSMonMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonMmInfo
*
pInfo
);
void
tFreeSMonMmInfo
(
SMonMmInfo
*
pInfo
);
typedef
struct
{
SArray
*
datadirs
;
// array of SMonDiskDesc
SMonDiskDesc
logdir
;
SMonDiskDesc
tempdir
;
SArray
*
datadirs
;
// array of SMonDiskDesc
}
SMonDiskInfo
;
typedef
struct
SMonInfo
SMonInfo
;
typedef
struct
{
SMonDiskInfo
tfs
;
SVnodesStat
vstat
;
SMonSysInfo
sys
;
SMonLogs
logs
;
}
SMonVmInfo
;
int32_t
tSerializeSMonVmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonVmInfo
*
pInfo
);
int32_t
tDeserializeSMonVMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonVmInfo
*
pInfo
);
void
tFreeSMonVmInfo
(
SMonVmInfo
*
pInfo
);
typedef
struct
{
SMonSysInfo
sys
;
SMonLogs
logs
;
}
SMonQmInfo
;
int32_t
tSerializeSMonQmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonQmInfo
*
pInfo
);
int32_t
tDeserializeSMonQMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonQmInfo
*
pInfo
);
void
tFreeSMonQmInfo
(
SMonQmInfo
*
pInfo
);
typedef
struct
{
SMonSysInfo
sys
;
SMonLogs
logs
;
}
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
;
SMonLogs
logs
;
}
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
);
typedef
struct
{
const
char
*
server
;
...
...
@@ -138,16 +201,14 @@ typedef struct {
int32_t
monInit
(
const
SMonCfg
*
pCfg
);
void
monCleanup
();
void
monRecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
);
SMonInfo
*
monCreateMonitorInfo
();
void
monSetBasicInfo
(
SMonInfo
*
pMonitor
,
SMonBasicInfo
*
pInfo
);
void
monSetClusterInfo
(
SMonInfo
*
pMonitor
,
SMonClusterInfo
*
pInfo
);
void
monSetVgroupInfo
(
SMonInfo
*
pMonitor
,
SMonVgroupInfo
*
pInfo
);
void
monSetGrantInfo
(
SMonInfo
*
pMonitor
,
SMonGrantInfo
*
pInfo
);
void
monSetDnodeInfo
(
SMonInfo
*
pMonitor
,
SMonDnodeInfo
*
pInfo
);
void
monSetDiskInfo
(
SMonInfo
*
pMonitor
,
SMonDiskInfo
*
pInfo
);
void
monSendReport
(
SMonInfo
*
pMonitor
);
void
monCleanupMonitorInfo
(
SMonInfo
*
pMonitor
);
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
();
#ifdef __cplusplus
}
...
...
include/os/osSysinfo.h
浏览文件 @
f492ae74
...
...
@@ -44,8 +44,8 @@ int32_t taosGetTotalMemory(int64_t *totalKB);
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
);
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
);
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
);
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
);
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
);
void
taosGetProcIODelta
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
);
void
taosGetCardInfoDelta
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
);
void
taosKillSystem
();
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
);
...
...
source/dnode/mgmt/dm/dmHandle.c
浏览文件 @
f492ae74
...
...
@@ -212,4 +212,7 @@ void dmInitMsgHandle(SMgmtWrapper *pWrapper) {
dndSetMsgHandle
(
pWrapper
,
TDMT_MND_STATUS_RSP
,
dmProcessStatusMsg
,
DEFAULT_HANDLE
);
dndSetMsgHandle
(
pWrapper
,
TDMT_MND_GRANT_RSP
,
dmProcessMgmtMsg
,
DEFAULT_HANDLE
);
dndSetMsgHandle
(
pWrapper
,
TDMT_MND_AUTH_RSP
,
dmProcessMgmtMsg
,
DEFAULT_HANDLE
);
// Monitor info exchange between processes
dndSetMsgHandle
(
pWrapper
,
TDMT_MON_DISK_INFO
,
dmProcessStatusMsg
,
DEFAULT_HANDLE
);
}
source/dnode/mgmt/dm/dmMonitor.c
浏览文件 @
f492ae74
...
...
@@ -14,7 +14,7 @@
*/
#define _DEFAULT_SOURCE
#include "d
nd
Int.h"
#include "d
m
Int.h"
static
int32_t
dmGetMonitorDiskInfo
(
SDnode
*
pDnode
,
SMonDiskInfo
*
pInfo
)
{
tstrncpy
(
pInfo
->
logdir
.
name
,
tsLogDir
,
sizeof
(
pInfo
->
logdir
.
name
));
...
...
@@ -104,4 +104,36 @@ void dmSendMonitorReport(SDnode *pDnode) {
monSendReport
(
pMonitor
);
monCleanupMonitorInfo
(
pMonitor
);
}
int32_t
dmSetDiskInfo
(
SDnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
)
{
SDnode
*
pDnode
=
pMgmt
->
pDnode
;
SMonDiskInfo
info
=
{
0
};
if
(
tDeserializeSMonDiskInfo
(
pMsg
->
rpcMsg
.
pCont
,
pMsg
->
rpcMsg
.
contLen
,
&
info
)
!=
0
)
{
dError
(
"failed to parse diskinfo since %s"
,
terrstr
());
return
0
;
}
taosWLockLatch
(
&
pMgmt
->
latch
);
memcpy
(
&
pMgmt
->
diskInfo
,
&
info
,
sizeof
(
SMonDiskInfo
));
taosWUnLockLatch
(
&
pMgmt
->
latch
);
return
0
;
}
int32_t
dmSetVnodeStat
(
SDnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
)
{
SDnode
*
pDnode
=
pMgmt
->
pDnode
;
SVnodesStat
info
=
{
0
};
if
(
tDeserializeSMonDiskInfo
(
pMsg
->
rpcMsg
.
pCont
,
pMsg
->
rpcMsg
.
contLen
,
&
info
)
!=
0
)
{
dError
(
"failed to parse diskinfo since %s"
,
terrstr
());
return
0
;
}
taosWLockLatch
(
&
pMgmt
->
latch
);
memcpy
(
&
pMgmt
->
diskInfo
,
&
info
,
sizeof
(
SMonDiskInfo
));
taosWUnLockLatch
(
&
pMgmt
->
latch
);
return
0
;
}
\ No newline at end of file
source/dnode/mgmt/dm/dmWorker.c
浏览文件 @
f492ae74
...
...
@@ -78,6 +78,9 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
case
TDMT_MND_GRANT_RSP
:
code
=
dmProcessGrantRsp
(
pMgmt
,
pMsg
);
break
;
case
TDMT_MON_DISK_INFO_RSP
:
code
=
dmSetDiskInfo
(
pMgmt
,
pMsg
);
break
;
default:
code
=
dmProcessCDnodeReq
(
pMgmt
->
pDnode
,
pMsg
);
break
;
...
...
source/dnode/mgmt/inc/dmInt.h
浏览文件 @
f492ae74
...
...
@@ -37,6 +37,11 @@ typedef struct SDnodeMgmt {
const
char
*
path
;
SDnode
*
pDnode
;
SMgmtWrapper
*
pWrapper
;
// monitor infos
SMonDiskInfo
diskInfo
;
SMonVnodesStat
vnodesStat
;
SMonVnodesLoad
vnodesLoad
;
}
SDnodeMgmt
;
// dmFile.c
...
...
@@ -54,7 +59,10 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
int32_t
dmProcessCDnodeReq
(
SDnode
*
pDnode
,
SNodeMsg
*
pMsg
);
// dmMonitor.c
void
dmSendMonitorReport
(
SDnode
*
pDnode
);
int32_t
dmSetDiskInfo
(
SDnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
);
int32_t
dmSetVnodesStat
(
SDnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
);
int32_t
dmSetVnodesLoad
(
SDnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
);
void
dmSendMonitorReport
(
SDnode
*
pDnode
);
// dmWorker.c
int32_t
dmStartThread
(
SDnodeMgmt
*
pMgmt
);
...
...
source/libs/monitor/inc/monInt.h
浏览文件 @
f492ae74
...
...
@@ -18,43 +18,32 @@
#include "monitor.h"
#include "tarray.h"
#include "tjson.h"
typedef
struct
{
int64_t
ts
;
ELogLevel
level
;
char
content
[
MON_LOG_LEN
];
}
SMonLogItem
;
typedef
struct
{
int64_t
time
;
int64_t
req_select
;
int64_t
req_insert
;
int64_t
req_insert_batch
;
int64_t
net_in
;
int64_t
net_out
;
int64_t
io_read
;
int64_t
io_write
;
int64_t
io_read_disk
;
int64_t
io_write_disk
;
}
SMonState
;
typedef
struct
SMonInfo
{
int64_t
curTime
;
SMonState
lastState
;
SArray
*
logs
;
// array of SMonLogItem
SJson
*
pJson
;
int64_t
curTime
;
int64_t
lastTime
;
SJson
*
pJson
;
SMonLogs
logs
;
SMonDmInfo
dmInfo
;
SMonMmInfo
mmInfo
;
SMonVmInfo
vmInfo
;
SMonSmInfo
smInfo
;
SMonQmInfo
qmInfo
;
SMonBmInfo
bmInfo
;
}
SMonInfo
;
typedef
struct
{
TdThreadMutex
lock
;
SArray
*
logs
;
// array of SMonLogItem
int32_t
maxLogs
;
const
char
*
server
;
uint16_t
port
;
bool
comp
;
SMonState
state
;
SArray
*
logs
;
// array of SMonLogItem
SMonCfg
cfg
;
int64_t
lastTime
;
SMonDmInfo
dmInfo
;
SMonMmInfo
mmInfo
;
SMonVmInfo
vmInfo
;
SMonSmInfo
smInfo
;
SMonQmInfo
qmInfo
;
SMonBmInfo
bmInfo
;
}
SMonitor
;
#ifdef __cplusplus
...
...
source/libs/monitor/src/monMsg.c
0 → 100644
浏览文件 @
f492ae74
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "monInt.h"
#include "tcoding.h"
#include "tencode.h"
int32_t
tSerializeSMonMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonMmInfo
*
pInfo
);
int32_t
tDeserializeSMonMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonMmInfo
*
pInfo
);
void
tFreeSMonMmInfo
(
SMonMmInfo
*
pInfo
)
{
taosArrayDestroy
(
pInfo
->
logs
.
logs
);
pInfo
->
logs
.
logs
=
NULL
;
}
int32_t
tSerializeSMonVmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonVmInfo
*
pInfo
);
int32_t
tDeserializeSMonVMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonVmInfo
*
pInfo
);
void
tFreeSMonVmInfo
(
SMonVmInfo
*
pInfo
)
{
taosArrayDestroy
(
pInfo
->
logs
.
logs
);
pInfo
->
logs
.
logs
=
NULL
;
}
int32_t
tSerializeSMonQmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonQmInfo
*
pInfo
);
int32_t
tDeserializeSMonQMmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonQmInfo
*
pInfo
);
void
tFreeSMonQmInfo
(
SMonQmInfo
*
pInfo
)
{
taosArrayDestroy
(
pInfo
->
logs
.
logs
);
pInfo
->
logs
.
logs
=
NULL
;
}
int32_t
tSerializeSMonSmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonSmInfo
*
pInfo
);
int32_t
tDeserializeSMonSmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonSmInfo
*
pInfo
);
void
tFreeSMonSmInfo
(
SMonSmInfo
*
pInfo
)
{
taosArrayDestroy
(
pInfo
->
logs
.
logs
);
pInfo
->
logs
.
logs
=
NULL
;
}
int32_t
tSerializeSMonBmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonBmInfo
*
pInfo
);
int32_t
tDeserializeSMonBmInfo
(
void
*
buf
,
int32_t
bufLen
,
SMonBmInfo
*
pInfo
);
void
tFreeSMonBmInfo
(
SMonBmInfo
*
pInfo
)
{
taosArrayDestroy
(
pInfo
->
logs
.
logs
);
pInfo
->
logs
.
logs
=
NULL
;
}
\ No newline at end of file
source/libs/monitor/src/monitor.c
浏览文件 @
f492ae74
此差异已折叠。
点击以展开。
source/libs/monitor/test/CMakeLists.txt
浏览文件 @
f492ae74
enable_testing
()
aux_source_directory
(
. MONITOR_TEST_SRC
)
add_executable
(
monitor
_t
est
${
MONITOR_TEST_SRC
}
)
add_executable
(
monitor
T
est
${
MONITOR_TEST_SRC
}
)
target_link_libraries
(
monitor
_t
est
monitor
T
est
PUBLIC monitor
PUBLIC gtest_main
)
add_test
(
NAME monitor
_t
est
COMMAND monitor
_t
est
NAME monitor
T
est
COMMAND monitor
T
est
)
source/libs/monitor/test/monTest.cpp
浏览文件 @
f492ae74
...
...
@@ -22,7 +22,7 @@ class MonitorTest : public ::testing::Test {
cfg
.
maxLogs
=
2
;
cfg
.
port
=
80
;
cfg
.
server
=
"localhost"
;
cfg
.
comp
=
0
;
cfg
.
comp
=
1
;
monInit
(
&
cfg
);
}
...
...
@@ -32,24 +32,64 @@ class MonitorTest : public ::testing::Test {
void
SetUp
()
override
{}
void
TearDown
()
override
{}
void
GetBasicInfo
(
SMonInfo
*
pMonitor
,
SMonBasicInfo
*
pInfo
);
void
GetClusterInfo
(
SMonInfo
*
pMonitor
,
SMonClusterInfo
*
pInfo
);
void
GetVgroupInfo
(
SMonInfo
*
pMonitor
,
SMonVgroupInfo
*
pInfo
);
void
GetGrantInfo
(
SMonInfo
*
pMonitor
,
SMonGrantInfo
*
pInfo
);
void
GetDnodeInfo
(
SMonInfo
*
pMonitor
,
SMonDnodeInfo
*
pInfo
);
void
GetDiskInfo
(
SMonInfo
*
pMonitor
,
SMonDiskInfo
*
pInfo
);
void
GetBasicInfo
(
SMonBasicInfo
*
pInfo
);
void
GetDnodeInfo
(
SMonDnodeInfo
*
pInfo
);
void
GetSysInfo
(
SMonSysInfo
*
pInfo
);
void
GetClusterInfo
(
SMonClusterInfo
*
pInfo
);
void
GetVgroupInfo
(
SMonVgroupInfo
*
pInfo
);
void
GetGrantInfo
(
SMonGrantInfo
*
pInfo
);
void
GetVnodeStat
(
SVnodesStat
*
pStat
);
void
GetDiskInfo
(
SMonDiskInfo
*
pInfo
);
void
GetLogInfo
(
SMonLogs
*
logs
);
void
AddLogInfo1
();
void
AddLogInfo2
();
};
void
MonitorTest
::
GetBasicInfo
(
SMon
Info
*
pMonitor
,
SMon
BasicInfo
*
pInfo
)
{
void
MonitorTest
::
GetBasicInfo
(
SMonBasicInfo
*
pInfo
)
{
pInfo
->
dnode_id
=
1
;
strcpy
(
pInfo
->
dnode_ep
,
"localhost"
);
pInfo
->
cluster_id
=
6980428120398645172
;
pInfo
->
protocol
=
1
;
}
void
MonitorTest
::
GetClusterInfo
(
SMonInfo
*
pMonitor
,
SMonClusterInfo
*
pInfo
)
{
void
MonitorTest
::
GetDnodeInfo
(
SMonDnodeInfo
*
pInfo
)
{
pInfo
->
uptime
=
1.2
;
pInfo
->
has_mnode
=
1
;
strcpy
(
pInfo
->
logdir
.
name
,
"/log/dir/d"
);
pInfo
->
logdir
.
size
.
avail
=
41
;
pInfo
->
logdir
.
size
.
total
=
42
;
pInfo
->
logdir
.
size
.
used
=
43
;
strcpy
(
pInfo
->
tempdir
.
name
,
"/data/dir/d"
);
pInfo
->
tempdir
.
size
.
avail
=
51
;
pInfo
->
tempdir
.
size
.
total
=
52
;
pInfo
->
tempdir
.
size
.
used
=
53
;
}
void
MonitorTest
::
GetSysInfo
(
SMonSysInfo
*
pInfo
)
{
pInfo
->
cpu_engine
=
2.1
;
pInfo
->
cpu_system
=
2.1
;
pInfo
->
cpu_cores
=
2
;
pInfo
->
mem_engine
=
3.1
;
pInfo
->
mem_system
=
3.2
;
pInfo
->
mem_total
=
3.3
;
pInfo
->
disk_engine
=
4.1
;
pInfo
->
disk_used
=
4.2
;
pInfo
->
disk_total
=
4.3
;
pInfo
->
net_in
=
5.1
;
pInfo
->
net_out
=
5.2
;
pInfo
->
io_read
=
6.1
;
pInfo
->
io_write
=
6.2
;
pInfo
->
io_read_disk
=
7.1
;
pInfo
->
io_write_disk
=
7.2
;
}
void
MonitorTest
::
GetClusterInfo
(
SMonClusterInfo
*
pInfo
)
{
strcpy
(
pInfo
->
first_ep
,
"localhost:6030"
);
pInfo
->
first_ep_dnode_id
=
1
;
strcpy
(
pInfo
->
version
,
"3.0.0.0"
);
...
...
@@ -86,7 +126,7 @@ void MonitorTest::GetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) {
taosArrayPush
(
pInfo
->
mnodes
,
&
m2
);
}
void
MonitorTest
::
GetVgroupInfo
(
SMon
Info
*
pMonitor
,
SMon
VgroupInfo
*
pInfo
)
{
void
MonitorTest
::
GetVgroupInfo
(
SMonVgroupInfo
*
pInfo
)
{
pInfo
->
vgroups
=
taosArrayInit
(
4
,
sizeof
(
SMonVgroupDesc
));
SMonVgroupDesc
vg1
=
{
0
};
...
...
@@ -121,41 +161,24 @@ void MonitorTest::GetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) {
taosArrayPush
(
pInfo
->
vgroups
,
&
vg3
);
}
void
MonitorTest
::
GetGrantInfo
(
SMon
Info
*
pMonitor
,
SMon
GrantInfo
*
pInfo
)
{
void
MonitorTest
::
GetGrantInfo
(
SMonGrantInfo
*
pInfo
)
{
pInfo
->
expire_time
=
1234567
;
pInfo
->
timeseries_total
=
234567
;
pInfo
->
timeseries_used
=
34567
;
}
void
MonitorTest
::
GetDnodeInfo
(
SMonInfo
*
pMonitor
,
SMonDnodeInfo
*
pInfo
)
{
pInfo
->
uptime
=
1.2
;
pInfo
->
cpu_engine
=
2.1
;
pInfo
->
cpu_system
=
2.1
;
pInfo
->
cpu_cores
=
2
;
pInfo
->
mem_engine
=
3.1
;
pInfo
->
mem_system
=
3.2
;
pInfo
->
mem_total
=
3.3
;
pInfo
->
disk_engine
=
4.1
;
pInfo
->
disk_used
=
4.2
;
pInfo
->
disk_total
=
4.3
;
pInfo
->
net_in
=
5.1
;
pInfo
->
net_out
=
5.2
;
pInfo
->
io_read
=
6.1
;
pInfo
->
io_write
=
6.2
;
pInfo
->
io_read_disk
=
7.1
;
pInfo
->
io_write_disk
=
7.2
;
pInfo
->
req_select
=
8
;
pInfo
->
req_insert
=
9
;
pInfo
->
req_insert_success
=
10
;
pInfo
->
req_insert_batch
=
11
;
pInfo
->
req_insert_batch_success
=
12
;
void
MonitorTest
::
GetVnodeStat
(
SVnodesStat
*
pInfo
)
{
pInfo
->
numOfSelectReqs
=
8
;
pInfo
->
numOfInsertReqs
=
9
;
pInfo
->
numOfInsertSuccessReqs
=
10
;
pInfo
->
numOfBatchInsertReqs
=
11
;
pInfo
->
numOfBatchInsertSuccessReqs
=
12
;
pInfo
->
errors
=
4
;
pInfo
->
vnodes_num
=
5
;
pInfo
->
masters
=
6
;
pInfo
->
has_mnode
=
1
;
pInfo
->
totalVnodes
=
5
;
pInfo
->
masterNum
=
6
;
}
void
MonitorTest
::
GetDiskInfo
(
SMon
Info
*
pMonitor
,
SMon
DiskInfo
*
pInfo
)
{
void
MonitorTest
::
GetDiskInfo
(
SMonDiskInfo
*
pInfo
)
{
pInfo
->
datadirs
=
taosArrayInit
(
2
,
sizeof
(
SMonDiskDesc
));
SMonDiskDesc
d1
=
{
0
};
strcpy
(
d1
.
name
,
"/t1/d1/d"
);
...
...
@@ -180,16 +203,25 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) {
d3
.
size
.
total
=
32
;
d3
.
size
.
used
=
33
;
taosArrayPush
(
pInfo
->
datadirs
,
&
d3
);
}
strcpy
(
pInfo
->
logdir
.
name
,
"/log/dir/d"
);
pInfo
->
logdir
.
size
.
avail
=
41
;
pInfo
->
logdir
.
size
.
total
=
42
;
pInfo
->
logdir
.
size
.
used
=
43
;
void
MonitorTest
::
GetLogInfo
(
SMonLogs
*
logs
)
{
logs
->
logs
=
taosArrayInit
(
4
,
sizeof
(
SMonLogItem
));
strcpy
(
pInfo
->
tempdir
.
name
,
"/data/dir/d"
);
pInfo
->
tempdir
.
size
.
avail
=
51
;
pInfo
->
tempdir
.
size
.
total
=
52
;
pInfo
->
tempdir
.
size
.
used
=
53
;
SMonLogItem
item1
=
{.
level
=
DEBUG_INFO
};
item1
.
ts
=
taosGetTimestampMs
();
strcpy
(
item1
.
content
,
"log test1"
);
taosArrayPush
(
logs
->
logs
,
&
item1
);
SMonLogItem
item2
=
{.
level
=
DEBUG_ERROR
};
item2
.
ts
=
taosGetTimestampMs
();
strcpy
(
item2
.
content
,
"log test2"
);
taosArrayPush
(
logs
->
logs
,
&
item2
);
logs
->
numOfErrorLogs
=
1
;
logs
->
numOfInfoLogs
=
2
;
logs
->
numOfDebugLogs
=
3
;
logs
->
numOfTraceLogs
=
4
;
}
void
MonitorTest
::
AddLogInfo1
()
{
...
...
@@ -206,46 +238,52 @@ void MonitorTest::AddLogInfo2() {
TEST_F
(
MonitorTest
,
01
_Full
)
{
AddLogInfo1
();
SMonInfo
*
pMonitor
=
monCreateMonitorInfo
();
if
(
pMonitor
==
NULL
)
return
;
SMonBasicInfo
basicInfo
=
{
0
};
GetBasicInfo
(
pMonitor
,
&
basicInfo
);
monSetBasicInfo
(
pMonitor
,
&
basicInfo
);
SMonClusterInfo
clusterInfo
=
{
0
};
SMonVgroupInfo
vgroupInfo
=
{
0
};
SMonGrantInfo
grantInfo
=
{
0
};
GetClusterInfo
(
pMonitor
,
&
clusterInfo
);
GetVgroupInfo
(
pMonitor
,
&
vgroupInfo
);
GetGrantInfo
(
pMonitor
,
&
grantInfo
);
monSetClusterInfo
(
pMonitor
,
&
clusterInfo
);
monSetVgroupInfo
(
pMonitor
,
&
vgroupInfo
);
monSetGrantInfo
(
pMonitor
,
&
grantInfo
);
SMonDnodeInfo
dnodeInfo
=
{
0
};
GetDnodeInfo
(
pMonitor
,
&
dnodeInfo
);
monSetDnodeInfo
(
pMonitor
,
&
dnodeInfo
);
SMonDiskInfo
diskInfo
=
{
0
};
GetDiskInfo
(
pMonitor
,
&
diskInfo
);
monSetDiskInfo
(
pMonitor
,
&
diskInfo
);
monSendReport
(
pMonitor
);
monCleanupMonitorInfo
(
pMonitor
);
taosArrayDestroy
(
clusterInfo
.
dnodes
);
taosArrayDestroy
(
clusterInfo
.
mnodes
);
taosArrayDestroy
(
vgroupInfo
.
vgroups
);
taosArrayDestroy
(
diskInfo
.
datadirs
);
SMonDmInfo
dmInfo
=
{
0
};
GetBasicInfo
(
&
dmInfo
.
basic
);
GetDnodeInfo
(
&
dmInfo
.
dnode
);
GetSysInfo
(
&
dmInfo
.
sys
);
SMonMmInfo
mmInfo
=
{
0
};
GetClusterInfo
(
&
mmInfo
.
cluster
);
GetVgroupInfo
(
&
mmInfo
.
vgroup
);
GetGrantInfo
(
&
mmInfo
.
grant
);
GetSysInfo
(
&
mmInfo
.
sys
);
GetLogInfo
(
&
mmInfo
.
logs
);
SMonVmInfo
vmInfo
=
{
0
};
GetDiskInfo
(
&
vmInfo
.
tfs
);
GetVnodeStat
(
&
vmInfo
.
vstat
);
GetSysInfo
(
&
vmInfo
.
sys
);
GetLogInfo
(
&
vmInfo
.
logs
);
SMonQmInfo
qmInfo
=
{
0
};
GetSysInfo
(
&
qmInfo
.
sys
);
GetLogInfo
(
&
qmInfo
.
logs
);
SMonSmInfo
smInfo
=
{
0
};
GetSysInfo
(
&
smInfo
.
sys
);
GetLogInfo
(
&
smInfo
.
logs
);
SMonBmInfo
bmInfo
=
{
0
};
GetSysInfo
(
&
bmInfo
.
sys
);
GetLogInfo
(
&
bmInfo
.
logs
);
monSetDmInfo
(
&
dmInfo
);
monSetMmInfo
(
&
mmInfo
);
monSetVmInfo
(
&
vmInfo
);
monSetQmInfo
(
&
qmInfo
);
monSetSmInfo
(
&
smInfo
);
monSetBmInfo
(
&
bmInfo
);
tFreeSMonMmInfo
(
&
mmInfo
);
tFreeSMonVmInfo
(
&
vmInfo
);
tFreeSMonSmInfo
(
&
smInfo
);
tFreeSMonQmInfo
(
&
qmInfo
);
tFreeSMonBmInfo
(
&
bmInfo
);
monSendReport
();
}
TEST_F
(
MonitorTest
,
02
_Log
)
{
AddLogInfo2
();
SMonInfo
*
pMonitor
=
monCreateMonitorInfo
();
if
(
pMonitor
==
NULL
)
return
;
monSendReport
(
pMonitor
);
monCleanupMonitorInfo
(
pMonitor
);
monSendReport
();
}
source/os/src/osSysinfo.c
浏览文件 @
f492ae74
...
...
@@ -129,14 +129,12 @@ static void taosGetProcIOnfos() {
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
TdFilePtr
pFile
=
taosOpenFile
(
tsSysCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsSysCpuFile);
return
-
1
;
}
char
*
line
=
NULL
;
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", tsSysCpuFile);
taosCloseFile
(
&
pFile
);
return
-
1
;
}
...
...
@@ -153,14 +151,12 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
TdFilePtr
pFile
=
taosOpenFile
(
tsProcCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsProcCpuFile);
return
-
1
;
}
char
*
line
=
NULL
;
ssize_t
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", tsProcCpuFile);
taosCloseFile
(
&
pFile
);
return
-
1
;
}
...
...
@@ -182,12 +178,12 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
#endif
bool
taosCheckSystemIsSmallEnd
()
{
union
check
{
int16_t
i
;
char
ch
[
2
];
}
c
;
c
.
i
=
1
;
return
c
.
ch
[
0
]
==
1
;
union
check
{
int16_t
i
;
char
ch
[
2
];
}
c
;
c
.
i
=
1
;
return
c
.
ch
[
0
]
==
1
;
}
void
taosGetSystemInfo
()
{
...
...
@@ -617,6 +613,28 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
#endif
}
void
taosGetProcIODelta
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
static
int64_t
last_rchars
=
0
;
static
int64_t
last_wchars
=
0
;
static
int64_t
last_read_bytes
=
0
;
static
int64_t
last_write_bytes
=
0
;
static
int64_t
cur_rchars
=
0
;
static
int64_t
cur_wchars
=
0
;
static
int64_t
cur_read_bytes
=
0
;
static
int64_t
cur_write_bytes
=
0
;
if
(
taosGetProcIO
(
&
cur_rchars
,
&
cur_wchars
,
&
cur_read_bytes
,
&
cur_write_bytes
)
!=
0
)
{
*
rchars
=
cur_rchars
-
last_rchars
;
*
wchars
=
cur_wchars
-
last_wchars
;
*
read_bytes
=
cur_read_bytes
-
last_read_bytes
;
*
write_bytes
=
cur_write_bytes
-
last_write_bytes
;
last_rchars
=
cur_rchars
;
last_wchars
=
cur_wchars
;
last_read_bytes
=
cur_read_bytes
;
last_write_bytes
=
cur_write_bytes
;
}
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
*
receive_bytes
=
0
;
...
...
@@ -672,6 +690,20 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
#endif
}
void
taosGetCardInfoDelta
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
static
int64_t
last_receive_bytes
=
0
;
static
int64_t
last_transmit_bytes
=
0
;
static
int64_t
cur_receive_bytes
=
0
;
static
int64_t
cur_transmit_bytes
=
0
;
if
(
taosGetCardInfo
(
&
cur_receive_bytes
,
&
cur_transmit_bytes
)
!=
0
)
{
*
receive_bytes
=
cur_receive_bytes
-
last_receive_bytes
;
*
transmit_bytes
=
cur_transmit_bytes
-
last_transmit_bytes
;
last_receive_bytes
=
cur_receive_bytes
;
last_transmit_bytes
=
cur_transmit_bytes
;
}
}
void
taosKillSystem
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
printf
(
"function taosKillSystem, exit!"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录