browbeat/browbeat-containers/collectd-openstack/files/collectd_ovsagent.py
Charles Short 2ba39b30ab Refresh collectd for "train"
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>
2019-11-05 08:08:37 -05:00

83 lines
2.8 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.
#
"""
"""
import collectd
import os
import subprocess
import time
def configure(cfg):
global INTERVAL
global interfaces
global namespaces
interfaces = []
namespaces = []
config = {c.key: c.values for c in cfg.children}
INTERVAL = config['interval'][0]
collectd.register_read(read, INTERVAL)
if 'interfaces' in config:
interfaces = config['interfaces']
if 'namespaces' in config :
namespaces = config['namespaces']
def run_command(command):
output = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
return output.communicate()
def read(data=None):
starttime = time.time()
ifs = []
ns = []
if len(interfaces) > 0 :
collectd.debug("Interfaces : {}".format(interfaces))
for interface in interfaces :
ifs.append({interface: run_command("ovs-vsctl show | grep 'Port \\\"{}' | wc -l".format(interface))[0].replace("\n","")})
if len(namespaces) > 0 :
collectd.debug("Namespaces : {}".format(namespaces))
for namespace in namespaces :
ns.append({namespace: run_command("sudo ip netns | grep {} | wc -l".format(namespace))[0].replace("\n","")})
if len(ifs) > 0 :
for i in ifs :
for value in i:
metric = collectd.Values()
metric.plugin = 'ovsagent_monitoring'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = "{}_interface_total-count".format(value)
metric.values = [i[value]]
metric.dispatch()
if len(ns) > 0 :
for n in ns :
for value in n:
metric = collectd.Values()
metric.plugin = 'ovsagent_monitoring'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = "{}_ns_total-count".format(value)
metric.values = [n[value]]
metric.dispatch()
timediff = time.time() - starttime
if timediff > INTERVAL:
collectd.warning(
'ovsagent_monitoring: Took: {} > {}'.format(
round(timediff, 2),
INTERVAL)
)
collectd.register_config(configure)