Muehlenhoff has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398072 )

Change subject: Add Prometheus exporter for WDQS Updater
......................................................................

Add Prometheus exporter for WDQS Updater

Based on previous Diamond collector

Change-Id: Icb2c084fcaa3da4fc8827eb84f0669bb37153937
---
A debian/changelog
A debian/compat
A debian/control
A debian/copyright
A debian/dirs
A debian/install
A debian/postinst
A debian/rules
A debian/service
A prometheus-wdqs-updater-exporter
10 files changed, 199 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/operations/debs/prometheus-wdqs-updater-exporter
 refs/changes/72/398072/1

diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..b612a17
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+prometheus-wdqs-updater-exporter (0.2) jessie-wikimedia; urgency=medium
+
+  * Initial release
+
+ -- Moritz Muehlenhoff <mor...@wikimedia.org>  Wed, 13 Dec 2017 16:40:36 +0000
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..11afa59
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,12 @@
+Source: prometheus-wdqs-updater-exporter
+Section: net
+Priority: extra
+Maintainer: Moritz Muehlenhoff <mor...@wikimedia.org>
+Build-Depends: debhelper (>= 9), dh-systemd (>= 1.5)
+Standards-Version: 3.9.8
+
+Package: prometheus-wdqs-updater-exporter
+Architecture: all
+Depends: python-prometheus-client, ${misc:Depends}
+Description: Prometheus exporter for WDQS Updater
+ Prometheus exporter for WDQS Updater metrics.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..57c5caf
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,22 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+
+Files: *
+Copyright: 2017 Moritz Muehlenhoff <mor...@wikimedia.org>, Filippo Giunchedi 
<fili...@wikimedia.org>, Wikimedia Foundation
+           2015 Stanislav Malyshev <smalys...@wikimedia.org>
+License: Apache-2.0
+
+License: Apache-2.0
+ 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.
+ .
+ On Debian systems, the full text of the Apache License version 2 can be found
+ in the file `/usr/share/common-licenses/Apache-2.0'.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644
index 0000000..1f11d5e
--- /dev/null
+++ b/debian/dirs
@@ -0,0 +1,2 @@
+usr/bin
+etc/prometheus
\ No newline at end of file
diff --git a/debian/install b/debian/install
new file mode 100644
index 0000000..2514ba9
--- /dev/null
+++ b/debian/install
@@ -0,0 +1 @@
+prometheus-wdqs-updater-exporter usr/bin
\ No newline at end of file
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 0000000..a43ff27
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+  configure)
+    # Add prometheus user
+    if ! getent passwd prometheus > /dev/null; then
+        adduser --quiet --system --no-create-home \
+            --group --gecos "Prometheus daemon" prometheus || true
+    fi
+
+  ;;
+
+  abort-upgrade|abort-remove|abort-deconfigure)
+    :
+  ;;
+
+  *)
+    echo "postinst called with unknown argument \`$1'" >&2
+    exit 1
+  ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..305c822
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,4 @@
+#!/usr/bin/make -f
+
+%:
+       dh $@ --with systemd
diff --git a/debian/service b/debian/service
new file mode 100644
index 0000000..e369d9f
--- /dev/null
+++ b/debian/service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Prometheus WDQS Updater exporter
+
+[Service]
+Restart=always
+User=prometheus
+ExecStart=/usr/bin/prometheus-wdqs-updater-exporter
+
+[Install]
+WantedBy=multi-user.target
diff --git a/prometheus-wdqs-updater-exporter b/prometheus-wdqs-updater-exporter
new file mode 100755
index 0000000..877c36c
--- /dev/null
+++ b/prometheus-wdqs-updater-exporter
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+# Copyright 2017 Moritz Muehlenhoff
+#                Filippo Giunchedi
+#                Wikimedia Foundation
+# Copyright 2015 Stanislav Malyshev
+# 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 argparse
+import logging
+import sys
+import time
+import urllib2
+import json
+
+from prometheus_client import start_http_server, Summary
+from prometheus_client.core import (CounterMetricFamily, GaugeMetricFamily,
+                                    REGISTRY)
+
+log = logging.getLogger(__name__)
+
+
+class PrometheusWDQSUpdaterCollector(object):
+    scrape_duration = Summary(
+            'wdqs_updater_scrape_duration_seconds', 'WDQS Updater exporter 
scrape duration')
+
+    counters = ["updates/Count", "batch-progress/Count"]
+    stats_url = 'http://localhost:8778/jolokia/'
+
+    def get_data(self, metric):
+        url = "%sread/metrics:name=%s" % (self.stats_url, metric)
+        req = urllib2.Request(url)
+        response = urllib2.urlopen(req)
+        data = json.loads(response.read())
+        if 'value' in data:
+            return data['value']
+
+    @scrape_duration.time()
+    def collect(self):
+        stats = ''
+
+        up = GaugeMetricFamily('wdqs_updater_up', 'WDQS Updater is running')
+        try:
+            url = urllib2.urlopen(self.stats_url)
+            if url.code == 200:
+                stats = json.loads(url.read())
+            up.add_metric([], 1)
+
+        except urllib2.URLError:
+            log.error('Could not connect to WDQS updater stats URL')
+            up.add_metric([], 0)
+            yield up
+            return
+
+        yield up
+
+        metrics = {
+            'updates': CounterMetricFamily('wdqs_updater_updates', ''),
+            'batch-progress': 
CounterMetricFamily('wdqs_updater_batch_progress', ''),
+        }
+
+        for counter in self.counters:
+            data = self.get_data(counter)
+            if data:
+                base_metric = counter.split('/')[0]
+                metric = metrics.get(base_metric)
+                try:
+                    value = float(data)
+                except ValueError:
+                    value = float('nan')
+                if metric:
+                    metric.add_metric([], value)
+
+        for metric in metrics.values():
+            yield metric
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-l', '--listen', metavar='ADDRESS',
+                        help='Listen on this address', default=':9194')
+    parser.add_argument('-d', '--debug', action='store_true',
+                        help='Enable debug logging')
+    args = parser.parse_args()
+
+    if args.debug:
+        logging.basicConfig(level=logging.DEBUG)
+    else:
+        logging.basicConfig(level=logging.WARNING)
+
+    address, port = args.listen.split(':', 1)
+
+    log.info('Starting wdqs_updater_exporter on %s:%s', address, port)
+
+    REGISTRY.register(PrometheusWDQSUpdaterCollector())
+    start_http_server(int(port), addr=address)
+
+    try:
+        while True:
+            time.sleep(1)
+    except KeyboardInterrupt:
+        return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main())

-- 
To view, visit https://gerrit.wikimedia.org/r/398072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb2c084fcaa3da4fc8827eb84f0669bb37153937
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/prometheus-wdqs-updater-exporter
Gerrit-Branch: master
Gerrit-Owner: Muehlenhoff <mmuhlenh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to