Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
29238fa4
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看板
提交
29238fa4
编写于
9月 23, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6452]<feature>: taoskeeper metrics collector phase 1 taosd implementation
上级
65626152
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
37 deletion
+60
-37
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+60
-37
未找到文件。
src/plugins/monitor/src/monMain.c
浏览文件 @
29238fa4
...
...
@@ -181,7 +181,7 @@ static void *monThreadFunc(void *param) {
}
if
(
tsMonitor
.
state
==
MON_STATE_INITED
)
{
if
(
accessTimes
%
tsMonitorInterval
==
0
)
{
if
(
accessTimes
%
tsMonitorInterval
==
0
||
accessTimes
==
1
)
{
monSaveSystemInfo
();
monSaveClusterInfo
();
}
...
...
@@ -408,6 +408,17 @@ static void monSaveSystemInfo() {
}
}
static
int32_t
monGetRowElemCharLen
(
TAOS_FIELD
field
,
char
*
rowElem
)
{
int32_t
charLen
=
varDataLen
(
rowElem
-
VARSTR_HEADER_SIZE
);
if
(
field
.
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
field
.
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
field
.
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
return
charLen
;
}
static
int32_t
monBuildFirstEpSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
",
\"
%s
\"
"
,
tsFirst
);
}
...
...
@@ -417,7 +428,26 @@ static int32_t monBuildVersionSql(char *sql) {
}
static
int32_t
monBuildMasterUptimeSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
int64_t
masterUptime
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show mnodes"
);
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"role_time"
)
==
0
)
{
int64_t
now
=
taosGetTimestamp
(
TSDB_TIME_PRECISION_MILLI
);
//master uptime in seconds
masterUptime
=
(
now
-
*
(
int64_t
*
)
row
[
i
])
/
1000
;
}
}
}
taos_free_result
(
result
);
return
sprintf
(
sql
,
", %"
PRId64
,
masterUptime
);
}
static
int32_t
monBuildMonIntervalSql
(
char
*
sql
)
{
...
...
@@ -436,12 +466,7 @@ static int32_t monBuildDnodesTotalSql(char *sql) {
totalDnodes
++
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"status"
)
==
0
)
{
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
);
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
"ready"
,
charLen
)
==
0
)
{
totalDnodesAlive
++
;
printf
(
"Gavin0- row:%s, charLen:%d
\n
"
,
(
char
*
)
row
[
i
],
charLen
);
...
...
@@ -459,10 +484,22 @@ static int32_t monBuildDnodesTotalSql(char *sql) {
static
int32_t
monBuildMnodesTotalSql
(
char
*
sql
)
{
int32_t
totalMnodes
=
0
,
totalMnodesAlive
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show mnodes"
);
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
totalMnodes
++
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"role"
)
==
0
)
{
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
"master"
,
charLen
)
==
0
||
strncmp
((
char
*
)
row
[
i
],
"slave"
,
charLen
)
==
0
)
{
totalMnodesAlive
+=
1
;
}
}
}
}
taos_free_result
(
result
);
...
...
@@ -470,6 +507,7 @@ static int32_t monBuildMnodesTotalSql(char *sql) {
return
sprintf
(
sql
,
", %d, %d"
,
totalMnodes
,
totalMnodesAlive
);
}
static
int32_t
monGetVgroupsTotalStats
(
char
*
dbName
,
int32_t
*
totalVgroups
,
int32_t
*
totalVgroupsAlive
)
{
char
subsql
[
TSDB_DB_NAME_LEN
+
14
];
...
...
@@ -485,13 +523,7 @@ static int32_t monGetVgroupsTotalStats(char *dbName, int32_t *totalVgroups,
*
totalVgroups
+=
1
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"status"
)
==
0
)
{
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
);
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
"ready"
,
charLen
)
==
0
)
{
*
totalVgroupsAlive
+=
1
;
}
...
...
@@ -515,12 +547,6 @@ static int32_t monBuildVgroupsTotalSql(char *sql) {
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
//database name
if
(
strcmp
(
fields
[
i
].
name
,
"name"
)
==
0
)
{
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
);
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
monGetVgroupsTotalStats
((
char
*
)
row
[
i
],
&
totalVgroups
,
&
totalVgroupsAlive
);
}
}
...
...
@@ -535,8 +561,8 @@ static int32_t monGetVnodesTotalStats(char *ep, int32_t *totalVnodes,
int32_t
*
totalVnodesAlive
)
{
char
subsql
[
TSDB_EP_LEN
+
15
];
memset
(
subsql
,
0
,
sizeof
(
subsql
));
//
sprintf(subsql, "show vnodes \"%s\"", ep);
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show vnodes 'ubuntu:6030'"
);
sprintf
(
subsql
,
"show vnodes
\"
%s
\"
"
,
ep
);
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
subsql
);
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
...
...
@@ -546,13 +572,7 @@ static int32_t monGetVnodesTotalStats(char *ep, int32_t *totalVnodes,
*
totalVnodes
+=
1
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"status"
)
==
0
)
{
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
);
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
"master"
,
charLen
)
==
0
||
strncmp
((
char
*
)
row
[
i
],
"slave"
,
charLen
)
==
0
)
{
*
totalVnodesAlive
+=
1
;
...
...
@@ -577,12 +597,6 @@ static int32_t monBuildVnodesTotalSql(char *sql) {
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
//database name
if
(
strcmp
(
fields
[
i
].
name
,
"end_point"
)
==
0
)
{
int32_t
charLen
=
varDataLen
((
char
*
)
row
[
i
]
-
VARSTR_HEADER_SIZE
);
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
charLen
<=
fields
[
i
].
bytes
&&
charLen
>=
0
);
}
else
{
assert
(
charLen
<=
fields
[
i
].
bytes
*
TSDB_NCHAR_SIZE
&&
charLen
>=
0
);
}
monGetVnodesTotalStats
((
char
*
)
row
[
i
],
&
totalVnodes
,
&
totalVnodesAlive
);
}
}
...
...
@@ -594,7 +608,16 @@ static int32_t monBuildVnodesTotalSql(char *sql) {
}
static
int32_t
monBuildConnsTotalSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d)"
,
0
);
int32_t
totalConns
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show connections"
);
TAOS_ROW
row
;
while
((
row
=
taos_fetch_row
(
result
)))
{
totalConns
++
;
}
taos_free_result
(
result
);
return
sprintf
(
sql
,
", %d)"
,
totalConns
);
}
static
void
monSaveClusterInfo
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录