Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
acaf116a
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看板
提交
acaf116a
编写于
10月 27, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add audit db for DDL storage
上级
d2367337
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
11 deletion
+68
-11
src/common/inc/tglobal.h
src/common/inc/tglobal.h
+1
-0
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-0
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+66
-11
未找到文件。
src/common/inc/tglobal.h
浏览文件 @
acaf116a
...
...
@@ -148,6 +148,7 @@ extern int32_t tsHttpKeepAlive;
extern
int8_t
tsEnableMonitorModule
;
extern
int8_t
tsMonitorReplica
;
extern
char
tsMonitorDbName
[];
extern
char
tsAuditDbName
[];
extern
char
tsInternalPass
[];
extern
int32_t
tsMonitorInterval
;
...
...
src/common/src/tglobal.c
浏览文件 @
acaf116a
...
...
@@ -197,6 +197,7 @@ int32_t tsHttpKeepAlive = 30000;
int8_t
tsEnableMonitorModule
=
1
;
int8_t
tsMonitorReplica
=
1
;
char
tsMonitorDbName
[
TSDB_DB_NAME_LEN
]
=
"log"
;
char
tsAuditDbName
[
TSDB_DB_NAME_LEN
]
=
"audit"
;
char
tsInternalPass
[]
=
"secretkey"
;
int32_t
tsMonitorInterval
=
30
;
// seconds
...
...
src/plugins/monitor/src/monMain.c
浏览文件 @
acaf116a
...
...
@@ -41,6 +41,7 @@
#define DNODE_INFO_LEN 128
#define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000
#define AUDIT_MAX_RETRIES 10
#define SQL_STR_FMT "\"%s\""
...
...
@@ -175,16 +176,24 @@ static void monSaveDisksInfo();
static
void
monSaveGrantsInfo
();
static
void
monSaveHttpReqInfo
();
static
void
monGetSysStats
();
static
void
*
monThreadFunc
(
void
*
param
);
static
void
*
monThreadFunc
(
void
*
param
);
static
void
*
monAuditFunc
(
void
*
param
);
static
void
monBuildMonitorSql
(
char
*
sql
,
int32_t
cmd
);
static
void
monInitHttpStatusHashTable
();
static
void
monCleanupHttpStatusHashTable
();
static
void
monInitHttpStatusHashTable
();
static
void
monCleanupHttpStatusHashTable
();
extern
int32_t
(
*
monStartSystemFp
)();
extern
void
(
*
monStopSystemFp
)();
extern
void
(
*
monExecuteSQLFp
)(
char
*
sql
);
extern
char
*
strptime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
);
//make the compilation pass
#ifdef _STORAGE
char
*
keepValue
=
"30,30,30"
;
#else
char
*
keepValue
=
"30"
;
#endif
int32_t
monInitSystem
()
{
if
(
tsMonitor
.
ep
[
0
]
==
0
)
{
strcpy
(
tsMonitor
.
ep
,
tsLocalEp
);
...
...
@@ -203,12 +212,20 @@ int32_t monInitSystem() {
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
tsMonitor
.
thread
,
&
thAttr
,
monThreadFunc
,
NULL
))
{
monError
(
"failed to create thread to for monitor module, reason:%s"
,
strerror
(
errno
));
monError
(
"failed to create thread for monitor module, reason:%s"
,
strerror
(
errno
));
return
-
1
;
}
monError
(
"monitor thread is launched"
);
pthread_t
auditThread
;
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_DETACHED
);
if
(
pthread_create
(
&
auditThread
,
&
thAttr
,
monAuditFunc
,
NULL
))
{
monError
(
"failed to create audit thread, reason:%s"
,
strerror
(
errno
));
return
-
1
;
}
monError
(
"audit thread is launched"
);
pthread_attr_destroy
(
&
thAttr
);
monDebug
(
"monitor thread is launched"
);
monStartSystemFp
=
monStartSystem
;
monStopSystemFp
=
monStopSystem
;
...
...
@@ -250,6 +267,50 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) {
return
(
SMonHttpStatus
*
)
taosHashGet
(
monHttpStatusHashTable
,
&
code
,
sizeof
(
int32_t
));
}
static
void
*
monAuditFunc
(
void
*
param
)
{
monDebug
(
"starting to initialize audit database..."
);
setThreadName
(
"audit"
);
//taosMsleep(30000);
void
*
conn
=
NULL
;
int32_t
try
=
0
;
for
(;
try
<
AUDIT_MAX_RETRIES
;
++
try
)
{
conn
=
taos_connect
(
NULL
,
"root"
,
"taosdata"
,
""
,
0
);
if
(
conn
==
NULL
)
{
monDebug
(
"audit retry connect, tries: %d"
,
try
);
taosMsleep
(
1000
);
}
else
{
monDebug
(
"audit successfuly connect to database"
);
break
;
}
}
if
(
try
==
AUDIT_MAX_RETRIES
)
{
monError
(
"audit failed to connect to database, reason:%s"
,
tstrerror
(
terrno
));
return
NULL
;
}
char
sql
[
512
]
=
{
0
};
snprintf
(
sql
,
SQL_LENGTH
,
"create database if not exists %s replica 1 days 10 keep %s cache %d "
"blocks %d precision 'us'"
,
tsAuditDbName
,
keepValue
,
TSDB_MIN_CACHE_BLOCK_SIZE
,
TSDB_MIN_TOTAL_BLOCKS
);
void
*
res
=
taos_query
(
conn
,
sql
);
int32_t
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
if
(
code
!=
0
)
{
monError
(
"failed to exec sql:%s, reason:%s"
,
sql
,
tstrerror
(
code
));
return
NULL
;
}
else
{
monDebug
(
"successfully to exec sql:%s"
,
sql
);
}
return
NULL
;
}
static
void
*
monThreadFunc
(
void
*
param
)
{
monDebug
(
"starting to initialize monitor module ..."
);
setThreadName
(
"monitor"
);
...
...
@@ -335,12 +396,6 @@ static void *monThreadFunc(void *param) {
static
void
monBuildMonitorSql
(
char
*
sql
,
int32_t
cmd
)
{
memset
(
sql
,
0
,
SQL_LENGTH
);
#ifdef _STORAGE
char
*
keepValue
=
"30,30,30"
;
#else
char
*
keepValue
=
"30"
;
#endif
if
(
cmd
==
MON_CMD_CREATE_DB
)
{
snprintf
(
sql
,
SQL_LENGTH
,
"create database if not exists %s replica %d days 10 keep %s cache %d "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录