Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5367ca7f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5367ca7f
编写于
3月 04, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
record log
上级
1d9119df
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
42 addition
and
55 deletion
+42
-55
include/libs/monitor/monitor.h
include/libs/monitor/monitor.h
+1
-7
include/util/tlog.h
include/util/tlog.h
+3
-0
source/libs/monitor/inc/monInt.h
source/libs/monitor/inc/monInt.h
+12
-6
source/libs/monitor/src/monitor.c
source/libs/monitor/src/monitor.c
+20
-14
source/libs/monitor/test/monTest.cpp
source/libs/monitor/test/monTest.cpp
+5
-28
source/util/src/tlog.c
source/util/src/tlog.c
+1
-0
未找到文件。
include/libs/monitor/monitor.h
浏览文件 @
5367ca7f
...
...
@@ -127,12 +127,6 @@ typedef struct {
SMonDiskDesc
tempdir
;
}
SMonDiskInfo
;
typedef
struct
{
int64_t
ts
;
ELogLevel
level
;
char
content
[
MON_LOG_LEN
];
}
SMonLogItem
;
typedef
struct
SMonInfo
SMonInfo
;
typedef
struct
{
...
...
@@ -143,7 +137,7 @@ typedef struct {
int32_t
monInit
(
const
SMonCfg
*
pCfg
);
void
monCleanup
();
void
mon
AddLogItem
(
SMonLogItem
*
pItem
);
void
mon
RecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
);
SMonInfo
*
monCreateMonitorInfo
();
void
monSetBasicInfo
(
SMonInfo
*
pMonitor
,
SMonBasicInfo
*
pInfo
);
...
...
include/util/tlog.h
浏览文件 @
5367ca7f
...
...
@@ -34,10 +34,13 @@ typedef enum {
DEBUG_FILE
=
128
}
ELogLevel
;
typedef
void
(
*
LogFp
)(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
);
extern
bool
tsLogEmbedded
;
extern
bool
tsAsyncLog
;
extern
int32_t
tsNumOfLogLines
;
extern
int32_t
tsLogKeepDays
;
extern
LogFp
tsLogFp
;
extern
int64_t
tsNumOfErrorLogs
;
extern
int64_t
tsNumOfInfoLogs
;
extern
int64_t
tsNumOfDebugLogs
;
...
...
source/libs/monitor/inc/monInt.h
浏览文件 @
5367ca7f
...
...
@@ -23,18 +23,24 @@
#include "tjson.h"
typedef
struct
{
SRWLatch
lock
;
SArray
*
logs
;
// array of SMonLogItem
int32_t
maxLogs
;
const
char
*
server
;
uint16_t
port
;
}
SMonitor
;
int64_t
ts
;
ELogLevel
level
;
char
content
[
MON_LOG_LEN
];
}
SMonLogItem
;
typedef
struct
SMonInfo
{
SArray
*
logs
;
// array of SMonLogItem
SJson
*
pJson
;
}
SMonInfo
;
typedef
struct
{
pthread_rwlock_t
rwlock
;
SArray
*
logs
;
// array of SMonLogItem
int32_t
maxLogs
;
const
char
*
server
;
uint16_t
port
;
}
SMonitor
;
#ifdef __cplusplus
}
#endif
...
...
source/libs/monitor/src/monitor.c
浏览文件 @
5367ca7f
...
...
@@ -22,6 +22,21 @@
static
SMonitor
tsMonitor
=
{
0
};
void
monRecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
)
{
pthread_rwlock_rdlock
(
&
tsMonitor
.
rwlock
);
int32_t
size
=
taosArrayGetSize
(
tsMonitor
.
logs
);
if
(
size
>=
tsMonitor
.
maxLogs
)
{
uInfo
(
"too many logs for monitor"
);
}
else
{
SMonLogItem
item
=
{.
ts
=
ts
,
.
level
=
level
};
SMonLogItem
*
pItem
=
taosArrayPush
(
tsMonitor
.
logs
,
&
item
);
if
(
pItem
!=
NULL
)
{
tstrncpy
(
pItem
->
content
,
content
,
sizeof
(
item
.
content
));
}
}
pthread_rwlock_unlock
(
&
tsMonitor
.
rwlock
);
}
int32_t
monInit
(
const
SMonCfg
*
pCfg
)
{
tsMonitor
.
logs
=
taosArrayInit
(
16
,
sizeof
(
SMonLogItem
));
if
(
tsMonitor
.
logs
==
NULL
)
{
...
...
@@ -32,24 +47,15 @@ int32_t monInit(const SMonCfg *pCfg) {
tsMonitor
.
maxLogs
=
pCfg
->
maxLogs
;
tsMonitor
.
server
=
pCfg
->
server
;
tsMonitor
.
port
=
pCfg
->
port
;
taosInitRWLatch
(
&
tsMonitor
.
lock
);
tsLogFp
=
monRecordLog
;
pthread_rwlock_init
(
&
tsMonitor
.
rwlock
,
NULL
);
return
0
;
}
void
monCleanup
()
{
taosArrayDestroy
(
tsMonitor
.
logs
);
tsMonitor
.
logs
=
NULL
;
}
void
monAddLogItem
(
SMonLogItem
*
pItem
)
{
taosWLockLatch
(
&
tsMonitor
.
lock
);
int32_t
size
=
taosArrayGetSize
(
tsMonitor
.
logs
);
if
(
size
>=
tsMonitor
.
maxLogs
)
{
uInfo
(
"too many logs for monitor"
);
}
else
{
taosArrayPush
(
tsMonitor
.
logs
,
pItem
);
}
taosWUnLockLatch
(
&
tsMonitor
.
lock
);
pthread_rwlock_wrlock
(
&
tsMonitor
.
rwlock
);
}
SMonInfo
*
monCreateMonitorInfo
()
{
...
...
@@ -59,10 +65,10 @@ SMonInfo *monCreateMonitorInfo() {
return
NULL
;
}
taosWLockLatch
(
&
tsMonitor
.
lock
);
pthread_rwlock_wrlock
(
&
tsMonitor
.
rw
lock
);
pMonitor
->
logs
=
taosArrayDup
(
tsMonitor
.
logs
);
taosArrayClear
(
tsMonitor
.
logs
);
taosWUnLockLatch
(
&
tsMonitor
.
lock
);
pthread_rwlock_unlock
(
&
tsMonitor
.
rw
lock
);
pMonitor
->
pJson
=
tjsonCreateObject
();
if
(
pMonitor
->
pJson
==
NULL
||
pMonitor
->
logs
==
NULL
)
{
...
...
source/libs/monitor/test/monTest.cpp
浏览文件 @
5367ca7f
...
...
@@ -193,37 +193,14 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) {
}
void
MonitorTest
::
AddLogInfo1
()
{
SMonLogItem
log1
=
{
0
};
log1
.
ts
=
taosGetTimestampMs
();
log1
.
level
=
DEBUG_INFO
;
strcpy
(
log1
.
content
,
"1 -------------------------- a"
);
monAddLogItem
(
&
log1
);
SMonLogItem
log2
=
{
0
};
log2
.
ts
=
taosGetTimestampMs
();
log2
.
level
=
DEBUG_ERROR
;
strcpy
(
log2
.
content
,
"1 ------------------------ b"
);
monAddLogItem
(
&
log2
);
SMonLogItem
log3
=
{
0
};
log3
.
ts
=
taosGetTimestampMs
();
log3
.
level
=
DEBUG_DEBUG
;
strcpy
(
log3
.
content
,
"1 ------- c"
);
monAddLogItem
(
&
log3
);
monRecordLog
(
taosGetTimestampMs
(),
DEBUG_INFO
,
"1 -------------------------- a"
);
monRecordLog
(
taosGetTimestampMs
(),
DEBUG_ERROR
,
"1 ------------------------ b"
);
monRecordLog
(
taosGetTimestampMs
(),
DEBUG_DEBUG
,
"1 ------- c"
);
}
void
MonitorTest
::
AddLogInfo2
()
{
SMonLogItem
log1
;
log1
.
ts
=
taosGetTimestampMs
();
log1
.
level
=
DEBUG_ERROR
;
strcpy
(
log1
.
content
,
"2 ------- a"
);
monAddLogItem
(
&
log1
);
SMonLogItem
log2
;
log2
.
ts
=
taosGetTimestampMs
();
log2
.
level
=
DEBUG_ERROR
;
strcpy
(
log2
.
content
,
"2 ------- b"
);
monAddLogItem
(
&
log2
);
monRecordLog
(
taosGetTimestampMs
(),
DEBUG_ERROR
,
"2 ------- a"
);
monRecordLog
(
taosGetTimestampMs
(),
DEBUG_ERROR
,
"2 ------- b"
);
}
TEST_F
(
MonitorTest
,
01
_Full
)
{
...
...
source/util/src/tlog.c
浏览文件 @
5367ca7f
...
...
@@ -73,6 +73,7 @@ bool tsLogEmbedded = 0;
bool
tsAsyncLog
=
true
;
int32_t
tsNumOfLogLines
=
10000000
;
int32_t
tsLogKeepDays
=
0
;
LogFp
tsLogFp
=
NULL
;
int64_t
tsNumOfErrorLogs
=
0
;
int64_t
tsNumOfInfoLogs
=
0
;
int64_t
tsNumOfDebugLogs
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录