Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
gm-mysql-exporter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
system
gm-mysql-exporter
Commits
d012edb4
Commit
d012edb4
authored
Apr 03, 2019
by
胡凯旋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format tencent cpu ratio from 100 to 1
parent
fb5fb180
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
exporter.py
exporter.py
+20
-7
No files found.
exporter.py
View file @
d012edb4
...
...
@@ -47,7 +47,8 @@ class TencentExporter(Exporter):
return
data_from_tencent
def
_transfer_to_prometheus_format
(
self
,
data
):
# print(data)
# 做一步格式转换
self
.
_format_data
(
data
)
metrics_to_export
=
[]
service_provider
=
"tencent"
...
...
@@ -71,15 +72,27 @@ class TencentExporter(Exporter):
instance_type
=
instance
.
get
(
'type'
,
'master'
)
# 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor
=
instance
.
get
(
factor
,
1
)
for
timestamp
,
value
in
timestamp_value_dict
.
item
s
():
avg_metric_family
.
add_metric
([
instance_name
,
instance_type
,
service_provider
],
value
,
timestamp
)
for
value
in
timestamp_value_dict
.
value
s
():
avg_metric_family
.
add_metric
([
instance_name
,
instance_type
,
service_provider
],
value
)
with_factor_metric_family
.
add_metric
(
[
'{}*{}'
.
format
(
instance_name
,
rds_factor
),
instance_type
,
service_provider
],
value
*
rds_factor
,
timestamp
)
value
*
rds_factor
)
metrics_to_export
.
extend
([
avg_metric_family
,
with_factor_metric_family
])
return
metrics_to_export
def
_format_data
(
self
,
data
):
""" inplace change data
"""
for
label
,
instance_data_list
in
data
.
items
():
# 腾讯云CPU利用率返回的是0-100(%), 转化成 0-1
if
label
==
"CPUUseRate"
:
for
instance
in
instance_data_list
:
instance
[
'Values'
][:]
=
map
(
lambda
v
:
v
/
100
,
instance
[
'Values'
])
# 腾讯云返回的是内存使用率,通过除以配置中记录的实例的总内存得到内存使用率
elif
label
==
"MemoryUse"
:
pass
class
AliyunExporter
(
Exporter
):
def
__init__
(
self
):
...
...
@@ -132,11 +145,11 @@ class AliyunExporter(Exporter):
# 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor
=
rds
.
get
(
factor
,
1
)
avg_metric_family
.
add_metric
([
rds_name
,
rds_type
,
service_provider
],
point
[
'Average'
]
/
100.0
,
point
[
'timestamp'
]
/
1000
)
point
[
'Average'
]
/
100.0
)
max_metric_family
.
add_metric
([
rds_name
,
rds_type
,
service_provider
],
point
[
'Maximum'
]
/
100.0
,
point
[
'timestamp'
]
/
1000
)
point
[
'Maximum'
]
/
100.0
)
with_factor_metric_family
.
add_metric
([
'{}*{}'
.
format
(
rds_name
,
rds_factor
),
rds_type
,
service_provider
],
point
[
'Average'
]
*
rds_factor
/
100.0
,
point
[
'timestamp'
]
/
1000
)
point
[
'Average'
]
*
rds_factor
/
100.0
)
metrics_to_export
.
extend
([
avg_metric_family
,
max_metric_family
,
with_factor_metric_family
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment