Merge "Add white list for reporting metrics"
This commit is contained in:
commit
75ba59793a
|
@ -2,6 +2,10 @@
|
|||
init_config:
|
||||
# Timeout on cAdvisor requests
|
||||
# connection_timeout: 3
|
||||
# white_list:
|
||||
# - cpu.system_time_sec
|
||||
# - mem.used_bytes
|
||||
# - net.in_bytes_sec
|
||||
|
||||
instances:
|
||||
# URL of cAdvisor to connect to.
|
||||
|
|
|
@ -31,9 +31,9 @@ class AgentCheck(util.Dimensions):
|
|||
super(AgentCheck, self).__init__(agent_config)
|
||||
self.name = name
|
||||
self.init_config = init_config
|
||||
self.white_list = init_config.get('white_list', None)
|
||||
self.hostname = util.get_hostname()
|
||||
self.log = logging.getLogger('%s.%s' % (__name__, name))
|
||||
|
||||
threshold = agent_config.get('recent_point_threshold', None)
|
||||
tenant_id = agent_config.get('global_delegated_tenant', None)
|
||||
self.aggregator = (
|
||||
|
@ -49,6 +49,23 @@ class AgentCheck(util.Dimensions):
|
|||
"""
|
||||
return len(self.instances)
|
||||
|
||||
def submit_metric(self, metric, value, metric_type, dimensions,
|
||||
delegated_tenant, hostname, device_name, value_meta,
|
||||
timestamp=None):
|
||||
# If there is no white list, then report all the metrics
|
||||
# If there is a white list, then only report the metrics listed in
|
||||
# white list
|
||||
if self.white_list is None or metric in self.white_list:
|
||||
self.aggregator.submit_metric(metric,
|
||||
value,
|
||||
metric_type,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta,
|
||||
timestamp)
|
||||
|
||||
def gauge(self, metric, value, dimensions=None, delegated_tenant=None, hostname=None,
|
||||
device_name=None, timestamp=None, value_meta=None):
|
||||
"""Record the value of a gauge, with optional dimensions, hostname, value metadata and device name.
|
||||
|
@ -62,15 +79,15 @@ class AgentCheck(util.Dimensions):
|
|||
:param timestamp: (optional) The timestamp for this metric value
|
||||
:param value_meta: Additional metadata about this value
|
||||
"""
|
||||
self.aggregator.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Gauge,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta,
|
||||
timestamp)
|
||||
self.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Gauge,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta,
|
||||
timestamp)
|
||||
|
||||
def increment(self, metric, value=1, dimensions=None, delegated_tenant=None,
|
||||
hostname=None, device_name=None, value_meta=None):
|
||||
|
@ -84,14 +101,14 @@ class AgentCheck(util.Dimensions):
|
|||
:param device_name: (optional) The device name for this metric
|
||||
:param value_meta: Additional metadata about this value
|
||||
"""
|
||||
self.aggregator.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Counter,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
self.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Counter,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
|
||||
def decrement(self, metric, value=1, dimensions=None, delegated_tenant=None,
|
||||
hostname=None, device_name=None, value_meta=None):
|
||||
|
@ -106,14 +123,14 @@ class AgentCheck(util.Dimensions):
|
|||
:param value_meta: Additional metadata about this value
|
||||
"""
|
||||
value *= -1
|
||||
self.aggregator.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Counter,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
self.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Counter,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
|
||||
def rate(self, metric, value, dimensions=None, delegated_tenant=None,
|
||||
hostname=None, device_name=None, value_meta=None):
|
||||
|
@ -130,14 +147,14 @@ class AgentCheck(util.Dimensions):
|
|||
:param device_name: (optional) The device name for this metric
|
||||
:param value_meta: Additional metadata about this value
|
||||
"""
|
||||
self.aggregator.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Rate,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
self.submit_metric(metric,
|
||||
value,
|
||||
metrics_pkg.Rate,
|
||||
dimensions,
|
||||
delegated_tenant,
|
||||
hostname,
|
||||
device_name,
|
||||
value_meta)
|
||||
|
||||
def get_metrics(self, prettyprint=False):
|
||||
"""Get all metrics, including the ones that are tagged.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
|
||||
import requests
|
||||
import six
|
||||
|
||||
from monasca_agent.collector.checks import AgentCheck
|
||||
from monasca_agent.collector.checks import utils
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||
|
||||
import fcntl
|
||||
import json
|
||||
|
@ -34,7 +34,8 @@ def _create_agent_conf():
|
|||
""".format(hostname=HOSTNAME)
|
||||
)
|
||||
|
||||
config = monasca_agent.common.config.Config(conf_file)
|
||||
config_obj = monasca_agent.common.config.Config(conf_file)
|
||||
config = config_obj.get_config(sections='Main')
|
||||
# clean up
|
||||
rmtree(tempdir, ignore_errors=True)
|
||||
return config
|
||||
|
@ -52,9 +53,9 @@ class MockJsonPlugin(json_plugin.JsonPlugin):
|
|||
def __init__(self):
|
||||
super(MockJsonPlugin, self).__init__(
|
||||
name='json_plugin',
|
||||
init_config=_create_agent_conf(),
|
||||
init_config={},
|
||||
instances=[],
|
||||
agent_config={}
|
||||
agent_config=_create_agent_conf()
|
||||
)
|
||||
self._metrics = []
|
||||
|
||||
|
|
Loading…
Reference in New Issue