Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
TDengine
提交
0d532d15
TDengine
项目概览
weixin_40195168达庆意
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d532d15
编写于
8月 06, 2021
作者:
S
Shenglian Zhou
提交者:
shenglian zhou
8月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5861]<feature>:move log.dn to http plugins
上级
d8a4a54a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
201 addition
and
25 deletion
+201
-25
src/inc/tfs.h
src/inc/tfs.h
+8
-1
src/os/inc/osSysinfo.h
src/os/inc/osSysinfo.h
+3
-0
src/os/src/detail/osSysinfo.c
src/os/src/detail/osSysinfo.c
+12
-10
src/plugins/http/inc/httpMetricsHandle.h
src/plugins/http/inc/httpMetricsHandle.h
+17
-0
src/plugins/http/src/httpMetricsHandle.c
src/plugins/http/src/httpMetricsHandle.c
+146
-0
src/plugins/http/src/httpSystem.c
src/plugins/http/src/httpSystem.c
+2
-1
src/tfs/inc/tfsint.h
src/tfs/inc/tfsint.h
+1
-6
src/tfs/src/tfs.c
src/tfs/src/tfs.c
+12
-7
未找到文件。
src/inc/tfs.h
浏览文件 @
0d532d15
...
...
@@ -41,9 +41,16 @@ typedef struct {
int64_t
avail
;
}
SFSMeta
;
typedef
struct
{
int64_t
size
;
int64_t
used
;
int64_t
free
;
int16_t
nAvailDisks
;
// # of Available disks
}
STierMeta
;
int
tfsInit
(
SDiskCfg
*
pDiskCfg
,
int
ndisk
);
void
tfsDestroy
();
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
);
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
,
STierMeta
*
tierMetas
,
int8_t
numLevels
);
void
tfsGetMeta
(
SFSMeta
*
pMeta
);
void
tfsAllocDisk
(
int
expLevel
,
int
*
level
,
int
*
id
);
...
...
src/os/inc/osSysinfo.h
浏览文件 @
0d532d15
...
...
@@ -28,8 +28,11 @@ typedef struct {
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SysDiskSize
*
diskSize
);
int32_t
taosGetCpuCores
();
void
taosGetSystemInfo
();
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
);
bool
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
);
bool
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
tbytes
);
bool
taosGetBandSpeed
(
float
*
bandSpeedKb
);
void
taosGetDisk
();
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
;
...
...
src/os/src/detail/osSysinfo.c
浏览文件 @
0d532d15
...
...
@@ -277,7 +277,7 @@ static void taosGetSystemLocale() { // get and set default locale
}
}
static
int32_t
taosGetCpuCores
()
{
return
(
int32_t
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
int32_t
taosGetCpuCores
()
{
return
(
int32_t
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
}
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
{
static
uint64_t
lastSysUsed
=
0
;
...
...
@@ -332,7 +332,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
}
}
static
bool
taosGetCardInfo
(
int64_t
*
bytes
)
{
bool
taosGetCardInfo
(
int64_t
*
bytes
,
int64_t
*
rbytes
,
int64_t
*
t
bytes
)
{
*
bytes
=
0
;
FILE
*
fp
=
fopen
(
tsSysNetFile
,
"r"
);
if
(
fp
==
NULL
)
{
...
...
@@ -347,9 +347,9 @@ static bool taosGetCardInfo(int64_t *bytes) {
while
(
!
feof
(
fp
))
{
memset
(
line
,
0
,
len
);
int64_t
rbytes
=
0
;
int64_t
o_
rbytes
=
0
;
int64_t
rpackts
=
0
;
int64_t
tbytes
=
0
;
int64_t
o_
tbytes
=
0
;
int64_t
tpackets
=
0
;
int64_t
nouse1
=
0
;
int64_t
nouse2
=
0
;
...
...
@@ -374,8 +374,10 @@ static bool taosGetCardInfo(int64_t *bytes) {
sscanf
(
line
,
"%s %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
" %"
PRId64
,
nouse0
,
&
rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
tbytes
,
&
tpackets
);
*
bytes
+=
(
rbytes
+
tbytes
);
nouse0
,
&
o_rbytes
,
&
rpackts
,
&
nouse1
,
&
nouse2
,
&
nouse3
,
&
nouse4
,
&
nouse5
,
&
nouse6
,
&
o_tbytes
,
&
tpackets
);
if
(
rbytes
)
*
rbytes
=
o_rbytes
;
if
(
tbytes
)
*
tbytes
=
o_tbytes
;
*
bytes
+=
(
o_rbytes
+
o_tbytes
);
}
tfree
(
line
);
...
...
@@ -390,7 +392,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) {
int64_t
curBytes
=
0
;
time_t
curTime
=
time
(
NULL
);
if
(
!
taosGetCardInfo
(
&
curBytes
))
{
if
(
!
taosGetCardInfo
(
&
curBytes
,
NULL
,
NULL
))
{
return
false
;
}
...
...
@@ -420,7 +422,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) {
return
true
;
}
static
bool
taosReadProcIO
(
int64_t
*
readbyte
,
int64_t
*
writebyte
)
{
bool
taosReadProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
)
{
FILE
*
fp
=
fopen
(
tsProcIOFile
,
"r"
);
if
(
fp
==
NULL
)
{
uError
(
"open file:%s failed"
,
tsProcIOFile
);
...
...
@@ -441,10 +443,10 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
break
;
}
if
(
strstr
(
line
,
"rchar:"
)
!=
NULL
)
{
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
r
eadbyte
);
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
r
chars
);
readIndex
++
;
}
else
if
(
strstr
(
line
,
"wchar:"
)
!=
NULL
)
{
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
w
ritebyte
);
sscanf
(
line
,
"%s %"
PRId64
,
tmp
,
w
chars
);
readIndex
++
;
}
else
{
}
...
...
src/plugins/http/inc/httpMetricsHandle.h
0 → 100644
浏览文件 @
0d532d15
//
// Created by slzhou on 8/6/21.
//
#ifndef TDENGINE_HTTPMETRICSHANDLE_H
#define TDENGINE_HTTPMETRICSHANDLE_H
#include "http.h"
#include "httpInt.h"
#include "httpUtil.h"
#include "httpResp.h"
void
metricsInitHandle
(
HttpServer
*
httpServer
);
bool
metricsProcessRequest
(
struct
HttpContext
*
httpContext
);
#endif // TDENGINE_HTTPMETRICHANDLE_H
src/plugins/http/src/httpMetricsHandle.c
0 → 100644
浏览文件 @
0d532d15
//
// Created by slzhou on 8/6/21.
//
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "tfs.h"
#include "httpMetricsHandle.h"
#include "dnode.h"
#include "httpLog.h"
static
HttpDecodeMethod
metricsDecodeMethod
=
{
"metrics"
,
metricsProcessRequest
};
void
metricsInitHandle
(
HttpServer
*
pServer
)
{
httpAddMethod
(
pServer
,
&
metricsDecodeMethod
);
}
bool
metricsProcessRequest
(
HttpContext
*
pContext
)
{
httpDebug
(
"context:%p, fd:%d, user:%s, process admin grant msg"
,
pContext
,
pContext
->
fd
,
pContext
->
user
);
JsonBuf
*
jsonBuf
=
httpMallocJsonBuf
(
pContext
);
if
(
jsonBuf
==
NULL
)
{
httpError
(
"failed to allocate memory for metrics"
);
httpSendErrorResp
(
pContext
,
TSDB_CODE_HTTP_NO_ENOUGH_MEMORY
);
return
false
;
}
httpInitJsonBuf
(
jsonBuf
,
pContext
);
httpWriteJsonBufHead
(
jsonBuf
);
httpJsonToken
(
jsonBuf
,
JsonObjStt
);
{
int32_t
cpuCores
=
taosGetCpuCores
();
char
*
keyCpuCores
=
"cpu_cores"
;
httpJsonPairIntVal
(
jsonBuf
,
keyCpuCores
,
strlen
(
keyCpuCores
),
cpuCores
);
float
sysCpuUsage
=
0
;
float
procCpuUsage
=
0
;
bool
succeeded
=
taosGetCpuUsage
(
&
sysCpuUsage
,
&
procCpuUsage
);
if
(
!
succeeded
)
{
httpError
(
"failed to get cpu usage"
);
}
else
{
if
(
sysCpuUsage
<=
procCpuUsage
)
{
sysCpuUsage
=
procCpuUsage
+
0
.
1
f
;
}
char
*
keyCpuSystem
=
"cpu_system"
;
char
*
keyCpuEngine
=
"cpu_engine"
;
httpJsonPairFloatVal
(
jsonBuf
,
keyCpuSystem
,
strlen
(
keyCpuSystem
),
sysCpuUsage
);
httpJsonPairFloatVal
(
jsonBuf
,
keyCpuEngine
,
strlen
(
keyCpuEngine
),
procCpuUsage
);
}
}
{
float
sysMemoryUsedMB
=
0
;
bool
succeeded
=
taosGetSysMemory
(
&
sysMemoryUsedMB
);
if
(
!
succeeded
)
{
httpError
(
"failed to get sys memory info"
);
}
else
{
char
*
keyMemSystem
=
"mem_system"
;
httpJsonPairFloatVal
(
jsonBuf
,
keyMemSystem
,
strlen
(
keyMemSystem
),
sysMemoryUsedMB
);
}
float
procMemoryUsedMB
=
0
;
succeeded
=
taosGetProcMemory
(
&
procMemoryUsedMB
);
if
(
!
succeeded
)
{
httpError
(
"failed to get proc memory info"
);
}
else
{
char
*
keyMemEngine
=
"mem_engine"
;
httpJsonPairFloatVal
(
jsonBuf
,
keyMemEngine
,
strlen
(
keyMemEngine
),
procMemoryUsedMB
);
}
}
{
int64_t
bytes
=
0
,
rbytes
=
0
,
tbytes
=
0
;
bool
succeeded
=
taosGetCardInfo
(
&
bytes
,
&
rbytes
,
&
tbytes
);
if
(
!
succeeded
)
{
httpError
(
"failed to get network info"
);
}
else
{
char
*
keyNetIn
=
"net_in"
;
char
*
keyNetOut
=
"net_out"
;
httpJsonPairInt64Val
(
jsonBuf
,
keyNetIn
,
strlen
(
keyNetIn
),
rbytes
);
httpJsonPairInt64Val
(
jsonBuf
,
keyNetOut
,
strlen
(
keyNetOut
),
tbytes
);
}
}
{
int64_t
rchars
=
0
;
int64_t
wchars
=
0
;
bool
succeeded
=
taosReadProcIO
(
&
rchars
,
&
wchars
);
if
(
!
succeeded
)
{
httpError
(
"failed to get io info"
);
}
else
{
char
*
keyIORead
=
"io_read"
;
char
*
keyIOWrite
=
"io_write"
;
httpJsonPairInt64Val
(
jsonBuf
,
keyIORead
,
strlen
(
keyIORead
),
rchars
);
httpJsonPairInt64Val
(
jsonBuf
,
keyIOWrite
,
strlen
(
keyIOWrite
),
wchars
);
}
}
{
const
int8_t
numTiers
=
3
;
SFSMeta
fsMeta
;
STierMeta
tierMetas
[
numTiers
];
memset
(
tierMetas
,
0
,
3
*
sizeof
(
STierMeta
));
tfsUpdateInfo
(
&
fsMeta
,
tierMetas
,
numTiers
);
{
char
*
keyDiskUsed
=
"disk_used"
;
char
*
keyDiskTotal
=
"disk_total"
;
httpJsonPairInt64Val
(
jsonBuf
,
keyDiskTotal
,
strlen
(
keyDiskTotal
),
fsMeta
.
tsize
);
httpJsonPairInt64Val
(
jsonBuf
,
keyDiskUsed
,
strlen
(
keyDiskUsed
),
fsMeta
.
used
);
char
*
keyDisks
=
"disks"
;
httpJsonPairHead
(
jsonBuf
,
keyDisks
,
strlen
(
keyDisks
));
httpJsonToken
(
jsonBuf
,
JsonArrStt
);
for
(
int
i
=
0
;
i
<
numTiers
;
++
i
)
{
httpJsonItemToken
(
jsonBuf
);
httpJsonToken
(
jsonBuf
,
JsonObjStt
);
char
*
keyDataDirLevelUsed
=
"datadir_used"
;
char
*
keyDataDirLevelTotal
=
"datadir_total"
;
httpJsonPairInt64Val
(
jsonBuf
,
keyDataDirLevelUsed
,
strlen
(
keyDataDirLevelUsed
),
tierMetas
[
i
].
used
);
httpJsonPairInt64Val
(
jsonBuf
,
keyDataDirLevelTotal
,
strlen
(
keyDataDirLevelTotal
),
tierMetas
[
i
].
size
);
httpJsonToken
(
jsonBuf
,
JsonObjEnd
);
}
httpJsonToken
(
jsonBuf
,
JsonArrEnd
);
}
}
{
SStatisInfo
info
=
dnodeGetStatisInfo
();
{
char
*
keyReqHttp
=
"req_http"
;
char
*
keyReqSelect
=
"req_select"
;
char
*
keyReqInsert
=
"req_insert"
;
httpJsonPairInt64Val
(
jsonBuf
,
keyReqHttp
,
strlen
(
keyReqHttp
),
info
.
httpReqNum
);
httpJsonPairInt64Val
(
jsonBuf
,
keyReqSelect
,
strlen
(
keyReqSelect
),
info
.
queryReqNum
);
httpJsonPairInt64Val
(
jsonBuf
,
keyReqInsert
,
strlen
(
keyReqInsert
),
info
.
submitReqNum
);
}
}
httpJsonToken
(
jsonBuf
,
JsonObjEnd
);
httpWriteJsonBufEnd
(
jsonBuf
);
pContext
->
reqType
=
HTTP_REQTYPE_OTHERS
;
httpFreeJsonBuf
(
pContext
);
return
false
;
}
\ No newline at end of file
src/plugins/http/src/httpSystem.c
浏览文件 @
0d532d15
...
...
@@ -30,6 +30,7 @@
#include "httpGcHandle.h"
#include "httpRestHandle.h"
#include "httpTgHandle.h"
#include "httpMetricsHandle.h"
#ifndef _ADMIN
void
adminInitHandle
(
HttpServer
*
pServer
)
{}
...
...
@@ -52,7 +53,7 @@ int32_t httpInitSystem() {
gcInitHandle
(
&
tsHttpServer
);
tgInitHandle
(
&
tsHttpServer
);
opInitHandle
(
&
tsHttpServer
);
metricsInitHandle
(
&
tsHttpServer
);
return
0
;
}
...
...
src/tfs/inc/tfsint.h
浏览文件 @
0d532d15
...
...
@@ -65,12 +65,7 @@ SDisk *tfsFreeDisk(SDisk *pDisk);
int
tfsUpdateDiskInfo
(
SDisk
*
pDisk
);
// ttier.c ======================================================
typedef
struct
{
int64_t
size
;
int64_t
used
;
int64_t
free
;
int16_t
nAvailDisks
;
// # of Available disks
}
STierMeta
;
typedef
struct
STier
{
pthread_spinlock_t
lock
;
int
level
;
...
...
src/tfs/src/tfs.c
浏览文件 @
0d532d15
...
...
@@ -101,7 +101,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
return
-
1
;
}
tfsUpdateInfo
(
NULL
);
tfsUpdateInfo
(
NULL
,
NULL
,
0
);
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
tfsPosNextId
(
TFS_TIER_AT
(
level
));
}
...
...
@@ -119,7 +119,7 @@ void tfsDestroy() {
}
}
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
)
{
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
,
STierMeta
*
tierMetas
,
int8_t
numTiers
)
{
SFSMeta
fsMeta
;
STierMeta
tierMeta
;
...
...
@@ -130,11 +130,16 @@ void tfsUpdateInfo(SFSMeta *pFSMeta) {
memset
(
pFSMeta
,
0
,
sizeof
(
*
pFSMeta
));
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
STierMeta
*
pTierMeta
=
&
tierMeta
;
if
(
tierMetas
&&
level
<
numTiers
)
{
pTierMeta
=
tierMetas
+
level
;
}
STier
*
pTier
=
TFS_TIER_AT
(
level
);
tfsUpdateTierInfo
(
pTier
,
&
t
ierMeta
);
pFSMeta
->
tsize
+=
tierMeta
.
size
;
pFSMeta
->
avail
+=
tierMeta
.
free
;
pFSMeta
->
used
+=
tierMeta
.
used
;
tfsUpdateTierInfo
(
pTier
,
pT
ierMeta
);
pFSMeta
->
tsize
+=
pTierMeta
->
size
;
pFSMeta
->
avail
+=
pTierMeta
->
free
;
pFSMeta
->
used
+=
pTierMeta
->
used
;
}
tfsLock
();
...
...
@@ -595,7 +600,7 @@ void taosGetDisk() {
SFSMeta
fsMeta
;
if
(
tscEmbedded
)
{
tfsUpdateInfo
(
&
fsMeta
);
tfsUpdateInfo
(
&
fsMeta
,
NULL
,
0
);
tsTotalDataDirGB
=
(
float
)(
fsMeta
.
tsize
/
unit
);
tsUsedDataDirGB
=
(
float
)(
fsMeta
.
used
/
unit
);
tsAvailDataDirGB
=
(
float
)(
fsMeta
.
avail
/
unit
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录