Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c890b0b5
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
c890b0b5
编写于
3月 03, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sysinfo in monitor
上级
c018e918
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
139 addition
and
141 deletion
+139
-141
include/libs/monitor/monitor.h
include/libs/monitor/monitor.h
+3
-3
include/os/osEnv.h
include/os/osEnv.h
+3
-3
include/os/osSysinfo.h
include/os/osSysinfo.h
+6
-6
source/common/src/tglobal.c
source/common/src/tglobal.c
+3
-7
source/dnode/mgmt/impl/src/dndMgmt.c
source/dnode/mgmt/impl/src/dndMgmt.c
+34
-9
source/dnode/mnode/impl/src/mndTelem.c
source/dnode/mnode/impl/src/mndTelem.c
+4
-7
source/os/src/osEnv.c
source/os/src/osEnv.c
+8
-3
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+78
-103
未找到文件。
include/libs/monitor/monitor.h
浏览文件 @
c890b0b5
...
@@ -88,9 +88,9 @@ typedef struct {
...
@@ -88,9 +88,9 @@ typedef struct {
float
cpu_engine
;
float
cpu_engine
;
float
cpu_system
;
float
cpu_system
;
float
cpu_cores
;
float
cpu_cores
;
float
mem_engine
;
// M
B
int64_t
mem_engine
;
// K
B
float
mem_system
;
// M
B
int64_t
mem_system
;
// K
B
float
mem_total
;
// M
B
int64_t
mem_total
;
// K
B
float
disk_engine
;
// GB
float
disk_engine
;
// GB
float
disk_used
;
// GB
float
disk_used
;
// GB
float
disk_total
;
// GB
float
disk_total
;
// GB
...
...
include/os/osEnv.h
浏览文件 @
c890b0b5
...
@@ -28,11 +28,11 @@ extern char tsCharset[];
...
@@ -28,11 +28,11 @@ extern char tsCharset[];
extern
char
tsLocale
[];
extern
char
tsLocale
[];
extern
int8_t
tsDaylight
;
extern
int8_t
tsDaylight
;
extern
bool
tsEnableCoreFile
;
extern
bool
tsEnableCoreFile
;
extern
int64_t
tsPageSize
;
extern
int64_t
tsPageSize
KB
;
extern
int64_t
tsOpenMax
;
extern
int64_t
tsOpenMax
;
extern
int64_t
tsStreamMax
;
extern
int64_t
tsStreamMax
;
extern
int32_t
tsNumOfCores
;
extern
float
tsNumOfCores
;
extern
int
32_t
tsTotalMemoryM
B
;
extern
int
64_t
tsTotalMemoryK
B
;
extern
char
configDir
[];
extern
char
configDir
[];
extern
char
tsDataDir
[];
extern
char
tsDataDir
[];
...
...
include/os/osSysinfo.h
浏览文件 @
c890b0b5
...
@@ -36,12 +36,12 @@ typedef struct {
...
@@ -36,12 +36,12 @@ typedef struct {
void
taosGetSystemInfo
();
void
taosGetSystemInfo
();
int32_t
taosGetEmail
(
char
*
email
,
int32_t
maxLen
);
int32_t
taosGetEmail
(
char
*
email
,
int32_t
maxLen
);
int32_t
taosGetOsReleaseName
(
char
*
releaseName
,
int32_t
maxLen
);
int32_t
taosGetOsReleaseName
(
char
*
releaseName
,
int32_t
maxLen
);
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
int32_
t
*
numOfCores
);
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
floa
t
*
numOfCores
);
int32_t
taosGetCpuCores
();
int32_t
taosGetCpuCores
(
float
*
numOfCores
);
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsag
e
);
int32_t
taosGetCpuUsage
(
float
*
cpu_system
,
float
*
cpu_engin
e
);
bool
taosGetTotalSysMemoryKB
(
uint64_t
*
kb
);
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
);
bool
taosGetProcMemory
(
float
*
memoryUsedMB
);
//
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
);
bool
taosGetSysMemory
(
float
*
memoryUsedMB
);
//
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
);
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
);
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
);
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
);
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
);
bool
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
);
bool
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
);
...
...
source/common/src/tglobal.c
浏览文件 @
c890b0b5
...
@@ -279,11 +279,11 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
...
@@ -279,11 +279,11 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
if
(
cfgAddLocale
(
pCfg
,
"locale"
,
tsLocale
)
!=
0
)
return
-
1
;
if
(
cfgAddLocale
(
pCfg
,
"locale"
,
tsLocale
)
!=
0
)
return
-
1
;
if
(
cfgAddCharset
(
pCfg
,
"charset"
,
tsCharset
)
!=
0
)
return
-
1
;
if
(
cfgAddCharset
(
pCfg
,
"charset"
,
tsCharset
)
!=
0
)
return
-
1
;
if
(
cfgAddBool
(
pCfg
,
"enableCoreFile"
,
1
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddBool
(
pCfg
,
"enableCoreFile"
,
1
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"numOfCores"
,
tsNumOfCores
,
1
,
100000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddFloat
(
pCfg
,
"numOfCores"
,
tsNumOfCores
,
0
,
100000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"pageSize(KB)"
,
tsPageSize
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"openMax"
,
tsOpenMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"openMax"
,
tsOpenMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"streamMax"
,
tsStreamMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"streamMax"
,
tsStreamMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"totalMemory(MB)"
,
tsTotalMemoryMB
,
0
,
INT32_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"pageSize(KB)"
,
tsPageSizeKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"totalMemory(KB)"
,
tsTotalMemoryKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os sysname"
,
info
.
sysname
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os sysname"
,
info
.
sysname
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os nodename"
,
info
.
nodename
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os nodename"
,
info
.
nodename
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os release"
,
info
.
release
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os release"
,
info
.
release
,
1
)
!=
0
)
return
-
1
;
...
@@ -404,10 +404,6 @@ static void taosSetSystemCfg(SConfig *pCfg) {
...
@@ -404,10 +404,6 @@ static void taosSetSystemCfg(SConfig *pCfg) {
const
char
*
charset
=
cfgGetItem
(
pCfg
,
"charset"
)
->
str
;
const
char
*
charset
=
cfgGetItem
(
pCfg
,
"charset"
)
->
str
;
taosSetSystemLocale
(
locale
,
charset
);
taosSetSystemLocale
(
locale
,
charset
);
if
(
tsNumOfCores
<=
1
)
{
tsNumOfCores
=
2
;
}
bool
enableCore
=
cfgGetItem
(
pCfg
,
"enableCoreFile"
)
->
bval
;
bool
enableCore
=
cfgGetItem
(
pCfg
,
"enableCoreFile"
)
->
bval
;
taosSetConsoleEcho
(
enableCore
);
taosSetConsoleEcho
(
enableCore
);
...
...
source/dnode/mgmt/impl/src/dndMgmt.c
浏览文件 @
c890b0b5
...
@@ -474,13 +474,40 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
...
@@ -474,13 +474,40 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
rpcSendResponse
(
&
rpcRsp
);
rpcSendResponse
(
&
rpcRsp
);
}
}
static
int32_t
dndGetMonitorBasicInfo
(
SDnode
*
pDnode
,
SMonBasicInfo
*
pInfo
)
{
static
void
dndGetMonitorBasicInfo
(
SDnode
*
pDnode
,
SMonBasicInfo
*
pInfo
)
{
pInfo
->
dnode_id
=
dndGetDnodeId
(
pDnode
);
pInfo
->
dnode_id
=
dndGetDnodeId
(
pDnode
);
tstrncpy
(
pInfo
->
dnode_ep
,
tsLocalEp
,
TSDB_EP_LEN
);
tstrncpy
(
pInfo
->
dnode_ep
,
tsLocalEp
,
TSDB_EP_LEN
);
return
0
;
}
}
static
int32_t
dndGetMonitorDnodeInfo
(
SDnode
*
pDnode
,
SMonDnodeInfo
*
pInfo
)
{
return
0
;
}
static
void
dndGetMonitorDnodeInfo
(
SDnode
*
pDnode
,
SMonDnodeInfo
*
pInfo
)
{
pInfo
->
uptime
=
(
taosGetTimestampMs
()
-
pDnode
->
dmgmt
.
rebootTime
)
/
(
86400000
.
0
f
);
taosGetCpuUsage
(
&
pInfo
->
cpu_engine
,
&
pInfo
->
cpu_system
);
pInfo
->
cpu_cores
=
tsNumOfCores
;
taosGetProcMemory
(
&
pInfo
->
mem_engine
);
taosGetSysMemory
(
&
pInfo
->
mem_system
);
pInfo
->
mem_total
=
tsTotalMemoryKB
;
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_select_rate
=
8
.
1
;
pInfo
->
req_insert
=
9
;
pInfo
->
req_insert_success
=
10
;
pInfo
->
req_insert_rate
=
10
.
1
;
pInfo
->
req_insert_batch
=
11
;
pInfo
->
req_insert_batch_success
=
12
;
pInfo
->
req_insert_batch_rate
=
12
.
3
;
pInfo
->
errors
=
4
;
pInfo
->
vnodes_num
=
5
;
pInfo
->
masters
=
6
;
pInfo
->
has_mnode
=
1
;
}
static
void
dndSendMonitorReport
(
SDnode
*
pDnode
)
{
static
void
dndSendMonitorReport
(
SDnode
*
pDnode
)
{
if
(
!
tsEnableMonitor
||
tsMonitorFqdn
[
0
]
==
0
||
tsMonitorPort
==
0
)
return
;
if
(
!
tsEnableMonitor
||
tsMonitorFqdn
[
0
]
==
0
||
tsMonitorPort
==
0
)
return
;
...
@@ -490,9 +517,8 @@ static void dndSendMonitorReport(SDnode *pDnode) {
...
@@ -490,9 +517,8 @@ static void dndSendMonitorReport(SDnode *pDnode) {
if
(
pMonitor
==
NULL
)
return
;
if
(
pMonitor
==
NULL
)
return
;
SMonBasicInfo
basicInfo
=
{
0
};
SMonBasicInfo
basicInfo
=
{
0
};
if
(
dndGetMonitorBasicInfo
(
pDnode
,
&
basicInfo
)
==
0
)
{
dndGetMonitorBasicInfo
(
pDnode
,
&
basicInfo
);
monSetBasicInfo
(
pMonitor
,
&
basicInfo
);
monSetBasicInfo
(
pMonitor
,
&
basicInfo
);
}
SMonClusterInfo
clusterInfo
=
{
0
};
SMonClusterInfo
clusterInfo
=
{
0
};
SMonVgroupInfo
vgroupInfo
=
{
0
};
SMonVgroupInfo
vgroupInfo
=
{
0
};
...
@@ -504,9 +530,8 @@ static void dndSendMonitorReport(SDnode *pDnode) {
...
@@ -504,9 +530,8 @@ static void dndSendMonitorReport(SDnode *pDnode) {
}
}
SMonDnodeInfo
dnodeInfo
=
{
0
};
SMonDnodeInfo
dnodeInfo
=
{
0
};
if
(
dndGetMonitorDnodeInfo
(
pDnode
,
&
dnodeInfo
)
==
0
)
{
dndGetMonitorDnodeInfo
(
pDnode
,
&
dnodeInfo
);
monSetDnodeInfo
(
pMonitor
,
&
dnodeInfo
);
monSetDnodeInfo
(
pMonitor
,
&
dnodeInfo
);
}
SMonDiskInfo
diskInfo
=
{
0
};
SMonDiskInfo
diskInfo
=
{
0
};
if
(
dndGetMonitorDiskInfo
(
pDnode
,
&
diskInfo
)
==
0
)
{
if
(
dndGetMonitorDiskInfo
(
pDnode
,
&
diskInfo
)
==
0
)
{
...
...
source/dnode/mnode/impl/src/mndTelem.c
浏览文件 @
c890b0b5
...
@@ -56,19 +56,16 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
...
@@ -56,19 +56,16 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
tjsonAddStringToObject
(
pJson
,
"os"
,
tmp
);
tjsonAddStringToObject
(
pJson
,
"os"
,
tmp
);
}
}
int32_
t
numOfCores
=
0
;
floa
t
numOfCores
=
0
;
if
(
taosGetCpuInfo
(
tmp
,
sizeof
(
tmp
),
&
numOfCores
)
==
0
)
{
if
(
taosGetCpuInfo
(
tmp
,
sizeof
(
tmp
),
&
numOfCores
)
==
0
)
{
tjsonAddStringToObject
(
pJson
,
"cpuModel"
,
tmp
);
tjsonAddStringToObject
(
pJson
,
"cpuModel"
,
tmp
);
tjsonAddDoubleToObject
(
pJson
,
"numOfCpu"
,
numOfCores
);
tjsonAddDoubleToObject
(
pJson
,
"numOfCpu"
,
numOfCores
);
}
else
{
}
else
{
tjsonAddDoubleToObject
(
pJson
,
"numOfCpu"
,
t
aosGetCpuCores
()
);
tjsonAddDoubleToObject
(
pJson
,
"numOfCpu"
,
t
sNumOfCores
);
}
}
uint64_t
memoryKB
=
0
;
snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
PRId64
" kB"
,
tsTotalMemoryKB
);
if
(
taosGetTotalSysMemoryKB
(
&
memoryKB
))
{
tjsonAddStringToObject
(
pJson
,
"memory"
,
tmp
);
snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
PRIu64
" kB"
,
memoryKB
);
tjsonAddStringToObject
(
pJson
,
"memory"
,
tmp
);
}
tjsonAddStringToObject
(
pJson
,
"version"
,
version
);
tjsonAddStringToObject
(
pJson
,
"version"
,
version
);
tjsonAddStringToObject
(
pJson
,
"buildInfo"
,
buildinfo
);
tjsonAddStringToObject
(
pJson
,
"buildInfo"
,
buildinfo
);
...
...
source/os/src/osEnv.c
浏览文件 @
c890b0b5
...
@@ -31,11 +31,11 @@ char tsLocale[TD_LOCALE_LEN] = {0};
...
@@ -31,11 +31,11 @@ char tsLocale[TD_LOCALE_LEN] = {0};
char
tsCharset
[
TD_CHARSET_LEN
]
=
{
0
};
char
tsCharset
[
TD_CHARSET_LEN
]
=
{
0
};
int8_t
tsDaylight
=
0
;
int8_t
tsDaylight
=
0
;
bool
tsEnableCoreFile
=
0
;
bool
tsEnableCoreFile
=
0
;
int64_t
tsPageSize
=
0
;
int64_t
tsPageSize
KB
=
0
;
int64_t
tsOpenMax
=
0
;
int64_t
tsOpenMax
=
0
;
int64_t
tsStreamMax
=
0
;
int64_t
tsStreamMax
=
0
;
int32_t
tsNumOfCores
=
0
;
float
tsNumOfCores
=
0
;
int
32_t
tsTotalMemoryM
B
=
0
;
int
64_t
tsTotalMemoryK
B
=
0
;
void
osInit
()
{
void
osInit
()
{
srand
(
taosSafeRand
());
srand
(
taosSafeRand
());
...
@@ -44,6 +44,11 @@ void osInit() {
...
@@ -44,6 +44,11 @@ void osInit() {
taosSetSystemTimezone
(
tsTimezone
,
tsTimezone
,
&
tsDaylight
);
taosSetSystemTimezone
(
tsTimezone
,
tsTimezone
,
&
tsDaylight
);
taosGetSystemInfo
();
taosGetSystemInfo
();
// deadlock in query
if
(
tsNumOfCores
<
2
)
{
tsNumOfCores
=
2
;
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
taosWinSocketInit
();
taosWinSocketInit
();
...
...
source/os/src/osSysinfo.c
浏览文件 @
c890b0b5
...
@@ -39,32 +39,32 @@
...
@@ -39,32 +39,32 @@
#include <DbgHelp.h>
#include <DbgHelp.h>
#pragma warning(pop)
#pragma warning(pop)
static
int32_t
taosGetTotalMemory
(
)
{
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
MEMORYSTATUSEX
memsStat
;
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
0
;
return
-
1
;
}
}
float
nMemTotal
=
memsStat
.
ullTotalPhys
/
(
1024
.
0
f
*
1024
.
0
f
)
;
*
totalKB
=
memsStat
.
ullTotalPhys
/
1024
;
return
(
int32_t
)
nMemTotal
;
return
0
;
}
}
bool
taosGetSysMemory
(
float
*
memoryUsedM
B
)
{
int32_t
taosGetSysMemory
(
int64_t
*
usedK
B
)
{
MEMORYSTATUSEX
memsStat
;
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
return
false
;
return
-
1
;
}
}
float
nMemFree
=
memsStat
.
ullAvailPhys
/
(
1024
.
0
f
*
1024
.
0
f
)
;
int64_t
nMemFree
=
memsStat
.
ullAvailPhys
/
1024
;
float
nMemTotal
=
memsStat
.
ullTotalPhys
/
(
1024
.
0
f
*
1024
.
0
f
)
;
int64_t
nMemTotal
=
memsStat
.
ullTotalPhys
/
1024
.
0
;
*
memoryUsedM
B
=
nMemTotal
-
nMemFree
;
*
usedK
B
=
nMemTotal
-
nMemFree
;
return
true
;
return
0
;
}
}
bool
taosGetProcMemory
(
float
*
memoryUsedM
B
)
{
int32_t
taosGetProcMemory
(
int64_t
*
usedK
B
)
{
unsigned
bytes_used
=
0
;
unsigned
bytes_used
=
0
;
#if defined(_WIN64) && defined(_MSC_VER)
#if defined(_WIN64) && defined(_MSC_VER)
...
@@ -76,20 +76,21 @@ bool taosGetProcMemory(float *memoryUsedMB) {
...
@@ -76,20 +76,21 @@ bool taosGetProcMemory(float *memoryUsedMB) {
}
}
#endif
#endif
*
memoryUsedMB
=
(
float
)
bytes_used
/
1024
/
1024
;
*
usedKB
=
bytes_used
/
1024
;
return
true
;
return
0
;
}
}
int32_t
taosGetCpuCores
()
{
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
SYSTEM_INFO
info
;
SYSTEM_INFO
info
;
GetSystemInfo
(
&
info
);
GetSystemInfo
(
&
info
);
return
(
int32_t
)
info
.
dwNumberOfProcessors
;
*
numOfCores
=
info
.
dwNumberOfProcessors
;
return
0
;
}
}
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
int32_t
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
true
;
return
0
;
}
}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
...
@@ -162,8 +163,8 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
...
@@ -162,8 +163,8 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
}
}
void
taosGetSystemInfo
()
{
void
taosGetSystemInfo
()
{
t
sNumOfCores
=
taosGetCpuCores
(
);
t
aosGetCpuCores
(
&
tsNumOfCores
);
t
sTotalMemoryMB
=
taosGetTotalMemory
(
);
t
aosGetTotalMemory
(
&
tsTotalMemoryKB
);
float
tmp1
,
tmp2
;
float
tmp1
,
tmp2
;
taosGetBandSpeed
(
&
tmp1
);
taosGetBandSpeed
(
&
tmp1
);
...
@@ -245,16 +246,17 @@ void taosKillSystem() {
...
@@ -245,16 +246,17 @@ void taosKillSystem() {
exit
(
0
);
exit
(
0
);
}
}
int32_t
taosGetCpuCores
()
{
return
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
return
0
;
}
void
taosGetSystemInfo
()
{
void
taosGetSystemInfo
()
{
// taosGetProcInfos();
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
long
physical_pages
=
sysconf
(
_SC_PHYS_PAGES
);
long
physical_pages
=
sysconf
(
_SC_PHYS_PAGES
);
long
page_size
=
sysconf
(
_SC_PAGESIZE
);
long
page_size
=
sysconf
(
_SC_PAGESIZE
);
tsTotalMemoryMB
=
physical_pages
*
page_size
/
(
1024
*
1024
);
tsTotalMemoryKB
=
physical_pages
*
page_size
/
1024
;
tsPageSize
=
page_size
;
tsPageSizeKB
=
page_size
/
1024
;
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
}
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
)
{
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
)
{
...
@@ -281,20 +283,20 @@ bool taosGetBandSpeed(float *bandSpeedKb) {
...
@@ -281,20 +283,20 @@ bool taosGetBandSpeed(float *bandSpeedKb) {
return
true
;
return
true
;
}
}
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
int32_t
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
true
;
return
0
;
}
}
bool
taosGetProcMemory
(
float
*
memoryUsedM
B
)
{
int32_t
taosGetProcMemory
(
int64_t
*
usedK
B
)
{
*
memoryUsedM
B
=
0
;
*
usedK
B
=
0
;
return
true
;
return
0
;
}
}
bool
taosGetSysMemory
(
float
*
memoryUsedM
B
)
{
int32_t
taosGetSysMemory
(
int64_t
*
usedK
B
)
{
*
memoryUsedM
B
=
0
;
*
usedK
B
=
0
;
return
true
;
return
0
;
}
}
int
taosSystem
(
const
char
*
cmd
)
{
int
taosSystem
(
const
char
*
cmd
)
{
...
@@ -375,35 +377,34 @@ static char tsSysCpuFile[] = "/proc/stat";
...
@@ -375,35 +377,34 @@ static char tsSysCpuFile[] = "/proc/stat";
static
char
tsProcCpuFile
[
25
]
=
{
0
};
static
char
tsProcCpuFile
[
25
]
=
{
0
};
static
char
tsProcMemFile
[
25
]
=
{
0
};
static
char
tsProcMemFile
[
25
]
=
{
0
};
static
char
tsProcIOFile
[
25
]
=
{
0
};
static
char
tsProcIOFile
[
25
]
=
{
0
};
static
float
tsPageSizeKB
=
0
;
static
void
taosGetProcInfos
()
{
static
void
taosGetProcInfos
()
{
tsPageSize
=
sysconf
(
_SC_PAGESIZE
)
;
tsPageSize
KB
=
sysconf
(
_SC_PAGESIZE
)
/
1024
;
tsOpenMax
=
sysconf
(
_SC_OPEN_MAX
);
tsOpenMax
=
sysconf
(
_SC_OPEN_MAX
);
tsStreamMax
=
sysconf
(
_SC_STREAM_MAX
);
tsStreamMax
=
sysconf
(
_SC_STREAM_MAX
);
tsProcId
=
(
pid_t
)
syscall
(
SYS_gettid
);
tsProcId
=
(
pid_t
)
syscall
(
SYS_gettid
);
tsPageSizeKB
=
(
float
)(
sysconf
(
_SC_PAGESIZE
))
/
1024
;
snprintf
(
tsProcMemFile
,
25
,
"/proc/%d/status"
,
tsProcId
);
snprintf
(
tsProcMemFile
,
sizeof
(
tsProcMemFile
)
,
"/proc/%d/status"
,
tsProcId
);
snprintf
(
tsProcCpuFile
,
25
,
"/proc/%d/stat"
,
tsProcId
);
snprintf
(
tsProcCpuFile
,
sizeof
(
tsProcCpuFile
)
,
"/proc/%d/stat"
,
tsProcId
);
snprintf
(
tsProcIOFile
,
25
,
"/proc/%d/io"
,
tsProcId
);
snprintf
(
tsProcIOFile
,
sizeof
(
tsProcIOFile
)
,
"/proc/%d/io"
,
tsProcId
);
}
}
static
int32_t
taosGetTotalMemory
()
{
return
(
int32_t
)((
float
)
sysconf
(
_SC_PHYS_PAGES
)
*
tsPageSizeKB
/
1024
);
}
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
*
totalKB
=
(
int64_t
)(
sysconf
(
_SC_PHYS_PAGES
)
*
tsPageSizeKB
);
return
0
;
}
bool
taosGetSysMemory
(
float
*
memoryUsedMB
)
{
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
float
memoryAvailMB
=
(
float
)
sysconf
(
_SC_AVPHYS_PAGES
)
*
tsPageSizeKB
/
1024
;
*
usedKB
=
sysconf
(
_SC_AVPHYS_PAGES
)
*
tsPageSizeKB
;
*
memoryUsedMB
=
(
float
)
tsTotalMemoryMB
-
memoryAvailMB
;
return
0
;
return
true
;
}
}
bool
taosGetProcMemory
(
float
*
memoryUsedM
B
)
{
int32_t
taosGetProcMemory
(
int64_t
*
usedK
B
)
{
// FILE *fp = fopen(tsProcMemFile, "r");
// FILE *fp = fopen(tsProcMemFile, "r");
TdFilePtr
pFile
=
taosOpenFile
(
tsProcMemFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsProcMemFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsProcMemFile);
// printf("open file:%s failed", tsProcMemFile);
return
false
;
return
-
1
;
}
}
ssize_t
_bytes
=
0
;
ssize_t
_bytes
=
0
;
...
@@ -421,25 +422,23 @@ bool taosGetProcMemory(float *memoryUsedMB) {
...
@@ -421,25 +422,23 @@ bool taosGetProcMemory(float *memoryUsedMB) {
if
(
line
==
NULL
)
{
if
(
line
==
NULL
)
{
// printf("read file:%s failed", tsProcMemFile);
// printf("read file:%s failed", tsProcMemFile);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
false
;
return
-
1
;
}
}
int64_t
memKB
=
0
;
char
tmp
[
10
];
char
tmp
[
10
];
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
usedKB
);
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
&
memKB
);
*
memoryUsedMB
=
(
float
)((
double
)
memKB
/
1024
);
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
true
;
return
0
;
}
}
static
bool
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
// FILE *fp = fopen(tsSysCpuFile, "r");
// FILE *fp = fopen(tsSysCpuFile, "r");
TdFilePtr
pFile
=
taosOpenFile
(
tsSysCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsSysCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsSysCpuFile);
// printf("open file:%s failed", tsSysCpuFile);
return
false
;
return
-
1
;
}
}
char
*
line
=
NULL
;
char
*
line
=
NULL
;
...
@@ -447,7 +446,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
...
@@ -447,7 +446,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", tsSysCpuFile);
// printf("read file:%s failed", tsSysCpuFile);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
false
;
return
-
1
;
}
}
char
cpu
[
10
]
=
{
0
};
char
cpu
[
10
]
=
{
0
};
...
@@ -456,15 +455,15 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
...
@@ -456,15 +455,15 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
true
;
return
0
;
}
}
static
bool
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
// FILE *fp = fopen(tsProcCpuFile, "r");
// FILE *fp = fopen(tsProcCpuFile, "r");
TdFilePtr
pFile
=
taosOpenFile
(
tsProcCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsProcCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
// printf("open file:%s failed", tsProcCpuFile);
// printf("open file:%s failed", tsProcCpuFile);
return
false
;
return
-
1
;
}
}
char
*
line
=
NULL
;
char
*
line
=
NULL
;
...
@@ -472,7 +471,7 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
...
@@ -472,7 +471,7 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
if
((
_bytes
<
0
)
||
(
line
==
NULL
))
{
// printf("read file:%s failed", tsProcCpuFile);
// printf("read file:%s failed", tsProcCpuFile);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
false
;
return
-
1
;
}
}
for
(
int
i
=
0
,
blank
=
0
;
line
[
i
]
!=
0
;
++
i
)
{
for
(
int
i
=
0
,
blank
=
0
;
line
[
i
]
!=
0
;
++
i
)
{
...
@@ -486,23 +485,26 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
...
@@ -486,23 +485,26 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
return
true
;
return
0
;
}
}
int32_t
taosGetCpuCores
()
{
return
(
int32_t
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
*
numOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
return
0
;
}
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsag
e
)
{
int32_t
taosGetCpuUsage
(
float
*
cpu_system
,
float
*
cpu_engin
e
)
{
static
uint64_t
lastSysUsed
=
0
;
static
uint64_t
lastSysUsed
=
0
;
static
uint64_t
lastSysTotal
=
0
;
static
uint64_t
lastSysTotal
=
0
;
static
uint64_t
lastProcTotal
=
0
;
static
uint64_t
lastProcTotal
=
0
;
SysCpuInfo
sysCpu
;
SysCpuInfo
sysCpu
;
ProcCpuInfo
procCpu
;
ProcCpuInfo
procCpu
;
if
(
!
taosGetSysCpuInfo
(
&
sysCpu
)
)
{
if
(
taosGetSysCpuInfo
(
&
sysCpu
)
!=
0
)
{
return
false
;
return
-
1
;
}
}
if
(
!
taosGetProcCpuInfo
(
&
procCpu
)
)
{
if
(
taosGetProcCpuInfo
(
&
procCpu
)
!=
0
)
{
return
false
;
return
-
1
;
}
}
uint64_t
curSysUsed
=
sysCpu
.
user
+
sysCpu
.
nice
+
sysCpu
.
system
;
uint64_t
curSysUsed
=
sysCpu
.
user
+
sysCpu
.
nice
+
sysCpu
.
system
;
...
@@ -513,21 +515,21 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
...
@@ -513,21 +515,21 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
lastSysUsed
=
curSysUsed
>
1
?
curSysUsed
:
1
;
lastSysUsed
=
curSysUsed
>
1
?
curSysUsed
:
1
;
lastSysTotal
=
curSysTotal
>
1
?
curSysTotal
:
1
;
lastSysTotal
=
curSysTotal
>
1
?
curSysTotal
:
1
;
lastProcTotal
=
curProcTotal
>
1
?
curProcTotal
:
1
;
lastProcTotal
=
curProcTotal
>
1
?
curProcTotal
:
1
;
return
false
;
return
-
1
;
}
}
if
(
curSysTotal
==
lastSysTotal
)
{
if
(
curSysTotal
==
lastSysTotal
)
{
return
false
;
return
-
1
;
}
}
*
sysCpuUsag
e
=
(
float
)((
double
)(
curSysUsed
-
lastSysUsed
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
);
*
cpu_engin
e
=
(
float
)((
double
)(
curSysUsed
-
lastSysUsed
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
);
*
procCpuUsage
=
(
float
)((
double
)(
curProcTotal
-
lastProcTotal
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
);
*
cpu_system
=
(
float
)((
double
)(
curProcTotal
-
lastProcTotal
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
);
lastSysUsed
=
curSysUsed
;
lastSysUsed
=
curSysUsed
;
lastSysTotal
=
curSysTotal
;
lastSysTotal
=
curSysTotal
;
lastProcTotal
=
curProcTotal
;
lastProcTotal
=
curProcTotal
;
return
true
;
return
0
;
}
}
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
)
{
...
@@ -700,13 +702,10 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
...
@@ -700,13 +702,10 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
void
taosGetSystemInfo
()
{
void
taosGetSystemInfo
()
{
taosGetProcInfos
();
taosGetProcInfos
();
taosGetCpuCores
(
&
tsNumOfCores
);
tsNumOfCores
=
taosGetCpuCores
();
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
tsTotalMemoryMB
=
taosGetTotalMemory
();
float
tmp1
,
tmp2
;
float
tmp1
,
tmp2
;
taosGetSysMemory
(
&
tmp1
);
taosGetProcMemory
(
&
tmp2
);
taosGetBandSpeed
(
&
tmp1
);
taosGetBandSpeed
(
&
tmp1
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGetProcIO
(
&
tmp1
,
&
tmp2
);
taosGetProcIO
(
&
tmp1
,
&
tmp2
);
...
@@ -923,7 +922,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
...
@@ -923,7 +922,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
return
code
;
return
code
;
}
}
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
int32_
t
*
numOfCores
)
{
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
floa
t
*
numOfCores
)
{
char
*
line
=
NULL
;
char
*
line
=
NULL
;
size_t
size
=
0
;
size_t
size
=
0
;
int32_t
done
=
0
;
int32_t
done
=
0
;
...
@@ -941,7 +940,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
...
@@ -941,7 +940,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
done
|=
1
;
done
|=
1
;
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
*
numOfCores
=
ato
i
(
v
);
*
numOfCores
=
ato
f
(
v
);
done
|=
2
;
done
|=
2
;
}
}
}
}
...
@@ -952,28 +951,4 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
...
@@ -952,28 +951,4 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
return
code
;
return
code
;
}
}
bool
taosGetTotalSysMemoryKB
(
uint64_t
*
kb
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
bool
ret
=
false
;
TdFilePtr
pFile
=
taosOpenFile
(
"/proc/meminfo"
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
return
false
;
while
((
size
=
taosGetLineFile
(
pFile
,
&
line
))
!=
-
1
)
{
line
[
size
-
1
]
=
'\0'
;
if
(
strncmp
(
line
,
"MemTotal"
,
8
)
==
0
)
{
const
char
*
p
=
strchr
(
line
,
':'
)
+
1
;
while
(
*
p
==
' '
)
p
++
;
ret
=
true
;
*
kb
=
atoll
(
p
);
break
;
}
}
if
(
line
!=
NULL
)
free
(
line
);
taosCloseFile
(
&
pFile
);
return
ret
;
}
#endif
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录