Browse Source

Merge "Don't send http_check_check metric"

Jenkins 2 years ago
parent
commit
f984c73aac

+ 15
- 4
deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_base.py View File

@@ -49,7 +49,8 @@ class Base(object):
49 49
 
50 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 54
         self.debug = False
54 55
         self.timeout = 5
55 56
         self.max_retries = 3
@@ -63,11 +64,12 @@ class Base(object):
63 64
 
64 65
         self.service_name = service_name
65 66
         self.local_check = local_check
67
+        self.disable_check_metric = disable_check_metric
66 68
 
67 69
     def config_callback(self, conf):
68 70
         for node in conf.children:
69 71
             if node.key == "Debug":
70
-                if node.values[0] in ['True', 'true']:
72
+                if node.values[0].lower() == 'true':
71 73
                     self.debug = True
72 74
             elif node.key == "Timeout":
73 75
                 self.timeout = int(node.values[0])
@@ -75,6 +77,9 @@ class Base(object):
75 77
                 self.max_retries = int(node.values[0])
76 78
             elif node.key == 'DependsOnResource':
77 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 84
     @read_callback_wrapper
80 85
     def conditional_read_callback(self):
@@ -95,11 +100,17 @@ class Base(object):
95 100
         else:
96 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 110
         metric = {
100 111
             'meta': {'service_check': self.service_name or self.plugin,
101 112
                      'local_check': self.local_check},
102
-            'values': check,
113
+            'values': value,
103 114
         }
104 115
 
105 116
         if failure is not None:

+ 73
- 0
deployment_scripts/puppet/modules/lma_collector/files/collectd/collectd_fake.py View File

@@ -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
+
16
+import logging
17
+import os
18
+
19
+
20
+log_level = logging.INFO
21
+if os.getenv('COLLECTD_DEBUG', '') == '1':
22
+    log_level = logging.DEBUG
23
+logging.basicConfig(level=log_level)
24
+
25
+
26
+class 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
+
56
+def error(msg):
57
+    logging.error(msg)
58
+
59
+
60
+def warning(msg):
61
+    logging.warning(msg)
62
+
63
+
64
+def notice(msg):
65
+    logging.notice(msg)
66
+
67
+
68
+def info(msg):
69
+    logging.info(msg)
70
+
71
+
72
+def debug(msg):
73
+    logging.debug(msg)

+ 23
- 13
deployment_scripts/puppet/modules/lma_collector/files/collectd/http_check.py View File

@@ -13,7 +13,11 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
-import collectd
16
+try:
17
+    import collectd
18
+except ImportError:
19
+    import collectd_fake as collectd
20
+
17 21
 import requests
18 22
 
19 23
 import collectd_base as base
@@ -68,23 +72,29 @@ class HTTPCheckPlugin(base.Base):
68 72
                     yield {'type_instance': name, 'values': self.FAIL}
69 73
                 else:
70 74
                     self.logger.debug(
71
-                        "Got response from {}: '{}'".format(url, r.text))
75
+                        "Got response from {}: '{}'".format(url, r.content))
72 76
                     yield {'type_instance': name, 'values': self.OK}
73 77
 
74
-plugin = HTTPCheckPlugin(collectd)
75
-
76 78
 
77
-def config_callback(conf):
78
-    plugin.config_callback(conf)
79
+plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)
79 80
 
80 81
 
81
-def notification_callback(notification):
82
-    plugin.notification_callback(notification)
82
+if __name__ == '__main__':
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()
88
+else:
89
+    def config_callback(conf):
90
+        plugin.config_callback(conf)
83 91
 
92
+    def notification_callback(notification):
93
+        plugin.notification_callback(notification)
84 94
 
85
-def read_callback():
86
-    plugin.conditional_read_callback()
95
+    def read_callback():
96
+        plugin.conditional_read_callback()
87 97
 
88
-collectd.register_config(config_callback)
89
-collectd.register_notification(notification_callback)
90
-collectd.register_read(read_callback, base.INTERVAL)
98
+    collectd.register_config(config_callback)
99
+    collectd.register_notification(notification_callback)
100
+    collectd.register_read(read_callback, base.INTERVAL)

Loading…
Cancel
Save