Skip to content

Commit

Permalink
Add a dcache cluster label
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPickford committed Nov 28, 2019
1 parent 9bd0a86 commit 2816cb0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dcache_exporter.spec
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Summary: Prometheus exporter for dcache metrics
Name: dcache_exporter
Version: %{_version}
Release: 1
Release: 2
License: GPLv3
Source0: %{_source}
Requires: python2-prometheus_client
BuildArch: noarch
%{?systemd_requires}

%description
Expand Down
31 changes: 25 additions & 6 deletions src/dcache_exporter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python

import argparse
import copy
import httplib
import re
Expand All @@ -12,7 +13,11 @@
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn

VERSION = '0.5'
VERSION = '0.6'
PROM_PORT = 9310
PROM_ADDRESS = '::'
INFO_PORT = 22112
INFO_ADDRESS = 'localhost'

def start_http6_server(port, addr=''):
"""Starts an HTTP server for prometheus metrics as a daemon thread"""
Expand Down Expand Up @@ -91,9 +96,10 @@ class DcacheCollector(object):
ExportTag('pools', 'pool', False, [ 'active', 'queued', 'total', 'precious', 'removable', 'used', 'free' ], [], None, None),
ExportTag('poolgroups', 'poolgroup', False, [ 'active', 'queued', 'total', 'precious', 'removable', 'used', 'free' ], [], None, None) ]

def __init__(self, host, port):
def __init__(self, host, port, cluster):
self._info_host = host
self._info_port = port
self._cluster = cluster
self._tree = None
self._ns = None
self._metrics = {}
Expand Down Expand Up @@ -140,14 +146,14 @@ def _collect_metrics_set(self, element, export):
name = element.attrib.get('name')
if '@' in name:
name = name[:name.find('@')]
labels = [ (export.prefix, name) ]
labels = [ ('dcache_cluster', self._cluster), (export.prefix, name) ]
for child in element:
self._collect_metric(child, export, labels)

def _collect_all_metrics(self):
self._metrics = {}
for export in DcacheCollector.ExportTags:
elements = self._tree.findall("{0}{1}".format(self._ns, export.name))
elements = self._tree.findall('{0}{1}'.format(self._ns, export.name))
if len(elements) > 0:
for elem in elements[0]:
self._collect_metrics_set(elem, export)
Expand All @@ -159,9 +165,22 @@ def collect(self):
for metric_name in sorted(self._metrics.keys()):
yield self._metrics[metric_name]


def create_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--metrics-port', dest='metrics_port', type=int, default=PROM_PORT, help='port to export metrics on')
parser.add_argument('--metrics-address', dest='metrics_address', type=str, default=PROM_ADDRESS, help='address to export metrics on')
parser.add_argument('-c', '--cluster', dest='cluster', type=str, default='dcache_cluster', help='cluster prometheus label')
parser.add_argument('--info-port', dest='info_port', type=int, default=INFO_PORT, help='port to export metrics on')
parser.add_argument('--info-address', dest='info_address', type=str, default=INFO_ADDRESS, help='address to export metrics on')
return parser


def main():
pclient.REGISTRY.register(DcacheCollector("localhost", 22112))
start_http6_server(9310, '::')
parser = create_parser()
args = parser.parse_args()
pclient.REGISTRY.register(DcacheCollector(args.info_address, args.info_port, args.cluster))
start_http6_server(args.metrics_port, args.metrics_address)
while True:
time.sleep(10)

Expand Down

0 comments on commit 2816cb0

Please sign in to comment.