Initial version for Prometheus File Driver
-Plugin -Tests -Updates for requirements, setup, tox
This commit is contained in:
parent
5f80b9781c
commit
a94a8d8eee
1
.gitignore
vendored
1
.gitignore
vendored
@ -125,3 +125,4 @@ dmypy.json
|
||||
|
||||
# End of https://www.gitignore.io/api/python
|
||||
|
||||
.stestr/
|
||||
|
3
.stestr.conf
Normal file
3
.stestr.conf
Normal file
@ -0,0 +1,3 @@
|
||||
[DEFAULT]
|
||||
test_path=./ironic_prometheus_exporter/tests
|
||||
top_path=./
|
14
README.md
14
README.md
@ -1,3 +1,17 @@
|
||||
Ironic Prometheus Exporter
|
||||
==========================
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
After install the driver you will need to update the :ironic.conf: and add
|
||||
:file_dir: and :file_name: options
|
||||
|
||||
```
|
||||
[oslo_messaging_notifications]
|
||||
driver = prometheus_exporter
|
||||
transport_url = fake://
|
||||
file_dir=/tmp/ironic_prometheus_exporter
|
||||
file_name=myfile.txt
|
||||
```
|
||||
|
29
ironic_prometheus_exporter/messaging.py
Normal file
29
ironic_prometheus_exporter/messaging.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_messaging.notify import notifier
|
||||
|
||||
prometheus_opts = [
|
||||
cfg.StrOpt('file_name', required=True),
|
||||
cfg.StrOpt('file_dir', required=True)
|
||||
]
|
||||
|
||||
|
||||
class PrometheusFileDriver(notifier.Driver):
|
||||
|
||||
"Publish notifications into a File to be used by Prometheus"
|
||||
|
||||
def __init__(self, conf, topics, transport):
|
||||
conf.register_opts(prometheus_opts,
|
||||
group='oslo_messaging_notifications')
|
||||
self.conf = conf
|
||||
if not os.path.exists(self.conf.oslo_messaging_notifications.file_dir):
|
||||
os.makedirs(self.conf.oslo_messaging_notifications.file_dir)
|
||||
self.file_dir = self.conf.oslo_messaging_notifications.file_dir
|
||||
self.file_name = self.conf.oslo_messaging_notifications.file_name
|
||||
super(PrometheusFileDriver, self).__init__(conf, topics, transport)
|
||||
|
||||
def notify(self, ctxt, message, priority, retry):
|
||||
prometheus_file = open((self.file_dir + '/' + self.file_name), 'w')
|
||||
prometheus_file.write(str(message))
|
||||
prometheus_file.close()
|
0
ironic_prometheus_exporter/tests/__init__.py
Normal file
0
ironic_prometheus_exporter/tests/__init__.py
Normal file
23
ironic_prometheus_exporter/tests/test_driver.py
Normal file
23
ironic_prometheus_exporter/tests/test_driver.py
Normal file
@ -0,0 +1,23 @@
|
||||
import oslo_messaging
|
||||
|
||||
from oslo_messaging.tests import utils as test_utils
|
||||
|
||||
|
||||
class TestPrometheusFileNotifier(test_utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPrometheusFileNotifier, self).setUp()
|
||||
|
||||
def test_notifier(self):
|
||||
transport = oslo_messaging.get_notification_transport(self.conf)
|
||||
my_notifier = oslo_messaging.Notifier(transport,
|
||||
driver='prometheus_exporter',
|
||||
topics=['my_topics'])
|
||||
self.config(file_name='test.txt',
|
||||
file_dir='/tmp/ironic_prometheus_exporter',
|
||||
group='oslo_messaging_notifications')
|
||||
self.assertEqual(self.conf.oslo_messaging_notifications.file_name,
|
||||
"test.txt")
|
||||
self.assertEqual(self.conf.oslo_messaging_notifications.file_dir,
|
||||
'/tmp/ironic_prometheus_exporter')
|
||||
my_notifier.debug({}, "My Event", 'Payload')
|
@ -2,3 +2,5 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
flake8
|
||||
stevedore>=1.20.0 # Apache-2.0
|
||||
oslo.messaging!=9.0.0 # Apache-2.0
|
||||
oslotest>=2.15.0 # Apache-2.0
|
||||
stestr>=2.0.0 # Apache-2.0
|
||||
|
@ -23,4 +23,4 @@ packages =
|
||||
|
||||
[entry_points]
|
||||
oslo.messaging.notify.drivers =
|
||||
simplefile = ironic_prometheus_exporter.messaging:FileDriver
|
||||
prometheus_exporter = ironic_prometheus_exporter.messaging:PrometheusFileDriver
|
||||
|
3
tox.ini
3
tox.ini
@ -10,7 +10,7 @@ setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
PYTHONWARNINGS=default::DeprecationWarning
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
commands = python setup.py test
|
||||
commands = stestr run {posargs}
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python3
|
||||
@ -22,7 +22,6 @@ commands = {posargs}
|
||||
|
||||
[flake8]
|
||||
ignore = E129
|
||||
|
||||
show-source = True
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||
|
Loading…
Reference in New Issue
Block a user