2ba39b30ab
This commit does several things at once: - Use ansible_distribution_major_version to detect which version of the EPEL repository. So we dont have to hard code the URL for either epel7 or epel 8. - Remove "stein" workaround for colelctd-openstack role. The "stein" workaround has been removed in favor of running the collectd daemon in a podman container. - Drop opendaylight support for collectd since it is no longer suupported. - Add the collectd playbook so we can run collectd in a centos 7 container going forward for "train". This commit still needs to be tested on "stein" but it will probably work anyways. - Add browbeat-containers to tox.ini for flake8 - Simplify detection of docker or podman for older versions of OSP. (sai) - Fixed typo from compute_compute to collectd_compute that caused failures on computes - clear graphite_host in install/group_vars/all.yml - Move container DockerFiles into brwobeat tree - Conditionally copy required Dockerfiles to node instead of git clone - Fix up some log file paths - Use Docker/Podman depending on release - Provide single interface(collectd.yml) which has container and baremetal playbooks - Introduce variable collectd_container in install/group_vars/all - remove unneeded selinux rebaelling (already running as priveleged) when running container - remove unneed hostfs mount - collectd container logs to file instead of STDOUT for easier debug - add collectd-ping package to collectd-openstack Dockerfile - Improve docs to reflect changes - dynamically set rabbitmq and swift paths as well for tail plugin Co-Authored-By: Sai Sindhur Malleni <smalleni@redhat.com> Change-Id: I627a696f6f1240d96a0e1d85c26d59bbbfae2b1b Signed-off-by: Charles Short <chucks@redhat.com> Signed-off-by: Sai Sindhur Malleni <smalleni@redhat.com>
122 lines
4.4 KiB
Python
122 lines
4.4 KiB
Python
#!/usr/bin/env python
|
|
# 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.
|
|
#
|
|
"""Collectd python plugin to read swift stat on an OpenStack Controller."""
|
|
from swiftclient.client import Connection
|
|
import collectd
|
|
import os
|
|
import time
|
|
|
|
|
|
class CollectdSwiftStat(object):
|
|
SWIFT_STATS = {
|
|
'x-account-object-count': 'objects',
|
|
'x-account-container-count': 'containers',
|
|
'x-account-bytes-used': 'bytes'}
|
|
|
|
def __init__(self):
|
|
self.interval = 10
|
|
self.prefix = None
|
|
self.user = None
|
|
self.password = None
|
|
self.authurl = None
|
|
self.authversion = None
|
|
self.project = None
|
|
self.swift_conn = None
|
|
|
|
def configure_callback(self, configobj):
|
|
for node in configobj.children:
|
|
val = str(node.values[0])
|
|
if node.key == 'Interval':
|
|
self.interval = int(float(val))
|
|
elif node.key == 'Prefix':
|
|
self.prefix = val
|
|
elif node.key == 'User':
|
|
self.user = val
|
|
elif node.key == 'Password':
|
|
self.password = val
|
|
elif node.key == 'AuthURL':
|
|
self.authurl = val
|
|
elif node.key == 'AuthVersion':
|
|
self.authversion = val
|
|
elif node.key == 'Project':
|
|
self.project = val
|
|
else:
|
|
collectd.warning(
|
|
'collectd-swift-stat: Unknown config key: {}'
|
|
.format(node.key))
|
|
|
|
read_plugin = True
|
|
if not self.prefix:
|
|
collectd.error('collectd-swift-stat: Prefix Undefined')
|
|
read_plugin = False
|
|
if not self.user:
|
|
collectd.error('collectd-swift-stat: User Undefined')
|
|
read_plugin = False
|
|
if not self.password:
|
|
collectd.error('collectd-swift-stat: Password Undefined')
|
|
read_plugin = False
|
|
if not self.authurl:
|
|
collectd.error('collectd-swift-stat: AuthURL Undefined')
|
|
read_plugin = False
|
|
if not self.authversion:
|
|
collectd.error('collectd-swift-stat: AuthVersion Undefined')
|
|
read_plugin = False
|
|
if not self.project:
|
|
collectd.error('collectd-swift-stat: Project Undefined')
|
|
read_plugin = False
|
|
|
|
if read_plugin:
|
|
collectd.info(
|
|
'swift_stat: Connecting with user={}, password={}, tenant={}, auth_url={},'
|
|
' auth_version={}'.format(
|
|
self.user, self.password, self.project, self.authurl, self.authversion))
|
|
|
|
self.swift_conn = self.create_swift_session()
|
|
collectd.register_read(self.read_swift_stat, self.interval)
|
|
else:
|
|
collectd.error('collectd_swift_stat: Invalid configuration')
|
|
|
|
def read_swift_stat(self, data=None):
|
|
starttime = time.time()
|
|
|
|
stats = self.swift_conn.head_account()
|
|
|
|
for m_instance, name in CollectdSwiftStat.SWIFT_STATS.iteritems():
|
|
if m_instance in stats:
|
|
metric = collectd.Values()
|
|
metric.plugin = 'swift_stat'
|
|
metric.interval = self.interval
|
|
metric.type = 'gauge'
|
|
metric.type_instance = '{}-{}'.format(self.prefix, name)
|
|
metric.values = [stats[m_instance]]
|
|
metric.dispatch()
|
|
else:
|
|
collectd.error(
|
|
'swift_stat: Can not find: {}'.format(m_instance))
|
|
|
|
timediff = time.time() - starttime
|
|
if timediff > self.interval:
|
|
collectd.warning(
|
|
'swift_stat: Took: {} > {}'
|
|
.format(round(timediff, 2), self.interval))
|
|
|
|
def create_swift_session(self):
|
|
return Connection(
|
|
authurl=self.authurl, user=self.user, key=self.password,
|
|
tenant_name=self.project, auth_version=self.authversion)
|
|
|
|
|
|
collectd_swift_stat = CollectdSwiftStat()
|
|
collectd.register_config(collectd_swift_stat.configure_callback)
|