Commit d012edb4 authored by 胡凯旋's avatar 胡凯旋

format tencent cpu ratio from 100 to 1

parent fb5fb180
...@@ -47,7 +47,8 @@ class TencentExporter(Exporter): ...@@ -47,7 +47,8 @@ class TencentExporter(Exporter):
return data_from_tencent return data_from_tencent
def _transfer_to_prometheus_format(self, data): def _transfer_to_prometheus_format(self, data):
# print(data) # 做一步格式转换
self._format_data(data)
metrics_to_export = [] metrics_to_export = []
service_provider = "tencent" service_provider = "tencent"
...@@ -71,15 +72,27 @@ class TencentExporter(Exporter): ...@@ -71,15 +72,27 @@ class TencentExporter(Exporter):
instance_type = instance.get('type', 'master') instance_type = instance.get('type', 'master')
# 当前queryname,当前rds实例的因子,若没有配置,默认为1 # 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor = instance.get(factor, 1) rds_factor = instance.get(factor, 1)
for timestamp, value in timestamp_value_dict.items(): for value in timestamp_value_dict.values():
avg_metric_family.add_metric([instance_name, instance_type, service_provider], value, timestamp) avg_metric_family.add_metric([instance_name, instance_type, service_provider], value)
with_factor_metric_family.add_metric( with_factor_metric_family.add_metric(
['{}*{}'.format(instance_name,rds_factor), instance_type, service_provider], ['{}*{}'.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]) metrics_to_export.extend([avg_metric_family, with_factor_metric_family])
return metrics_to_export 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): class AliyunExporter(Exporter):
def __init__(self): def __init__(self):
...@@ -132,11 +145,11 @@ class AliyunExporter(Exporter): ...@@ -132,11 +145,11 @@ class AliyunExporter(Exporter):
# 当前queryname,当前rds实例的因子,若没有配置,默认为1 # 当前queryname,当前rds实例的因子,若没有配置,默认为1
rds_factor = rds.get(factor, 1) rds_factor = rds.get(factor, 1)
avg_metric_family.add_metric([rds_name, rds_type, service_provider], 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], 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], 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]) metrics_to_export.extend([avg_metric_family, max_metric_family, with_factor_metric_family])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment