Merge "Add plugin Calico Felix"
diff --git a/collectd/files/collectd_http_check.conf b/collectd/files/collectd_http_check.conf
index 8c3673a..bb19265 100644
--- a/collectd/files/collectd_http_check.conf
+++ b/collectd/files/collectd_http_check.conf
@@ -1,15 +1,31 @@
{%- if plugin.get('url', {})|length > 0 %}
-Import "http_check"
+Import "collectd_http_check"
-<Module "http_check">
+<Module "collectd_http_check">
MaxRetries "3"
Timeout "1"
+ PollingInterval "{{ plugin.polling_interval|default("10") }}"
{%- for name, params in plugin.url.iteritems() %}
ExpectedCode "{{ name }}" "{{ params.expected_code }}"
Url "{{ name }}" "{{ params.url }}"
{%- if params.get('expected_content') %}
ExpectedContent "{{ name }}" "{{ params.expected_content|replace('"','\\"') }}"
{%- endif %}
+ {%- if params.get('metric_name') %}
+ MetricName "{{ name }}" "{{ params.metric_name }}"
+ {%- endif %}
+ {%- if params.get('discard_hostname') %}
+ DiscardHostname "{{ name }}" "{{ params.discard_hostname }}"
+ {%- endif %}
+ {%- if params.verify is defined %}
+ Verify "{{ name }}" "{{ params.verify }}"
+ {%- endif %}
+ {%- if params.get('client_cert') %}
+ ClientCert "{{ name }}" "{{ params.client_cert }}"
+ {%- endif %}
+ {%- if params.get('client_key') %}
+ ClientKey "{{ name }}" "{{ params.client_key }}"
+ {%- endif %}
{%- endfor %}
</Module>
{%- endif %}
diff --git a/collectd/files/plugin/collectd_base.py b/collectd/files/plugin/collectd_base.py
index 6643693..36c0060 100644
--- a/collectd/files/plugin/collectd_base.py
+++ b/collectd/files/plugin/collectd_base.py
@@ -122,9 +122,10 @@
"""Iterate over the collected metrics
This class must be implemented by the subclass and should yield dict
- objects that represent the collected values. Each dict has 6 keys:
+ objects that represent the collected values. Each dict has 7 keys:
- 'values', a scalar number or a list of numbers if the type
defines several datasources.
+ - 'plugin' (optional)
- 'type_instance' (optional)
- 'plugin_instance' (optional)
- 'type' (optional, default='gauge')
@@ -153,9 +154,9 @@
(self.plugin, type_instance[:24], len(type_instance),
self.MAX_IDENTIFIER_LENGTH))
- plugin_instance = metric.get('plugin_instance', self.plugin_instance)
+ plugin_instance = metric.get('plugin_instance') or self.plugin_instance
v = self.collectd.Values(
- plugin=self.plugin,
+ plugin=metric.get('plugin') or self.plugin,
host=metric.get('hostname', ''),
type=metric.get('type', 'gauge'),
plugin_instance=plugin_instance,
diff --git a/collectd/files/plugin/collectd_http_check.py b/collectd/files/plugin/collectd_http_check.py
new file mode 100644
index 0000000..897bae7
--- /dev/null
+++ b/collectd/files/plugin/collectd_http_check.py
@@ -0,0 +1,196 @@
+#!/usr/bin/python
+# Copyright 2016 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.
+
+if __name__ == '__main__':
+ import collectd_fake as collectd
+else:
+ import collectd
+
+import collectd_base as base
+import requests
+
+NAME = 'http_check'
+
+
+class HTTPCheckPlugin(base.Base):
+
+ def __init__(self, *args, **kwargs):
+ super(HTTPCheckPlugin, self).__init__(*args, **kwargs)
+ self.plugin = NAME
+ self.urls = {}
+ self.expected_codes = {}
+ self.expected_contents = {}
+ self.verify = {}
+ self.client_keys = {}
+ self.client_certs = {}
+
+ self.timeout = 3
+ self.max_retries = 2
+ self.metric_names = {}
+ self.discard_hostnames = {}
+
+ self.interval = base.INTERVAL
+ self.polling_interval = base.INTERVAL
+
+ self.sessions = {}
+ self._threads = {}
+
+ def shutdown_callback(self):
+ for tid, t in self._threads.items():
+ if t.is_alive():
+ self.logger.info('Waiting for {} thread to finish'.format(tid))
+ t.stop()
+ t.join()
+
+ def config_callback(self, config):
+ super(HTTPCheckPlugin, self).config_callback(config)
+ for node in config.children:
+ if node.key == "Url":
+ self.urls[node.values[0]] = node.values[1]
+ elif node.key == 'MetricName':
+ self.metric_names[node.values[0]] = node.values[1]
+ elif node.key == 'DiscardHostname':
+ if node.values[1].lower() == 'true':
+ self.discard_hostnames[node.values[0]] = True
+ elif node.key == 'ExpectedCode':
+ self.expected_codes[node.values[0]] = int(node.values[1])
+ elif node.key == 'ExpectedContent':
+ self.expected_contents[node.values[0]] = node.values[1]
+ elif node.key == 'Verify':
+ if node.values[1].lower() == 'false':
+ self.verify[node.values[0]] = False
+ else:
+ self.verify[node.values[0]] = node.values[1]
+ elif node.key == 'ClientCert':
+ self.client_certs[node.values[0]] = node.values[1]
+ elif node.key == 'ClientKey':
+ self.client_keys[node.values[0]] = node.values[1]
+
+ for name, url in self.urls.items():
+ session = requests.Session()
+ session.mount(
+ 'http://',
+ requests.adapters.HTTPAdapter(max_retries=self.max_retries)
+ )
+ if url.startswith('https'):
+ session.mount(
+ 'https://',
+ requests.adapters.HTTPAdapter(max_retries=self.max_retries)
+ )
+
+ session.verify = self.verify.get(name, True)
+ if self.client_certs.get(name) and self.client_keys.get(name):
+ session.cert = (self.client_certs.get(name), self.client_keys.get(name))
+ elif self.client_certs.get(name):
+ session.cert = self.client_certs.get(name)
+
+ self.sessions[name] = session
+
+ def check_url(self, name, url):
+
+ def get():
+ try:
+ r = self.sessions[name].get(url, timeout=self.timeout)
+ except Exception as e:
+ self.logger.warning("Got exception for '{}': {}".format(
+ url, e)
+ )
+ status = self.FAIL
+ else:
+
+ expected_code = self.expected_codes.get(name, 200)
+ if r.status_code != expected_code:
+ self.logger.warning(
+ ("{} ({}) responded with code {} "
+ "while {} is expected").format(name, url,
+ r.status_code,
+ expected_code))
+ status = self.FAIL
+ else:
+ self.logger.debug(
+ "Got response from {}: '{}'".format(url, r.content))
+ status = self.OK
+ expected_content = self.expected_contents.get(name)
+ if expected_content:
+ if r.content != expected_content:
+ status = self.FAIL
+ self.logger.warning(
+ 'Content "{}" does not match "{}"'.format(
+ r.content[0:30], expected_content
+ ))
+ return [status]
+
+ if url not in self._threads:
+ t = base.AsyncPoller(self.collectd,
+ get,
+ self.polling_interval,
+ url)
+ t.start()
+ self._threads[url] = t
+
+ t = self._threads[url]
+ if not t.is_alive():
+ self.logger.warning("Unexpected end of the thread {}".format(
+ t.name))
+ del self._threads[url]
+ return []
+
+ return t.results
+
+ def itermetrics(self):
+ for name, url in self.urls.items():
+ r = self.check_url(name, url)
+ if r:
+ meta = {'service': name}
+ if self.discard_hostnames.get(name):
+ meta['discard_hostname'] = True
+
+ yield {'meta': meta,
+ 'values': r,
+ 'plugin': self.metric_names.get(name),
+ }
+
+
+plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)
+
+
+def config_callback(conf):
+ plugin.config_callback(conf)
+
+
+def notification_callback(notification):
+ plugin.notification_callback(notification)
+
+
+def read_callback():
+ plugin.conditional_read_callback()
+
+
+if __name__ == '__main__':
+ plugin.urls['google_ok'] = 'https://www.google.com'
+ plugin.urls['google_fail'] = 'https://www.google.com/not_found'
+ plugin.urls['no_network'] = 'https://127.0.0.2:999'
+ plugin.expected_codes['google_ok'] = 200
+ plugin.expected_codes['google_fail'] = 200
+ collectd.load_configuration(plugin)
+ plugin.read_callback()
+ import time
+ time.sleep(base.INTERVAL)
+ plugin.read_callback()
+ plugin.shutdown_callback()
+else:
+ collectd.register_config(config_callback)
+ collectd.register_notification(notification_callback)
+ collectd.register_read(read_callback, base.INTERVAL)
diff --git a/collectd/files/plugin/collectd_openstack.py b/collectd/files/plugin/collectd_openstack.py
index 84b0092..a8a72b7 100644
--- a/collectd/files/plugin/collectd_openstack.py
+++ b/collectd/files/plugin/collectd_openstack.py
@@ -44,13 +44,14 @@
"""
EXPIRATION_TOKEN_DELTA = datetime.timedelta(0, 30)
- def __init__(self, username, password, tenant, keystone_url, timeout,
- logger, max_retries):
+ def __init__(self, username, password, tenant, keystone_url, region,
+ timeout, logger, max_retries):
self.logger = logger
self.username = username
self.password = password
self.tenant_name = tenant
self.keystone_url = keystone_url
+ self.region = region
self.service_catalog = []
self.tenant_id = None
self.timeout = timeout
@@ -108,6 +109,9 @@
self.service_catalog = []
for item in data['access']['serviceCatalog']:
endpoint = item['endpoints'][0]
+ if self.region and self.region != endpoint['region']:
+ continue
+
self.service_catalog.append({
'name': item['name'],
'region': endpoint['region'],
@@ -169,6 +173,7 @@
self.password = None
self.tenant_name = None
self.keystone_url = None
+ self.region = None
self.os_client = None
self.extra_config = {}
self._threads = {}
@@ -287,6 +292,8 @@
self.tenant_name = node.values[0]
elif node.key == 'KeystoneUrl':
self.keystone_url = node.values[0]
+ elif node.key == 'Region':
+ self.region = node.values[0]
elif node.key == 'PaginationLimit':
self.pagination_limit = int(node.values[0])
elif node.key == 'PollingInterval':
@@ -303,7 +310,8 @@
self.os_client = OSClient(self.username, self.password,
self.tenant_name, self.keystone_url,
- self.timeout, self.logger, self.max_retries)
+ self.region, self.timeout, self.logger,
+ self.max_retries)
def get_objects(self, project, object_name, api_version='',
params=None, detail=False, since=False):
diff --git a/collectd/files/plugin/http_check.py b/collectd/files/plugin/http_check.py
deleted file mode 100644
index 1002928..0000000
--- a/collectd/files/plugin/http_check.py
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/usr/bin/python
-# Copyright 2016 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.
-
-if __name__ == '__main__':
- import collectd_fake as collectd
-else:
- import collectd
-
-import collectd_base as base
-import requests
-
-NAME = 'http_check'
-
-
-class HTTPCheckPlugin(base.Base):
-
- def __init__(self, *args, **kwargs):
- super(HTTPCheckPlugin, self).__init__(*args, **kwargs)
- self.plugin = NAME
- self.session = requests.Session()
- self.session.mount(
- 'http://',
- requests.adapters.HTTPAdapter(max_retries=self.max_retries)
- )
- self.session.mount(
- 'https://',
- requests.adapters.HTTPAdapter(max_retries=self.max_retries)
- )
- self.urls = {}
- self.expected_codes = {}
- self.expected_contents = {}
-
- def config_callback(self, config):
- super(HTTPCheckPlugin, self).config_callback(config)
- for node in config.children:
- if node.key == "Url":
- self.urls[node.values[0]] = node.values[1]
- elif node.key == 'ExpectedCode':
- self.expected_codes[node.values[0]] = int(node.values[1])
- elif node.key == 'ExpectedContent':
- self.expected_contents[node.values[0]] = node.values[1]
-
- def itermetrics(self):
- for name, url in self.urls.items():
- try:
- r = self.session.get(url, timeout=self.timeout)
- except Exception as e:
- self.logger.warning("Got exception for '{}': {}".format(
- url, e)
- )
- status = self.FAIL
- else:
-
- expected_code = self.expected_codes.get(name, 200)
- if r.status_code != expected_code:
- self.logger.warning(
- ("{} ({}) responded with code {} "
- "while {} is expected").format(name, url,
- r.status_code,
- expected_code))
- status = self.FAIL
- else:
- self.logger.debug(
- "Got response from {}: '{}'".format(url, r.content))
- status = self.OK
- expected_content = self.expected_contents.get(name)
- if expected_content:
- if r.content != expected_content:
- status = self.FAIL
- self.logger.warning(
- 'Content "{}" does not match "{}"'.format(
- r.content[0:30], expected_content
- ))
-
- yield {'type_instance': name, 'values': status }
-
-
-plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)
-
-
-def config_callback(conf):
- plugin.config_callback(conf)
-
-
-def notification_callback(notification):
- plugin.notification_callback(notification)
-
-
-def read_callback():
- plugin.conditional_read_callback()
-
-
-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:
- collectd.register_config(config_callback)
- collectd.register_notification(notification_callback)
- collectd.register_read(read_callback, base.INTERVAL)
diff --git a/collectd/map.jinja b/collectd/map.jinja
index 4464c9c..1077513 100644
--- a/collectd/map.jinja
+++ b/collectd/map.jinja
@@ -25,7 +25,7 @@
'automatic_starting': True,
},
'RedHat': {
- 'pkgs': ['collectd', 'collectd-ping', 'net-snmp', 'PyYAML'],
+ 'pkgs': ['collectd', 'collectd-ping', 'collectd-netlink', 'net-snmp', 'PyYAML'],
'service': 'collectd',
'defaults_file': '/etc/sysconfig/collectd',
'config_file': '/etc/collectd.conf',
diff --git a/collectd/meta/collectd.yml b/collectd/meta/collectd.yml
index c8391c0..71731ae 100644
--- a/collectd/meta/collectd.yml
+++ b/collectd/meta/collectd.yml
@@ -57,3 +57,9 @@
plugin: python
template: collectd/files/collectd_http_check.conf
url: {}
+
+remote_plugin:
+ collectd_http_check:
+ plugin: python
+ template: collectd/files/collectd_http_check.conf
+ url: {}