Python 2.7 to 3.x for openstack-exporter
Make required changes in openstack helm image of Prometheus-openstack-exporter to move from python 2.7 to 3.x Change-Id: I27de3d7f6b6877430751d33b940de3ead7906dc6 Co-Authored By: Steven Fitzpatrick <steven.fitzpatrick@att.com>
This commit is contained in:
parent
53cdce9b9e
commit
fefb878740
|
@ -0,0 +1,17 @@
|
|||
ARG FROM=docker.io/ubuntu:bionic
|
||||
FROM ${FROM}
|
||||
|
||||
RUN apt-get -y update \
|
||||
&& apt-get install --no-install-recommends -y python3 python3-pip curl python3-setuptools \
|
||||
&& python3 -m pip install --upgrade pip \
|
||||
&& python3 -m pip install python-dateutil requests simplejson pyyaml prometheus-client \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir /usr/local/bin/exporter
|
||||
COPY exporter /usr/local/bin/exporter
|
||||
RUN chmod +x /usr/local/bin/exporter/main.py
|
||||
|
||||
EXPOSE 9103
|
||||
|
||||
CMD ["/usr/local/bin/exporter/main.py"]
|
|
@ -1,15 +0,0 @@
|
|||
ARG FROM=docker.io/ubuntu:xenial
|
||||
FROM ${FROM}
|
||||
|
||||
RUN apt-get -y update \
|
||||
&& apt-get -y install curl python-dateutil python-requests python-simplejson python-yaml python-prometheus-client\
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir /usr/local/bin/exporter
|
||||
COPY exporter /usr/local/bin/exporter
|
||||
RUN chmod +x /usr/local/bin/exporter/main.py
|
||||
|
||||
EXPOSE 9103
|
||||
|
||||
CMD ["/usr/local/bin/exporter/main.py"]
|
|
@ -6,7 +6,7 @@ cd ${SCRIPT_DIR}/..
|
|||
|
||||
IMAGE="prometheus-openstack-exporter"
|
||||
VERSION=${VERSION:-latest}
|
||||
DISTRO=${DISTRO:-ubuntu_xenial}
|
||||
DISTRO=${DISTRO:-ubuntu_bionic}
|
||||
REGISTRY_URI=${REGISTRY_URI:-"openstackhelm/"}
|
||||
EXTRA_TAG_INFO=${EXTRA_TAG_INFO:-""}
|
||||
docker build -f ${IMAGE}/Dockerfile.${DISTRO} --network=host -t ${REGISTRY_URI}${IMAGE}:${VERSION}-${DISTRO}${EXTRA_TAG_INFO} ${extra_build_args} ${IMAGE}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,7 +14,7 @@
|
|||
|
||||
from base import OSBase
|
||||
|
||||
from urlparse import urlparse
|
||||
from urllib.parse import urlparse
|
||||
from prometheus_client import CollectorRegistry, generate_latest, Gauge
|
||||
import logging
|
||||
logging.basicConfig(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -60,7 +59,7 @@ class HypervisorStats(OSBase):
|
|||
'metrics': {'free_vcpus': 0},
|
||||
}
|
||||
nova_aggregates[agg['name']]['metrics'].update(
|
||||
{v: 0 for v in self.VALUE_MAP.values()}
|
||||
{v: 0 for v in list(self.VALUE_MAP.values())}
|
||||
)
|
||||
|
||||
r = self.osclient.get('nova', 'os-hypervisors/detail')
|
||||
|
@ -68,12 +67,12 @@ class HypervisorStats(OSBase):
|
|||
logger.warning("Could not get hypervisor statistics")
|
||||
return
|
||||
|
||||
total_stats = {v: 0 for v in self.VALUE_MAP.values()}
|
||||
total_stats = {v: 0 for v in list(self.VALUE_MAP.values())}
|
||||
total_stats['free_vcpus'] = 0
|
||||
hypervisor_stats = r.json().get('hypervisors', [])
|
||||
for stats in hypervisor_stats:
|
||||
host = stats['hypervisor_hostname']
|
||||
for k, v in self.VALUE_MAP.iteritems():
|
||||
for k, v in self.VALUE_MAP.items():
|
||||
m_val = stats.get(k, 0)
|
||||
cache_stats.append({
|
||||
'stat_name': v,
|
||||
|
@ -81,7 +80,7 @@ class HypervisorStats(OSBase):
|
|||
'host': host,
|
||||
})
|
||||
total_stats[v] += m_val
|
||||
for agg in nova_aggregates.keys():
|
||||
for agg in list(nova_aggregates.keys()):
|
||||
agg_hosts = nova_aggregates[agg]['hosts']
|
||||
if host in agg_hosts:
|
||||
nova_aggregates[agg]['metrics'][v] += m_val
|
||||
|
@ -94,7 +93,7 @@ class HypervisorStats(OSBase):
|
|||
'host': host,
|
||||
})
|
||||
total_stats['free_vcpus'] += free
|
||||
for agg in nova_aggregates.keys():
|
||||
for agg in list(nova_aggregates.keys()):
|
||||
agg_hosts = nova_aggregates[agg]['hosts']
|
||||
if host in agg_hosts:
|
||||
free = ((int(self.extra_config['cpu_ratio'] *
|
||||
|
@ -103,7 +102,7 @@ class HypervisorStats(OSBase):
|
|||
nova_aggregates[agg]['metrics']['free_vcpus'] += free
|
||||
|
||||
# Dispatch the aggregate metrics
|
||||
for agg in nova_aggregates.keys():
|
||||
for agg in list(nova_aggregates.keys()):
|
||||
agg_id = nova_aggregates[agg]['id']
|
||||
agg_total_free_ram = (
|
||||
nova_aggregates[agg]['metrics']['free_ram_MB'] +
|
||||
|
@ -114,7 +113,7 @@ class HypervisorStats(OSBase):
|
|||
(100.0 * nova_aggregates[agg]['metrics']['free_ram_MB']) /
|
||||
agg_total_free_ram,
|
||||
2)
|
||||
for k, v in nova_aggregates[agg]['metrics'].iteritems():
|
||||
for k, v in nova_aggregates[agg]['metrics'].items():
|
||||
cache_stats.append({
|
||||
'stat_name': 'aggregate_{}'.format(k),
|
||||
'stat_value': v,
|
||||
|
@ -122,7 +121,7 @@ class HypervisorStats(OSBase):
|
|||
'aggregate_id': agg_id,
|
||||
})
|
||||
# Dispatch the global metrics
|
||||
for k, v in total_stats.iteritems():
|
||||
for k, v in total_stats.items():
|
||||
cache_stats.append({
|
||||
'stat_name': 'total_{}'.format(k),
|
||||
'stat_value': v,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -16,10 +16,11 @@
|
|||
import argparse
|
||||
import yaml
|
||||
import os
|
||||
import urlparse
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
from BaseHTTPServer import HTTPServer
|
||||
from SocketServer import ForkingMixIn
|
||||
import urllib.parse
|
||||
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from http.server import HTTPServer
|
||||
from socketserver import ForkingMixIn
|
||||
from prometheus_client import CONTENT_TYPE_LATEST
|
||||
|
||||
from osclient import OSClient
|
||||
|
@ -48,9 +49,9 @@ class OpenstackExporterHandler(BaseHTTPRequestHandler):
|
|||
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
|
||||
|
||||
def do_GET(self):
|
||||
url = urlparse.urlparse(self.path)
|
||||
url = urllib.parse.urlparse(self.path)
|
||||
if url.path == '/metrics':
|
||||
output = ''
|
||||
output = b''
|
||||
for collector in collectors:
|
||||
try:
|
||||
stats = collector.get_stats()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2017 The Openstack-Helm Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
docker_images:
|
||||
- context: prometheus-openstack-exporter
|
||||
repository: openstackhelm/prometheus-openstack-exporter
|
||||
dockerfile: Dockerfile.ubuntu_xenial
|
||||
dockerfile: Dockerfile.ubuntu_bionic
|
||||
tags:
|
||||
- latest-ubuntu_xenial
|
||||
- "ubuntu_xenial-{{ currentdate }}"
|
||||
|
|
Loading…
Reference in New Issue