Merge "Don't send http_check_check metric"
This commit is contained in:
commit
f984c73aac
|
@ -49,7 +49,8 @@ class Base(object):
|
|||
|
||||
MAX_IDENTIFIER_LENGTH = 63
|
||||
|
||||
def __init__(self, collectd, service_name=None, local_check=True):
|
||||
def __init__(self, collectd, service_name=None, local_check=True,
|
||||
disable_check_metric=False):
|
||||
self.debug = False
|
||||
self.timeout = 5
|
||||
self.max_retries = 3
|
||||
|
@ -63,11 +64,12 @@ class Base(object):
|
|||
|
||||
self.service_name = service_name
|
||||
self.local_check = local_check
|
||||
self.disable_check_metric = disable_check_metric
|
||||
|
||||
def config_callback(self, conf):
|
||||
for node in conf.children:
|
||||
if node.key == "Debug":
|
||||
if node.values[0] in ['True', 'true']:
|
||||
if node.values[0].lower() == 'true':
|
||||
self.debug = True
|
||||
elif node.key == "Timeout":
|
||||
self.timeout = int(node.values[0])
|
||||
|
@ -75,6 +77,9 @@ class Base(object):
|
|||
self.max_retries = int(node.values[0])
|
||||
elif node.key == 'DependsOnResource':
|
||||
self.depends_on_resource = node.values[0]
|
||||
elif node.key == 'DisableCheckMetric':
|
||||
if node.values[0].lower() == 'true':
|
||||
self.disable_check_metric = True
|
||||
|
||||
@read_callback_wrapper
|
||||
def conditional_read_callback(self):
|
||||
|
@ -95,11 +100,17 @@ class Base(object):
|
|||
else:
|
||||
self.dispatch_check_metric(self.OK)
|
||||
|
||||
def dispatch_check_metric(self, check, failure=None):
|
||||
def dispatch_check_metric(self, value, failure=None):
|
||||
"""Send a check metric reporting whether or not the plugin succeeded
|
||||
|
||||
"""
|
||||
if self.disable_check_metric:
|
||||
return
|
||||
|
||||
metric = {
|
||||
'meta': {'service_check': self.service_name or self.plugin,
|
||||
'local_check': self.local_check},
|
||||
'values': check,
|
||||
'values': value,
|
||||
}
|
||||
|
||||
if failure is not None:
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
log_level = logging.INFO
|
||||
if os.getenv('COLLECTD_DEBUG', '') == '1':
|
||||
log_level = logging.DEBUG
|
||||
logging.basicConfig(level=log_level)
|
||||
|
||||
|
||||
class Values(object):
|
||||
|
||||
def __init__(self, type=None, values=None, plugin_instance=None,
|
||||
type_instance=None, plugin=None, host=None, time=None,
|
||||
meta=None, interval=None):
|
||||
self._type = type
|
||||
self._values = values
|
||||
self._plugin_instance = plugin_instance
|
||||
self._type_instance = type_instance
|
||||
self._plugin = plugin
|
||||
self._host = host
|
||||
self._time = time
|
||||
self._meta = meta
|
||||
self._interval = interval
|
||||
|
||||
def dispatch(self, type=None, values=None, plugin_instance=None,
|
||||
type_instance=None, plugin=None, host=None, time=None,
|
||||
meta=None, interval=None):
|
||||
info("plugin={plugin} plugin_instance={plugin_instance} "
|
||||
"type={type} type_instance={type_instance} "
|
||||
"values={values} meta={meta}".format(
|
||||
plugin=plugin or self._plugin,
|
||||
plugin_instance=plugin_instance or self._plugin_instance,
|
||||
type=type or self._type,
|
||||
type_instance=type_instance or self._type_instance,
|
||||
values=values or self._values,
|
||||
meta=meta or self._meta,
|
||||
))
|
||||
|
||||
|
||||
def error(msg):
|
||||
logging.error(msg)
|
||||
|
||||
|
||||
def warning(msg):
|
||||
logging.warning(msg)
|
||||
|
||||
|
||||
def notice(msg):
|
||||
logging.notice(msg)
|
||||
|
||||
|
||||
def info(msg):
|
||||
logging.info(msg)
|
||||
|
||||
|
||||
def debug(msg):
|
||||
logging.debug(msg)
|
|
@ -13,7 +13,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import collectd
|
||||
try:
|
||||
import collectd
|
||||
except ImportError:
|
||||
import collectd_fake as collectd
|
||||
|
||||
import requests
|
||||
|
||||
import collectd_base as base
|
||||
|
@ -68,23 +72,29 @@ class HTTPCheckPlugin(base.Base):
|
|||
yield {'type_instance': name, 'values': self.FAIL}
|
||||
else:
|
||||
self.logger.debug(
|
||||
"Got response from {}: '{}'".format(url, r.text))
|
||||
"Got response from {}: '{}'".format(url, r.content))
|
||||
yield {'type_instance': name, 'values': self.OK}
|
||||
|
||||
plugin = HTTPCheckPlugin(collectd)
|
||||
|
||||
plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)
|
||||
|
||||
|
||||
def config_callback(conf):
|
||||
plugin.config_callback(conf)
|
||||
if __name__ == '__main__':
|
||||
plugin.urls['google_ok'] = 'https://www.google.com'
|
||||
plugin.urls['google_fail'] = 'https://www.google.com/not_found'
|
||||
plugin.expected_codes['google_ok'] = 200
|
||||
plugin.expected_codes['github_fail'] = 200
|
||||
plugin.read_callback()
|
||||
else:
|
||||
def config_callback(conf):
|
||||
plugin.config_callback(conf)
|
||||
|
||||
def notification_callback(notification):
|
||||
plugin.notification_callback(notification)
|
||||
|
||||
def notification_callback(notification):
|
||||
plugin.notification_callback(notification)
|
||||
def read_callback():
|
||||
plugin.conditional_read_callback()
|
||||
|
||||
|
||||
def read_callback():
|
||||
plugin.conditional_read_callback()
|
||||
|
||||
collectd.register_config(config_callback)
|
||||
collectd.register_notification(notification_callback)
|
||||
collectd.register_read(read_callback, base.INTERVAL)
|
||||
collectd.register_config(config_callback)
|
||||
collectd.register_notification(notification_callback)
|
||||
collectd.register_read(read_callback, base.INTERVAL)
|
||||
|
|
Loading…
Reference in New Issue