Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e64bb853
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看板
提交
e64bb853
编写于
12月 31, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(query,insert,other,connector):implement slow query from 2.2
上级
99fa8041
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
3 addition
and
97 deletion
+3
-97
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+3
-97
未找到文件。
src/plugins/monitor/src/monMain.c
浏览文件 @
e64bb853
...
...
@@ -171,7 +171,6 @@ static void monSaveSystemInfo();
static
void
monSaveClusterInfo
();
static
void
monSaveDnodesInfo
();
static
void
monSaveVgroupsInfo
();
static
void
monSaveSlowQueryInfo
();
static
void
monSaveDisksInfo
();
static
void
monSaveGrantsInfo
();
static
void
monSaveHttpReqInfo
();
...
...
@@ -321,7 +320,6 @@ static void *monThreadFunc(void *param) {
monSaveClusterInfo
();
}
monSaveVgroupsInfo
();
monSaveSlowQueryInfo
();
monSaveDisksInfo
();
monSaveGrantsInfo
();
monSaveHttpReqInfo
();
...
...
@@ -383,9 +381,9 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) {
tsMonitorDbName
,
TSDB_DEFAULT_USER
);
}
else
if
(
cmd
==
MON_CMD_CREATE_TB_SLOWQUERY
)
{
snprintf
(
sql
,
SQL_LENGTH
,
"create table if not exists %s.slowquery(ts timestamp,
query_id
"
"binary(%d),
username binary(%d), qid binary(%d), created_time timestamp, time bigint, end_point binary(%d)
, sql binary(%d))"
,
tsMonitorDbName
,
QUERY_ID_LEN
,
TSDB_TABLE_FNAME_LEN
-
1
,
QUERY_ID_LEN
,
TSDB_EP_LEN
,
TSDB_SLOW_QUERY_SQL_LEN
);
"create table if not exists %s.slowquery(ts timestamp,
username
"
"binary(%d),
created_time timestamp, time bigint
, sql binary(%d))"
,
tsMonitorDbName
,
TSDB_TABLE_FNAME_LEN
-
1
,
TSDB_SLOW_QUERY_SQL_LEN
);
}
else
if
(
cmd
==
MON_CMD_CREATE_TB_LOG
)
{
snprintf
(
sql
,
SQL_LENGTH
,
"create table if not exists %s.log(ts timestamp, level tinyint, "
...
...
@@ -1213,98 +1211,6 @@ static void monSaveVgroupsInfo() {
taos_free_result
(
result
);
}
static
void
monSaveSlowQueryInfo
()
{
int64_t
ts
=
taosGetTimestampUs
();
char
*
sql
=
tsMonitor
.
sql
;
int32_t
pos
=
snprintf
(
sql
,
SQL_LENGTH
,
"insert into %s.slowquery values(%"
PRId64
,
tsMonitorDbName
,
ts
);
bool
has_slowquery
=
false
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show queries"
);
int32_t
code
=
taos_errno
(
result
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
monError
(
"failed to execute cmd: show queries, reason:%s"
,
tstrerror
(
code
));
}
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int32_t
charLen
;
while
((
row
=
taos_fetch_row
(
result
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"query_id"
)
==
0
)
{
has_slowquery
=
true
;
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
charLen
<
0
)
{
monError
(
"failed to save slow_query info, reason: invalid row %s len, sql:%s"
,
(
char
*
)
row
[
i
],
tsMonitor
.
sql
);
goto
DONE
;
}
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"user"
)
==
0
)
{
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
charLen
<
0
)
{
monError
(
"failed to save slow_query info, reason: invalid row %s len, sql:%s"
,
(
char
*
)
row
[
i
],
tsMonitor
.
sql
);
goto
DONE
;
}
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"qid"
)
==
0
)
{
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
charLen
<
0
)
{
monError
(
"failed to save slow_query info, reason: invalid row %s len, sql:%s"
,
(
char
*
)
row
[
i
],
tsMonitor
.
sql
);
goto
DONE
;
}
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"created_time"
)
==
0
)
{
int64_t
create_time
=
*
(
int64_t
*
)
row
[
i
];
create_time
=
convertTimePrecision
(
create_time
,
TSDB_TIME_PRECISION_MILLI
,
TSDB_TIME_PRECISION_MICRO
);
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", %"
PRId64
""
,
create_time
);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"time"
)
==
0
)
{
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", %"
PRId64
""
,
*
(
int64_t
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"ep"
)
==
0
)
{
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
charLen
<
0
)
{
monError
(
"failed to save slow_query info, reason: invalid row %s len, sql:%s"
,
(
char
*
)
row
[
i
],
tsMonitor
.
sql
);
goto
DONE
;
}
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"sql"
)
==
0
)
{
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
charLen
<
0
)
{
monError
(
"failed to save slow_query info, reason: invalid row %s len, sql:%s"
,
(
char
*
)
row
[
i
],
tsMonitor
.
sql
);
goto
DONE
;
}
if
(
pos
<
SQL_LENGTH
)
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
-
pos
,
", "
SQL_STR_FMT
")"
,
(
char
*
)
row
[
i
]);
}
}
}
monDebug
(
"save slow query, sql:%s"
,
sql
);
if
(
!
has_slowquery
)
{
goto
DONE
;
}
void
*
res
=
taos_query
(
tsMonitor
.
conn
,
tsMonitor
.
sql
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
if
(
code
!=
0
)
{
monError
(
"failed to save slowquery info, reason:%s, sql:%s"
,
tstrerror
(
code
),
tsMonitor
.
sql
);
}
else
{
monIncSubmitReqCnt
();
monDebug
(
"successfully to save slowquery info, sql:%s"
,
tsMonitor
.
sql
);
}
DONE:
taos_free_result
(
result
);
return
;
}
static
void
monSaveDisksInfo
()
{
int64_t
ts
=
taosGetTimestampUs
();
char
*
sql
=
tsMonitor
.
sql
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录