Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9f33b3ea
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
9f33b3ea
编写于
3月 05, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
3月 05, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10564 from taosdata/feature/config
sysinfo for monitor
上级
23521373
a11a2f37
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
129 addition
and
157 deletion
+129
-157
include/libs/monitor/monitor.h
include/libs/monitor/monitor.h
+14
-14
include/os/osSysinfo.h
include/os/osSysinfo.h
+5
-5
source/dnode/mgmt/impl/inc/dndEnv.h
source/dnode/mgmt/impl/inc/dndEnv.h
+1
-0
source/dnode/mgmt/impl/src/dndMgmt.c
source/dnode/mgmt/impl/src/dndMgmt.c
+7
-9
source/dnode/mgmt/impl/src/dndVnodes.c
source/dnode/mgmt/impl/src/dndVnodes.c
+7
-0
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+95
-129
未找到文件。
include/libs/monitor/monitor.h
浏览文件 @
9f33b3ea
...
@@ -86,21 +86,21 @@ typedef struct {
...
@@ -86,21 +86,21 @@ typedef struct {
typedef
struct
{
typedef
struct
{
float
uptime
;
// day
float
uptime
;
// day
float
cpu_engine
;
double
cpu_engine
;
float
cpu_system
;
double
cpu_system
;
float
cpu_cores
;
float
cpu_cores
;
int64_t
mem_engine
;
// KB
int64_t
mem_engine
;
// KB
int64_t
mem_system
;
// KB
int64_t
mem_system
;
// KB
int64_t
mem_total
;
// KB
int64_t
mem_total
;
// KB
float
disk_engine
;
// GB
int64_t
disk_engine
;
// Byte
float
disk_used
;
// GB
int64_t
disk_used
;
// Byte
float
disk_total
;
// GB
int64_t
disk_total
;
// Byte
int64_t
net_in
;
double
net_in
;
// bytes per second
int64_t
net_out
;
double
net_out
;
// bytes per second
float
io_read
;
double
io_read
;
float
io_write
;
double
io_write
;
float
io_read_disk
;
double
io_read_disk
;
float
io_write_disk
;
double
io_write_disk
;
int32_t
req_select
;
int32_t
req_select
;
float
req_select_rate
;
float
req_select_rate
;
int32_t
req_insert
;
int32_t
req_insert
;
...
...
include/os/osSysinfo.h
浏览文件 @
9f33b3ea
...
@@ -38,15 +38,15 @@ int32_t taosGetEmail(char *email, int32_t maxLen);
...
@@ -38,15 +38,15 @@ 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
,
float
*
numOfCores
);
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
float
*
numOfCores
);
int32_t
taosGetCpuCores
(
float
*
numOfCores
);
int32_t
taosGetCpuCores
(
float
*
numOfCores
);
int32_t
taosGetCpuUsage
(
float
*
cpu_system
,
float
*
cpu_engine
);
int32_t
taosGetCpuUsage
(
double
*
cpu_system
,
double
*
cpu_engine
);
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
);
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
);
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
);
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
);
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
);
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
);
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
);
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SDiskSize
*
diskSize
);
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
);
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
);
int32_t
taosGet
ProcIO
(
float
*
readKB
,
float
*
write
KB
);
int32_t
taosGet
IOSpeed
(
double
*
readKB
,
double
*
writeKB
,
double
*
readDiskKB
,
double
*
writeDisk
KB
);
int32_t
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
t
bytes
);
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_
bytes
);
int32_t
taosGetBandSpeed
(
float
*
bandSpeedKb
);
int32_t
taosGetBandSpeed
(
double
*
receive_bytes_per_sec
,
double
*
transmit_bytes_per_sec
);
int32_t
taosSystem
(
const
char
*
cmd
);
int32_t
taosSystem
(
const
char
*
cmd
);
void
taosKillSystem
();
void
taosKillSystem
();
...
...
source/dnode/mgmt/impl/inc/dndEnv.h
浏览文件 @
9f33b3ea
...
@@ -108,6 +108,7 @@ typedef struct {
...
@@ -108,6 +108,7 @@ typedef struct {
SHashObj
*
hash
;
SHashObj
*
hash
;
int32_t
openVnodes
;
int32_t
openVnodes
;
int32_t
totalVnodes
;
int32_t
totalVnodes
;
int32_t
masterNum
;
SRWLatch
latch
;
SRWLatch
latch
;
SQWorkerPool
queryPool
;
SQWorkerPool
queryPool
;
SFWorkerPool
fetchPool
;
SFWorkerPool
fetchPool
;
...
...
source/dnode/mgmt/impl/src/dndMgmt.c
浏览文件 @
9f33b3ea
...
@@ -487,12 +487,10 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
...
@@ -487,12 +487,10 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
taosGetSysMemory
(
&
pInfo
->
mem_system
);
taosGetSysMemory
(
&
pInfo
->
mem_system
);
pInfo
->
mem_total
=
tsTotalMemoryKB
;
pInfo
->
mem_total
=
tsTotalMemoryKB
;
pInfo
->
disk_engine
=
0
;
pInfo
->
disk_engine
=
0
;
pInfo
->
disk_used
=
tsDataSpace
.
size
.
used
/
(
1024
*
1024
*
1024
.
0
);
pInfo
->
disk_used
=
tsDataSpace
.
size
.
used
;
pInfo
->
disk_total
=
tsDataSpace
.
size
.
avail
/
(
1024
*
1024
*
1024
.
0
);
pInfo
->
disk_total
=
tsDataSpace
.
size
.
total
;
taosGetCardInfo
(
NULL
,
&
pInfo
->
net_in
,
&
pInfo
->
net_out
);
taosGetBandSpeed
(
&
pInfo
->
net_in
,
&
pInfo
->
net_out
);
taosGetProcIO
(
&
pInfo
->
io_read
,
&
pInfo
->
io_write
);
taosGetIOSpeed
(
&
pInfo
->
io_read
,
&
pInfo
->
io_write
,
&
pInfo
->
io_read_disk
,
&
pInfo
->
io_write_disk
);
pInfo
->
io_read_disk
=
0
;
pInfo
->
io_write_disk
=
0
;
pInfo
->
req_select
=
0
;
pInfo
->
req_select
=
0
;
pInfo
->
req_select_rate
=
0
;
pInfo
->
req_select_rate
=
0
;
pInfo
->
req_insert
=
0
;
pInfo
->
req_insert
=
0
;
...
@@ -501,9 +499,9 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
...
@@ -501,9 +499,9 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
pInfo
->
req_insert_batch
=
0
;
pInfo
->
req_insert_batch
=
0
;
pInfo
->
req_insert_batch_success
=
0
;
pInfo
->
req_insert_batch_success
=
0
;
pInfo
->
req_insert_batch_rate
=
0
;
pInfo
->
req_insert_batch_rate
=
0
;
pInfo
->
errors
=
0
;
pInfo
->
errors
=
tsNumOfErrorLogs
;
pInfo
->
vnodes_num
=
0
;
pInfo
->
vnodes_num
=
pDnode
->
vmgmt
.
totalVnodes
;
pInfo
->
masters
=
0
;
pInfo
->
masters
=
pDnode
->
vmgmt
.
masterNum
;
pInfo
->
has_mnode
=
dndIsMnode
(
pDnode
);
pInfo
->
has_mnode
=
dndIsMnode
(
pDnode
);
}
}
...
...
source/dnode/mgmt/impl/src/dndVnodes.c
浏览文件 @
9f33b3ea
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include "dndVnodes.h"
#include "dndVnodes.h"
#include "dndMgmt.h"
#include "dndMgmt.h"
#include "dndTransport.h"
#include "dndTransport.h"
#include "sync.h"
typedef
struct
{
typedef
struct
{
int32_t
vgId
;
int32_t
vgId
;
...
@@ -979,6 +980,8 @@ void dndCleanupVnodes(SDnode *pDnode) {
...
@@ -979,6 +980,8 @@ void dndCleanupVnodes(SDnode *pDnode) {
void
dndGetVnodeLoads
(
SDnode
*
pDnode
,
SArray
*
pLoads
)
{
void
dndGetVnodeLoads
(
SDnode
*
pDnode
,
SArray
*
pLoads
)
{
SVnodesMgmt
*
pMgmt
=
&
pDnode
->
vmgmt
;
SVnodesMgmt
*
pMgmt
=
&
pDnode
->
vmgmt
;
int32_t
totalVnodes
=
0
;
int32_t
masterNum
=
0
;
taosRLockLatch
(
&
pMgmt
->
latch
);
taosRLockLatch
(
&
pMgmt
->
latch
);
...
@@ -993,8 +996,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) {
...
@@ -993,8 +996,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) {
vnodeGetLoad
(
pVnode
->
pImpl
,
&
vload
);
vnodeGetLoad
(
pVnode
->
pImpl
,
&
vload
);
taosArrayPush
(
pLoads
,
&
vload
);
taosArrayPush
(
pLoads
,
&
vload
);
totalVnodes
++
;
if
(
vload
.
role
==
TAOS_SYNC_STATE_LEADER
)
masterNum
++
;
pIter
=
taosHashIterate
(
pMgmt
->
hash
,
pIter
);
pIter
=
taosHashIterate
(
pMgmt
->
hash
,
pIter
);
}
}
taosRUnLockLatch
(
&
pMgmt
->
latch
);
taosRUnLockLatch
(
&
pMgmt
->
latch
);
pMgmt
->
totalVnodes
=
totalVnodes
;
pMgmt
->
masterNum
=
masterNum
;
}
}
source/os/src/osSysinfo.c
浏览文件 @
9f33b3ea
...
@@ -87,7 +87,7 @@ int32_t taosGetCpuCores(float *numOfCores) {
...
@@ -87,7 +87,7 @@ int32_t taosGetCpuCores(float *numOfCores) {
return
0
;
return
0
;
}
}
int32_t
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
int32_t
taosGetCpuUsage
(
double
*
sysCpuUsage
,
double
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
return
0
;
...
@@ -112,64 +112,32 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
...
@@ -112,64 +112,32 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
}
}
}
}
int32_t
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
tbytes
)
{
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
if
(
bytes
)
*
bytes
=
0
;
*
receive_bytes
=
0
;
if
(
rbytes
)
*
rbytes
=
0
;
*
transmit_bytes
=
0
;
if
(
tbytes
)
*
tbytes
=
0
;
return
0
;
return
0
;
}
}
int32_t
taosGetBandSpeed
(
float
*
bandSpeedKb
)
{
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
*
bandSpeedKb
=
0
;
return
0
;
}
int32_t
taosReadProcIO
(
int64_t
*
readbyte
,
int64_t
*
writebyte
)
{
IO_COUNTERS
io_counter
;
IO_COUNTERS
io_counter
;
if
(
GetProcessIoCounters
(
GetCurrentProcess
(),
&
io_counter
))
{
if
(
GetProcessIoCounters
(
GetCurrentProcess
(),
&
io_counter
))
{
if
(
readbyte
)
*
readbyte
=
io_counter
.
ReadTransferCount
;
if
(
rchars
)
*
rchars
=
io_counter
.
ReadTransferCount
;
if
(
writebyte
)
*
writebyte
=
io_counter
.
WriteTransferCount
;
if
(
wchars
)
*
wchars
=
io_counter
.
WriteTransferCount
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
return
0
;
}
}
return
-
1
;
return
-
1
;
}
}
int32_t
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
)
{
static
int64_t
lastReadbyte
=
-
1
;
static
int64_t
lastWritebyte
=
-
1
;
int64_t
curReadbyte
=
0
;
int64_t
curWritebyte
=
0
;
if
(
taosReadProcIO
(
&
curReadbyte
,
&
curWritebyte
)
!=
0
)
{
return
-
1
;
}
if
(
lastReadbyte
==
-
1
||
lastWritebyte
==
-
1
)
{
lastReadbyte
=
curReadbyte
;
lastWritebyte
=
curWritebyte
;
return
-
1
;
}
*
readKB
=
(
float
)((
double
)(
curReadbyte
-
lastReadbyte
)
/
1024
);
*
writeKB
=
(
float
)((
double
)(
curWritebyte
-
lastWritebyte
)
/
1024
);
if
(
*
readKB
<
0
)
*
readKB
=
0
;
if
(
*
writeKB
<
0
)
*
writeKB
=
0
;
lastReadbyte
=
curReadbyte
;
lastWritebyte
=
curWritebyte
;
return
0
;
}
void
taosGetSystemInfo
()
{
void
taosGetSystemInfo
()
{
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
float
tmp1
,
tmp2
;
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetBandSpeed
(
&
tmp1
);
taosGetBandSpeed
(
&
tmp1
,
&
tmp2
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGet
ProcIO
(
&
tmp1
,
&
tmp2
);
taosGet
IOSpeed
(
&
tmp1
,
&
tmp2
,
&
tmp3
,
&
tmp4
);
}
}
void
taosKillSystem
()
{
void
taosKillSystem
()
{
...
@@ -259,31 +227,21 @@ void taosGetSystemInfo() {
...
@@ -259,31 +227,21 @@ void taosGetSystemInfo() {
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
tsNumOfCores
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
}
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
)
{
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
if
(
rchars
)
*
rchars
=
0
;
if
(
rchars
)
*
rchars
=
0
;
if
(
wchars
)
*
wchars
=
0
;
if
(
wchars
)
*
wchars
=
0
;
if
(
read_bytes
)
*
read_bytes
=
0
;
if
(
write_bytes
)
*
write_bytes
=
0
;
return
0
;
return
0
;
}
}
int32_t
taosGet
ProcIO
(
float
*
readKB
,
float
*
writeKB
)
{
int32_t
taosGet
CardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
*
re
adKB
=
0
;
*
re
ceive_bytes
=
0
;
*
writeKB
=
0
;
*
transmit_bytes
=
0
;
return
0
;
return
0
;
}
}
int32_t
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
tbytes
)
{
int32_t
taosGetCpuUsage
(
double
*
sysCpuUsage
,
double
*
procCpuUsage
)
{
if
(
bytes
)
*
bytes
=
0
;
if
(
rbytes
)
*
rbytes
=
0
;
if
(
tbytes
)
*
tbytes
=
0
;
return
0
;
}
int32_t
taosGetBandSpeed
(
float
*
bandSpeedKb
)
{
*
bandSpeedKb
=
0
;
return
0
;
}
int32_t
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
*
sysCpuUsage
=
0
;
*
sysCpuUsage
=
0
;
*
procCpuUsage
=
0
;
*
procCpuUsage
=
0
;
return
0
;
return
0
;
...
@@ -400,7 +358,6 @@ int32_t taosGetSysMemory(int64_t *usedKB) {
...
@@ -400,7 +358,6 @@ int32_t taosGetSysMemory(int64_t *usedKB) {
}
}
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
// 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);
...
@@ -434,7 +391,6 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
...
@@ -434,7 +391,6 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
}
}
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
// 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);
...
@@ -459,7 +415,6 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
...
@@ -459,7 +415,6 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
}
}
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
// 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);
...
@@ -493,7 +448,7 @@ int32_t taosGetCpuCores(float *numOfCores) {
...
@@ -493,7 +448,7 @@ int32_t taosGetCpuCores(float *numOfCores) {
return
0
;
return
0
;
}
}
int32_t
taosGetCpuUsage
(
float
*
cpu_system
,
float
*
cpu_engine
)
{
int32_t
taosGetCpuUsage
(
double
*
cpu_system
,
double
*
cpu_engine
)
{
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
;
...
@@ -522,8 +477,8 @@ int32_t taosGetCpuUsage(float *cpu_system, float *cpu_engine) {
...
@@ -522,8 +477,8 @@ int32_t taosGetCpuUsage(float *cpu_system, float *cpu_engine) {
return
-
1
;
return
-
1
;
}
}
*
cpu_engine
=
(
float
)((
double
)(
curSysUsed
-
lastSysUsed
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
)
;
*
cpu_engine
=
(
curSysUsed
-
lastSysUsed
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
;
*
cpu_system
=
(
float
)((
double
)(
curProcTotal
-
lastProcTotal
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
)
;
*
cpu_system
=
(
curProcTotal
-
lastProcTotal
)
/
(
double
)(
curSysTotal
-
lastSysTotal
)
*
100
;
lastSysUsed
=
curSysUsed
;
lastSysUsed
=
curSysUsed
;
lastSysTotal
=
curSysTotal
;
lastSysTotal
=
curSysTotal
;
...
@@ -544,14 +499,9 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
...
@@ -544,14 +499,9 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
}
}
}
}
int32_t
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
tbytes
)
{
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
if
(
bytes
)
*
bytes
=
0
;
// FILE *fp = fopen(tsSysNetFile, "r");
TdFilePtr
pFile
=
taosOpenFile
(
tsSysNetFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsSysNetFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
return
-
1
;
// printf("open file:%s failed", tsSysNetFile);
return
-
1
;
}
ssize_t
_bytes
=
0
;
ssize_t
_bytes
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
...
@@ -584,9 +534,8 @@ int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
...
@@ -584,9 +534,8 @@ int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
"%s %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
"%s %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
,
" %"
PRId64
,
nouse0
,
&
o_rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
o_tbytes
,
&
tpackets
);
nouse0
,
&
o_rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
o_tbytes
,
&
tpackets
);
if
(
rbytes
)
*
rbytes
=
o_rbytes
;
*
receive_bytes
=
o_rbytes
;
if
(
tbytes
)
*
tbytes
=
o_tbytes
;
*
transmit_bytes
=
o_tbytes
;
if
(
bytes
)
*
bytes
+=
(
o_rbytes
+
o_tbytes
);
}
}
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
...
@@ -595,58 +544,52 @@ int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
...
@@ -595,58 +544,52 @@ int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
return
0
;
return
0
;
}
}
int32_t
taosGetBandSpeed
(
float
*
bandSpeedKb
)
{
int32_t
taosGetBandSpeed
(
double
*
receive_bytes_per_sec
,
double
*
transmit_bytes_per_sec
)
{
static
int64_t
lastBytes
=
0
;
static
int64_t
last_receive_bytes
=
0
;
static
time_t
lastTime
=
0
;
static
int64_t
last_transmit_bytes
=
0
;
int64_t
curBytes
=
0
;
static
int64_t
last_time
=
0
;
time_t
curTime
=
time
(
NULL
);
int64_t
cur_receive_bytes
=
0
;
int64_t
cur_transmit_bytes
=
0
;
int64_t
cur_time
=
taosGetTimestampMs
();
if
(
taosGetCardInfo
(
&
cur
Bytes
,
NULL
,
NULL
)
!=
0
)
{
if
(
taosGetCardInfo
(
&
cur
_receive_bytes
,
&
cur_transmit_bytes
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
lastTime
==
0
||
lastBytes
==
0
)
{
if
(
last_time
==
0
||
last_time
>=
cur_time
)
{
lastTime
=
curTime
;
last_time
=
cur_time
;
lastBytes
=
curBytes
;
last_receive_bytes
=
cur_receive_bytes
;
*
bandSpeedKb
=
0
;
last_transmit_bytes
=
cur_transmit_bytes
;
*
receive_bytes_per_sec
=
0
;
*
transmit_bytes_per_sec
=
0
;
return
0
;
return
0
;
}
}
if
(
lastTime
>=
curTime
||
lastBytes
>
curBytes
)
{
*
receive_bytes_per_sec
=
(
cur_receive_bytes
-
last_receive_bytes
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
lastTime
=
curTime
;
*
transmit_bytes_per_sec
=
(
cur_transmit_bytes
-
last_transmit_bytes
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
lastBytes
=
curBytes
;
*
bandSpeedKb
=
0
;
return
0
;
}
double
totalBytes
=
(
double
)(
curBytes
-
lastBytes
)
/
1024
*
8
;
// Kb
last_time
=
cur_time
;
*
bandSpeedKb
=
(
float
)(
totalBytes
/
(
double
)(
curTime
-
lastTime
));
last_transmit_bytes
=
cur_transmit_bytes
;
last_receive_bytes
=
cur_receive_bytes
;
// //printf("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld,
if
(
*
receive_bytes_per_sec
<
0
)
*
receive_bytes_per_sec
=
0
;
// speed:%f", lastBytes, lastTime, curBytes, curTime, *bandSpeed);
if
(
*
transmit_bytes_per_sec
<
0
)
*
transmit_bytes_per_sec
=
0
;
lastTime
=
curTime
;
lastBytes
=
curBytes
;
return
0
;
return
0
;
}
}
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
)
{
int32_t
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
// FILE *fp = fopen(tsProcIOFile, "r");
TdFilePtr
pFile
=
taosOpenFile
(
tsProcIOFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
tsProcIOFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
return
-
1
;
// printf("open file:%s failed", tsProcIOFile);
return
-
1
;
}
ssize_t
_bytes
=
0
;
ssize_t
_bytes
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
char
tmp
[
10
];
char
tmp
[
24
];
int
readIndex
=
0
;
int
readIndex
=
0
;
while
(
!
taosEOFFile
(
pFile
))
{
while
(
!
taosEOFFile
(
pFile
))
{
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
(
_bytes
<
0
)
||
(
line
==
NULL
)
)
{
if
(
_bytes
<
10
||
line
==
NULL
)
{
break
;
break
;
}
}
if
(
strstr
(
line
,
"rchar:"
)
!=
NULL
)
{
if
(
strstr
(
line
,
"rchar:"
)
!=
NULL
)
{
...
@@ -655,47 +598,70 @@ int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) {
...
@@ -655,47 +598,70 @@ int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) {
}
else
if
(
strstr
(
line
,
"wchar:"
)
!=
NULL
)
{
}
else
if
(
strstr
(
line
,
"wchar:"
)
!=
NULL
)
{
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
wchars
);
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
wchars
);
readIndex
++
;
readIndex
++
;
}
else
if
(
strstr
(
line
,
"read_bytes:"
)
!=
NULL
)
{
// read_bytes
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
read_bytes
);
readIndex
++
;
}
else
if
(
strstr
(
line
,
"write_bytes:"
)
!=
NULL
)
{
// write_bytes
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
write_bytes
);
readIndex
++
;
}
else
{
}
else
{
}
}
if
(
readIndex
>=
2
)
break
;
if
(
readIndex
>=
4
)
break
;
}
}
if
(
line
!=
NULL
)
tfree
(
line
);
if
(
line
!=
NULL
)
tfree
(
line
);
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
if
(
readIndex
<
2
)
{
if
(
readIndex
<
4
)
{
// printf("read file:%s failed", tsProcIOFile);
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
int32_t
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
)
{
int32_t
taosGetIOSpeed
(
double
*
rchar_per_sec
,
double
*
wchar_per_sec
,
double
*
read_bytes_per_sec
,
static
int64_t
lastReadbyte
=
-
1
;
double
*
write_bytes_per_sec
)
{
static
int64_t
lastWritebyte
=
-
1
;
static
int64_t
last_rchar
=
-
1
;
static
int64_t
last_wchar
=
-
1
;
static
int64_t
last_read_bytes
=
-
1
;
static
int64_t
last_write_bytes
=
-
1
;
static
int64_t
last_time
=
0
;
int64_t
curReadbyte
=
0
;
int64_t
cur_rchar
=
0
;
int64_t
curWritebyte
=
0
;
int64_t
cur_wchar
=
0
;
int64_t
cur_read_bytes
=
0
;
int64_t
cur_write_bytes
=
0
;
int64_t
cur_time
=
taosGetTimestampMs
();
if
(
taosReadProcIO
(
&
cur
Readbyte
,
&
curWritebyte
)
!=
0
)
{
if
(
taosReadProcIO
(
&
cur
_rchar
,
&
cur_wchar
,
&
cur_read_bytes
,
&
cur_write_bytes
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
lastReadbyte
==
-
1
||
lastWritebyte
==
-
1
)
{
if
(
last_time
==
0
||
last_time
>=
cur_time
)
{
lastReadbyte
=
curReadbyte
;
last_time
=
cur_time
;
lastWritebyte
=
curWritebyte
;
last_rchar
=
cur_rchar
;
last_wchar
=
cur_wchar
;
last_read_bytes
=
cur_read_bytes
;
last_write_bytes
=
cur_write_bytes
;
return
-
1
;
return
-
1
;
}
}
*
readKB
=
(
float
)((
double
)(
curReadbyte
-
lastReadbyte
)
/
1024
);
*
rchar_per_sec
=
(
cur_rchar
-
last_rchar
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
*
writeKB
=
(
float
)((
double
)(
curWritebyte
-
lastWritebyte
)
/
1024
);
*
wchar_per_sec
=
(
cur_wchar
-
last_wchar
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
if
(
*
readKB
<
0
)
*
readKB
=
0
;
*
read_bytes_per_sec
=
(
cur_read_bytes
-
last_read_bytes
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
if
(
*
writeKB
<
0
)
*
writeKB
=
0
;
*
write_bytes_per_sec
=
(
cur_write_bytes
-
last_write_bytes
)
/
(
double
)(
cur_time
-
last_time
)
*
1000
;
last_time
=
cur_time
;
last_rchar
=
cur_rchar
;
last_wchar
=
cur_wchar
;
last_read_bytes
=
cur_read_bytes
;
last_write_bytes
=
cur_write_bytes
;
lastReadbyte
=
curReadbyte
;
if
(
*
rchar_per_sec
<
0
)
*
rchar_per_sec
=
0
;
lastWritebyte
=
curWritebyte
;
if
(
*
wchar_per_sec
<
0
)
*
wchar_per_sec
=
0
;
if
(
*
read_bytes_per_sec
<
0
)
*
read_bytes_per_sec
=
0
;
if
(
*
write_bytes_per_sec
<
0
)
*
write_bytes_per_sec
=
0
;
return
0
;
return
0
;
}
}
...
@@ -705,10 +671,10 @@ void taosGetSystemInfo() {
...
@@ -705,10 +671,10 @@ void taosGetSystemInfo() {
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
float
tmp1
,
tmp2
;
double
tmp1
,
tmp2
,
tmp3
,
tmp4
;
taosGetBandSpeed
(
&
tmp1
);
taosGetBandSpeed
(
&
tmp1
,
&
tmp2
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGetCpuUsage
(
&
tmp1
,
&
tmp2
);
taosGet
ProcIO
(
&
tmp1
,
&
tmp2
);
taosGet
IOSpeed
(
&
tmp1
,
&
tmp2
,
&
tmp3
,
&
tmp4
);
}
}
void
taosKillSystem
()
{
void
taosKillSystem
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录