summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-24 10:40:00 +0000
committerGerrit Code Review <review@openstack.org>2017-02-24 10:40:00 +0000
commitf984c73aacfd83cd7a296b3c89ad55d65592d9f5 (patch)
treed0c49c930472d70462f7464fd4cf10af4b341f98
parent4895cb7efb5abff4d7792296d24cb9e3c5ef492b (diff)
parent8fc21750cdf6b1f80c9d078858f7ddded2a6d6d3 (diff)
Merge "Don't send http_check_check metric"
-rw-r--r--deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py19
-rw-r--r--deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_fake.py73
-rw-r--r--deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py36
3 files changed, 111 insertions, 17 deletions
diff --git a/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py b/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py
index 31adabb..0b6646a 100644
--- a/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py
+++ b/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py
@@ -49,7 +49,8 @@ class Base(object):
49 49
50 MAX_IDENTIFIER_LENGTH = 63 50 MAX_IDENTIFIER_LENGTH = 63
51 51
52 def __init__(self, collectd, service_name=None, local_check=True): 52 def __init__(self, collectd, service_name=None, local_check=True,
53 disable_check_metric=False):
53 self.debug = False 54 self.debug = False
54 self.timeout = 5 55 self.timeout = 5
55 self.max_retries = 3 56 self.max_retries = 3
@@ -63,11 +64,12 @@ class Base(object):
63 64
64 self.service_name = service_name 65 self.service_name = service_name
65 self.local_check = local_check 66 self.local_check = local_check
67 self.disable_check_metric = disable_check_metric
66 68
67 def config_callback(self, conf): 69 def config_callback(self, conf):
68 for node in conf.children: 70 for node in conf.children:
69 if node.key == "Debug": 71 if node.key == "Debug":
70 if node.values[0] in ['True', 'true']: 72 if node.values[0].lower() == 'true':
71 self.debug = True 73 self.debug = True
72 elif node.key == "Timeout": 74 elif node.key == "Timeout":
73 self.timeout = int(node.values[0]) 75 self.timeout = int(node.values[0])
@@ -75,6 +77,9 @@ class Base(object):
75 self.max_retries = int(node.values[0]) 77 self.max_retries = int(node.values[0])
76 elif node.key == 'DependsOnResource': 78 elif node.key == 'DependsOnResource':
77 self.depends_on_resource = node.values[0] 79 self.depends_on_resource = node.values[0]
80 elif node.key == 'DisableCheckMetric':
81 if node.values[0].lower() == 'true':
82 self.disable_check_metric = True
78 83
79 @read_callback_wrapper 84 @read_callback_wrapper
80 def conditional_read_callback(self): 85 def conditional_read_callback(self):
@@ -95,11 +100,17 @@ class Base(object):
95 else: 100 else:
96 self.dispatch_check_metric(self.OK) 101 self.dispatch_check_metric(self.OK)
97 102
98 def dispatch_check_metric(self, check, failure=None): 103 def dispatch_check_metric(self, value, failure=None):
104 """Send a check metric reporting whether or not the plugin succeeded
105
106 """
107 if self.disable_check_metric:
108 return
109
99 metric = { 110 metric = {
100 'meta': {'service_check': self.service_name or self.plugin, 111 'meta': {'service_check': self.service_name or self.plugin,
101 'local_check': self.local_check}, 112 'local_check': self.local_check},
102 'values': check, 113 'values': value,
103 } 114 }
104 115
105 if failure is not None: 116 if failure is not None:
diff --git a/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_fake.py b/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_fake.py
new file mode 100644
index 0000000..f3ff34e
--- /dev/null
+++ b/deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_fake.py
@@ -0,0 +1,73 @@
1#!/usr/bin/python
2# Copyright 2015 Mirantis, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import logging
17import os
18
19
20log_level = logging.INFO
21if os.getenv('COLLECTD_DEBUG', '') == '1':
22 log_level = logging.DEBUG
23logging.basicConfig(level=log_level)
24
25
26class Values(object):
27
28 def __init__(self, type=None, values=None, plugin_instance=None,
29 type_instance=None, plugin=None, host=None, time=None,
30 meta=None, interval=None):
31 self._type = type
32 self._values = values
33 self._plugin_instance = plugin_instance
34 self._type_instance = type_instance
35 self._plugin = plugin
36 self._host = host
37 self._time = time
38 self._meta = meta
39 self._interval = interval
40
41 def dispatch(self, type=None, values=None, plugin_instance=None,
42 type_instance=None, plugin=None, host=None, time=None,
43 meta=None, interval=None):
44 info("plugin={plugin} plugin_instance={plugin_instance} "
45 "type={type} type_instance={type_instance} "
46 "values={values} meta={meta}".format(
47 plugin=plugin or self._plugin,
48 plugin_instance=plugin_instance or self._plugin_instance,
49 type=type or self._type,
50 type_instance=type_instance or self._type_instance,
51 values=values or self._values,
52 meta=meta or self._meta,
53 ))
54
55
56def error(msg):
57 logging.error(msg)
58
59
60def warning(msg):
61 logging.warning(msg)
62
63
64def notice(msg):
65 logging.notice(msg)
66
67
68def info(msg):
69 logging.info(msg)
70
71
72def debug(msg):
73 logging.debug(msg)
diff --git a/deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py b/deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py
index d84899a..774d889 100644
--- a/deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py
+++ b/deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py
@@ -13,7 +13,11 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16import collectd 16try:
17 import collectd
18except ImportError:
19 import collectd_fake as collectd
20
17import requests 21import requests
18 22
19import collectd_base as base 23import collectd_base as base
@@ -68,23 +72,29 @@ class HTTPCheckPlugin(base.Base):
68 yield {'type_instance': name, 'values': self.FAIL} 72 yield {'type_instance': name, 'values': self.FAIL}
69 else: 73 else:
70 self.logger.debug( 74 self.logger.debug(
71 "Got response from {}: '{}'".format(url, r.text)) 75 "Got response from {}: '{}'".format(url, r.content))
72 yield {'type_instance': name, 'values': self.OK} 76 yield {'type_instance': name, 'values': self.OK}
73 77
74plugin = HTTPCheckPlugin(collectd)
75
76 78
77def config_callback(conf): 79plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)
78 plugin.config_callback(conf)
79 80
80 81
81def notification_callback(notification): 82if __name__ == '__main__':
82 plugin.notification_callback(notification) 83 plugin.urls['google_ok'] = 'https://www.google.com'
84 plugin.urls['google_fail'] = 'https://www.google.com/not_found'
85 plugin.expected_codes['google_ok'] = 200
86 plugin.expected_codes['github_fail'] = 200
87 plugin.read_callback()
88else:
89 def config_callback(conf):
90 plugin.config_callback(conf)
83 91
92 def notification_callback(notification):
93 plugin.notification_callback(notification)
84 94
85def read_callback(): 95 def read_callback():
86 plugin.conditional_read_callback() 96 plugin.conditional_read_callback()
87 97
88collectd.register_config(config_callback) 98 collectd.register_config(config_callback)
89collectd.register_notification(notification_callback) 99 collectd.register_notification(notification_callback)
90collectd.register_read(read_callback, base.INTERVAL) 100 collectd.register_read(read_callback, base.INTERVAL)