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
ae31af1f
Commit
ae31af1f
authored
Apr 03, 2019
by
胡凯旋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix metric family
parent
88320f5b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
67 deletions
+11
-67
exporter.py
exporter.py
+1
-2
main.py
main.py
+10
-65
No files found.
exporter.py
View file @
ae31af1f
...
...
@@ -75,7 +75,7 @@ class TencentExporter(Exporter):
with_factor_metric_family
.
add_metric
(
[
'{}*{}'
.
format
(
instance_name
,
rds_factor
),
instance_type
,
service_provider
],
value
*
rds_factor
,
timestamp
)
metrics_to_export
.
extend
([
avg_metric_family
,
with_factor_metric
name
])
metrics_to_export
.
extend
([
avg_metric_family
,
with_factor_metric
_family
])
return
metrics_to_export
...
...
@@ -139,7 +139,6 @@ class AliyunExporter(Exporter):
metrics_to_export
.
extend
([
avg_metric_family
,
max_metric_family
,
with_factor_metric_family
])
print
(
metrics_to_export
)
return
metrics_to_export
if
__name__
==
"__main__"
:
...
...
main.py
View file @
ae31af1f
...
...
@@ -6,76 +6,21 @@ import math
import
yaml
from
prometheus_client
import
start_http_server
from
prometheus_client.core
import
GaugeMetricFamily
,
REGISTRY
from
prometheus_client.core
import
REGISTRY
from
aliyun
import
CMS
aliyun_cms
=
CMS
()
with
open
(
'config.yaml'
,
'r'
)
as
f
:
config
=
yaml
.
load
(
f
)
# rds_instances = settings.RDS_INSTANCES
rds_instances
=
config
[
'rds_instances'
]
queryname_metricname
=
config
[
'metrics'
]
from
exporter
import
TencentExporter
,
AliyunExporter
class
RDSCollector
(
object
):
def
__init__
(
self
):
self
.
exporter_list
=
[
TencentExporter
(),
# AliyunExporter(),
]
def
collect
(
self
):
metrics
=
[]
# 阿里云SDK查询字段与prometheus metric name的映射
# queryname_metricname = {
# 'CpuUsage': 'rds_cpu_usage_ratio',
# # 'DiskUsage': 'rds_disk_usage_ratio',
# 'MemoryUsage': 'rds_memory_usage_radio',
# 'ConnectionUsage': 'rds_connection_usage_radio',
# 'IOPSUsage': 'rds_iops_usage_radio',
# }
metrics_from_aliyun
=
{}
# all_rds_id = list(rds_instances.keys())
all_rds_id
=
rds_instances
.
keys
()
# get metrics from aliyun
for
label
in
queryname_metricname
.
keys
():
metrics_from_aliyun
[
label
]
=
[]
for
i
in
range
(
0
,
int
(
math
.
ceil
(
len
(
all_rds_id
)
/
10.0
))):
instance_id_list
=
all_rds_id
[
10
*
i
:
10
*
(
i
+
1
)]
try
:
res
=
aliyun_cms
.
get_rds_metric
(
instance_id_list
,
label
)
metrics_from_aliyun
[
label
]
.
extend
(
res
[
'Datapoints'
])
except
Exception
as
e
:
print
(
e
)
# transform to prometheus metric format
for
queryname
,
datapoints
in
metrics_from_aliyun
.
items
():
metric
=
queryname_metricname
[
queryname
]
metricname
=
metric
[
'name'
]
factor
=
metric
.
get
(
'factor'
,
None
)
avg_metric_family
=
GaugeMetricFamily
(
metricname
,
metricname
,
labels
=
[
'rds_name'
,
'type'
])
max_metricname
=
'{}_max'
.
format
(
metricname
)
max_metric_family
=
GaugeMetricFamily
(
max_metricname
,
max_metricname
,
labels
=
[
'rds_name'
,
'type'
])
with_factor_metricname
=
'{}_with_factor'
.
format
(
metricname
)
with_factor_metric_family
=
GaugeMetricFamily
(
with_factor_metricname
,
with_factor_metricname
,
labels
=
[
'rds_name'
,
'type'
])
for
point
in
datapoints
:
# rds_name = rds_instances[point['instanceId']]
rds
=
rds_instances
[
point
[
'instanceId'
]]
rds_name
=
rds
[
'name'
]
rds_type
=
rds
.
get
(
'type'
,
'master'
)
# 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor
=
rds
.
get
(
factor
,
1
)
avg_metric_family
.
add_metric
([
rds_name
,
rds_type
],
point
[
'Average'
]
/
100.0
,
point
[
'timestamp'
]
/
1000
)
max_metric_family
.
add_metric
([
rds_name
,
rds_type
],
point
[
'Maximum'
]
/
100.0
,
point
[
'timestamp'
]
/
1000
)
with_factor_metric_family
.
add_metric
([
'{}*{}'
.
format
(
rds_name
,
rds_factor
),
rds_type
],
point
[
'Average'
]
*
rds_factor
/
100.0
,
point
[
'timestamp'
]
/
1000
)
metrics
.
extend
([
avg_metric_family
,
max_metric_family
,
with_factor_metric_family
])
for
exporter
in
self
.
exporter_list
:
metrics
.
extend
(
exporter
.
export_prometheus_data
())
for
m
in
metrics
:
yield
m
...
...
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