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
3706c5f4
Commit
3706c5f4
authored
4 years ago
by
胡凯旋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log and fix
parent
0f33f775
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
20 deletions
+33
-20
exporter.py
exporter.py
+26
-20
main.py
main.py
+7
-0
No files found.
exporter.py
View file @
3706c5f4
# coding=utf-8
import
abc
import
math
import
pprint
import
time
import
json
import
logging
from
prometheus_client.core
import
GaugeMetricFamily
...
...
@@ -44,10 +44,10 @@ class TencentExporter(Exporter):
instance_to_get
=
instance_id_list
[
batch_size
*
i
:
batch_size
*
(
i
+
1
)]
try
:
res
=
self
.
monitor
.
get_cdb_metric
(
instance_to_get
,
label
,
self
.
data_interval
)
#
print
(res)
#
logging.info
(res)
data_from_tencent
[
label
]
.
extend
(
res
[
'DataPoints'
])
except
Exception
as
e
:
print
(
e
)
logging
.
error
(
e
)
return
data_from_tencent
def
_transfer_to_prometheus_format
(
self
,
data
):
...
...
@@ -69,22 +69,28 @@ class TencentExporter(Exporter):
])
if
len
(
instance_data_list
)
!=
len
(
self
.
instances
):
print
(
time
.
ctime
(),
label
,
u"取得监控数据的机器数量与配置的机器数量不一致"
,
len
(
instance_data_list
))
pprint
.
pprint
(
instance_data_list
)
logging
.
warn
(
"[label:{label}] 取得监控数据的机器数量{data_num}与配置的机器数量{ins_num}不一致"
.
format
(
label
=
label
,
data_num
=
len
(
instance_data_list
),
ins_num
=
len
(
self
.
instances
)))
for
instance_data
in
instance_data_list
:
value
=
instance_data
[
'Values'
][
-
1
]
instance_id
=
instance_data
[
'Dimensions'
][
0
][
'Value'
]
instance
=
self
.
instances
[
instance_id
]
instance_name
=
instance
[
'name'
]
instance_type
=
instance
.
get
(
'type'
,
'master'
)
instance_project
=
instance
.
get
(
'project'
,
'gengmei'
)
# 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor
=
instance
.
get
(
factor
,
1
)
avg_metric_family
.
add_metric
([
instance_name
,
instance_type
,
service_provider
,
instance_project
],
value
)
with_factor_metric_family
.
add_metric
(
[
'{}*{}'
.
format
(
instance_name
,
rds_factor
),
instance_type
,
service_provider
,
instance_project
],
value
*
rds_factor
)
try
:
value
=
instance_data
[
'Values'
][
-
1
]
instance_id
=
instance_data
[
'Dimensions'
][
0
][
'Value'
]
instance
=
self
.
instances
[
instance_id
]
instance_name
=
instance
[
'name'
]
instance_type
=
instance
.
get
(
'type'
,
'master'
)
instance_project
=
instance
.
get
(
'project'
,
'gengmei'
)
# 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor
=
instance
.
get
(
factor
,
1
)
avg_metric_family
.
add_metric
([
instance_name
,
instance_type
,
service_provider
,
instance_project
],
value
)
with_factor_metric_family
.
add_metric
(
[
'{}*{}'
.
format
(
instance_name
,
rds_factor
),
instance_type
,
service_provider
,
instance_project
],
value
*
rds_factor
)
except
Exception
as
e
:
logging
.
exception
(
e
)
logging
.
error
(
data
)
metrics_to_export
.
extend
([
avg_metric_family
,
with_factor_metric_family
])
return
metrics_to_export
...
...
@@ -122,7 +128,7 @@ class AliyunExporter(Exporter):
res
=
self
.
monitor
.
get_rds_metric
(
instance_id_list
,
label
)
metrics_from_aliyun
[
label
]
.
extend
(
res
[
'Datapoints'
])
except
Exception
as
e
:
print
(
e
)
logging
.
info
(
e
)
return
metrics_from_aliyun
...
...
@@ -163,7 +169,7 @@ class AliyunExporter(Exporter):
if
__name__
==
"__main__"
:
tencent_exporter
=
TencentExporter
()
data
=
tencent_exporter
.
export_prometheus_data
()
# #
print
(data)
# #
logging.info
(data)
# aliyun_exporter = AliyunExporter()
# data = aliyun_exporter._fetch_monitor_data()
#
print
(data)
#
logging.info
(data)
This diff is collapsed.
Click to expand it.
main.py
View file @
3706c5f4
...
...
@@ -3,6 +3,7 @@ import time
import
json
import
random
import
math
import
logging
import
yaml
from
prometheus_client
import
start_http_server
...
...
@@ -18,13 +19,19 @@ class RDSCollector(object):
]
def
collect
(
self
):
logging
.
info
(
'='
*
50
)
metrics
=
[]
for
exporter
in
self
.
exporter_list
:
metrics
.
extend
(
exporter
.
export_prometheus_data
())
logging
.
info
(
'='
*
50
)
for
m
in
metrics
:
yield
m
def
main
():
logging
.
basicConfig
(
format
=
'
%(asctime)
s
%(message)
s'
)
logging
.
getLogger
()
.
setLevel
(
logging
.
INFO
)
logging
.
info
(
'gm-mysql-exporter started'
)
REGISTRY
.
register
(
RDSCollector
())
start_http_server
(
7086
)
while
True
:
...
...
This diff is collapsed.
Click to expand it.
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