Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
65626152
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看板
提交
65626152
编写于
9月 23, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6452]<feature>: taoskeeper metrics collector phase 1 taosd implementation
上级
0e3fc7ed
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
125 addition
and
15 deletion
+125
-15
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+125
-15
未找到文件。
src/plugins/monitor/src/monMain.c
浏览文件 @
65626152
...
...
@@ -148,7 +148,8 @@ static void *monThreadFunc(void *param) {
if
(
tsMonitor
.
conn
==
NULL
)
{
tsMonitor
.
state
=
MON_STATE_NOT_INIT
;
tsMonitor
.
conn
=
taos_connect
(
NULL
,
"monitor"
,
tsInternalPass
,
""
,
0
);
//tsMonitor.conn = taos_connect(NULL, "monitor", tsInternalPass, "", 0);
tsMonitor
.
conn
=
taos_connect
(
NULL
,
"root"
,
"taosdata"
,
""
,
0
);
if
(
tsMonitor
.
conn
==
NULL
)
{
monError
(
"failed to connect to database, reason:%s"
,
tstrerror
(
terrno
));
continue
;
...
...
@@ -431,7 +432,6 @@ static int32_t monBuildDnodesTotalSql(char *sql) {
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
// fetch the records row by row
while
((
row
=
taos_fetch_row
(
result
)))
{
totalDnodes
++
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
...
...
@@ -457,27 +457,140 @@ static int32_t monBuildDnodesTotalSql(char *sql) {
}
static
int32_t
monBuildMnodesTotalSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
int32_t
totalMnodes
=
0
,
totalMnodesAlive
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show mnodes"
);
TAOS_ROW
row
;
while
((
row
=
taos_fetch_row
(
result
)))
{
totalMnodes
++
;
}
taos_free_result
(
result
);
return
sprintf
(
sql
,
", %d, %d"
,
totalMnodes
,
totalMnodesAlive
);
}
static
int32_t
monBuildMnodesAliveSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
static
int32_t
monGetVgroupsTotalStats
(
char
*
dbName
,
int32_t
*
totalVgroups
,
int32_t
*
totalVgroupsAlive
)
{
char
subsql
[
TSDB_DB_NAME_LEN
+
14
];
memset
(
subsql
,
0
,
sizeof
(
subsql
));
sprintf
(
subsql
,
"show %s.vgroups"
,
dbName
);
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
subsql
);
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
*
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
);
}
if
(
strncmp
((
char
*
)
row
[
i
],
"ready"
,
charLen
)
==
0
)
{
*
totalVgroupsAlive
+=
1
;
}
}
}
}
taos_free_result
(
result
);
return
0
;
}
static
int32_t
monBuildVgroupsTotalSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
int32_t
totalVgroups
=
0
,
totalVgroupsAlive
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show databases"
);
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
)
{
//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
);
}
}
}
taos_free_result
(
result
);
return
sprintf
(
sql
,
", %d, %d"
,
totalVgroups
,
totalVgroupsAlive
);
}
static
int32_t
monBuildVgroupsAliveSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
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'"
);
TAOS_ROW
row
;
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
while
((
row
=
taos_fetch_row
(
result
)))
{
*
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
);
}
if
(
strncmp
((
char
*
)
row
[
i
],
"master"
,
charLen
)
==
0
||
strncmp
((
char
*
)
row
[
i
],
"slave"
,
charLen
)
==
0
)
{
*
totalVnodesAlive
+=
1
;
}
}
}
}
taos_free_result
(
result
);
return
0
;
}
static
int32_t
monBuildVnodesTotalSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
)
;
}
int32_t
totalVnodes
=
0
,
totalVnodesAlive
=
0
;
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
"show dnodes"
);
static
int32_t
monBuildVnodesAliveSql
(
char
*
sql
)
{
return
sprintf
(
sql
,
", %d"
,
0
);
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
)
{
//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
);
}
}
}
taos_free_result
(
result
);
return
sprintf
(
sql
,
", %d, %d"
,
totalVnodes
,
totalVnodesAlive
);
}
static
int32_t
monBuildConnsTotalSql
(
char
*
sql
)
{
...
...
@@ -495,11 +608,8 @@ static void monSaveClusterInfo() {
pos
+=
monBuildMonIntervalSql
(
sql
+
pos
);
pos
+=
monBuildDnodesTotalSql
(
sql
+
pos
);
pos
+=
monBuildMnodesTotalSql
(
sql
+
pos
);
pos
+=
monBuildMnodesAliveSql
(
sql
+
pos
);
pos
+=
monBuildVgroupsTotalSql
(
sql
+
pos
);
pos
+=
monBuildVgroupsAliveSql
(
sql
+
pos
);
pos
+=
monBuildVnodesTotalSql
(
sql
+
pos
);
pos
+=
monBuildVnodesAliveSql
(
sql
+
pos
);
pos
+=
monBuildConnsTotalSql
(
sql
+
pos
);
monError
(
"sql:%s"
,
sql
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录