diff --git a/debian/control b/debian/control index 274ea06..98e983e 100644 --- a/debian/control +++ b/debian/control @@ -2,10 +2,11 @@ Source: publik-infra Section: unknown Priority: optional Maintainer: Christophe Siraut -Build-Depends: debhelper-compat (= 12), python3-all, - python3-sphinx, - python3-recommonmark, - python3-stemmer +Build-Depends: debhelper-compat (= 12), + python3-all, + python3-recommonmark, + python3-sphinx, + python3-stemmer, Standards-Version: 4.1.3 Homepage: https://git.entrouvert.org X-Python3-Version: >= 3.2 @@ -17,15 +18,15 @@ Description: Documentation for doc-publik.entrouvert.com/guide-de-l-administrate Package: prometheus-entrouvert-exporter Architecture: all -Depends: ${misc:Depends}, - moreutils, - prometheus-node-exporter, - python3-apt, - python3-cryptography, - python3-dbus, - python3-git, - python3-prometheus-client, - python3-psutil, - python3-requests, - python3-systemd +Depends: moreutils, + prometheus-node-exporter, + python3-apt, + python3-cryptography, + python3-dbus, + python3-git, + python3-prometheus-client, + python3-psutil, + python3-requests, + python3-systemd, + ${misc:Depends}, Description: useful metrics exporter as node exporter textfile diff --git a/prometheus-entrouvert-exporter/prometheus-system-exporter.py b/prometheus-entrouvert-exporter/prometheus-system-exporter.py index 9ffcbc2..410ac59 100755 --- a/prometheus-entrouvert-exporter/prometheus-system-exporter.py +++ b/prometheus-entrouvert-exporter/prometheus-system-exporter.py @@ -1,26 +1,25 @@ #!/usr/bin/python3 -import apt import argparse -from cryptography import x509 -from cryptography.hazmat.backends import default_backend import datetime -import dbus -import mailbox -from git import Repo import glob import json +import mailbox import os -import psutil -import requests import shlex import subprocess -from systemd import login, journal import time +import apt +import dbus +import psutil +import requests +from cryptography import x509 +from cryptography.hazmat.backends import default_backend +from git import Repo from prometheus_client import CollectorRegistry, Gauge from prometheus_client.exposition import generate_latest from prometheus_client.parser import text_string_to_metric_families - +from systemd import journal, login JOURNALD_IGNORED_ERRORS = { 'dovecot.service': [ @@ -47,7 +46,9 @@ eo_local_changes = Gauge("eo_local_changes", "", ["ctn"], registry=registry) eo_mailboxes = Gauge("eo_mailboxes", "emails in local mailboxes", ["ctn", "name"], registry=registry) eo_munin = Gauge("eo_munin", "munin", ["ctn", "name"], registry=registry) eo_nginx = Gauge("eo_nginx", "nginx", ["ctn", "name"], registry=registry) -eo_postgresql = Gauge("eo_postgresql", "postgresql", ["ctn", "version", "cluster", "context", "name"], registry=registry) +eo_postgresql = Gauge( + "eo_postgresql", "postgresql", ["ctn", "version", "cluster", "context", "name"], registry=registry +) eo_rabbitmq = Gauge("eo_rabbitmq", "rabbitmq", ["ctn"], registry=registry) eo_threads = Gauge("eo_threads", "system threads", ["ctn"], registry=registry) eo_units = Gauge("eo_units", "systemd units", ["ctn", "name", "state"], registry=registry) @@ -192,19 +193,28 @@ def postgresql(ctn): eo_postgresql.labels(ctn, version, name, "", "running").set(cluster["running"]) if cluster["running"]: # check the archiver status - archiver_failures = run("sudo -u postgres psql -p %s -tAc 'select failed_count from pg_stat_archiver;'" % cluster["port"]) + archiver_failures = run( + "sudo -u postgres psql -p %s -tAc 'select failed_count from pg_stat_archiver;'" + % cluster["port"] + ) eo_postgresql.labels(ctn, version, name, "", "archive_failed").set(int(archiver_failures)) if "recovery" in cluster and cluster["recovery"]: # we are on a standby, check it's connected to a master - receiver_statuses = run("sudo -u postgres psql -p %s -tAc 'select status from pg_stat_wal_receiver ;'" % cluster["port"]) + receiver_statuses = run( + "sudo -u postgres psql -p %s -tAc 'select status from pg_stat_wal_receiver ;'" + % cluster["port"] + ) eo_postgresql.labels(ctn, version, name, "", "replicating").set(0) for status in receiver_statuses.splitlines(): if status == "streaming": eo_postgresql.labels(ctn, version, name, "", "replicating").inc() else: # we are on a primary... check the slots are good - slots = run("sudo -u postgres psql -p %s -tAc 'select active, slot_name, pg_wal_lsn_diff(pg_current_wal_lsn() , restart_lsn) from pg_replication_slots where active;'" % cluster["port"]) + slots = run( + "sudo -u postgres psql -p %s -tAc 'select active, slot_name, pg_wal_lsn_diff(pg_current_wal_lsn() , restart_lsn) from pg_replication_slots where active;'" + % cluster["port"] + ) active_slot_count = 0 for slot in slots.splitlines(): active, slot_name, delta = slot.split("|") @@ -214,6 +224,7 @@ def postgresql(ctn): active_slot_count += 1 eo_postgresql.labels(ctn, version, name, "", "active-slot-count").set(active_slot_count) + def rabbitmq(ctn): rabbitmqctl = "/usr/sbin/rabbitmqctl" if os.path.isfile(rabbitmqctl): diff --git a/sysadmin-doc/conf.py b/sysadmin-doc/conf.py index fea106d..a85cfd5 100644 --- a/sysadmin-doc/conf.py +++ b/sysadmin-doc/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Infrastructure de Publik documentation build configuration file, created by # sphinx-quickstart on Mon Oct 30 17:41:53 2017. @@ -52,18 +51,18 @@ source_suffix = ['.rst', '.md'] master_doc = 'index' # General information about the project. -project = u'Infrastructure de Publik' -copyright = u'2017, Entrouvert' -author = u'Entrouvert' +project = 'Infrastructure de Publik' +copyright = '2017, Entrouvert' +author = 'Entrouvert' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = '1.0' # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = '1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -272,8 +271,8 @@ latex_documents = [ ( master_doc, 'InfrastructuredePublik.tex', - u'Infrastructure de Publik Documentation', - u'Entrouvert', + 'Infrastructure de Publik Documentation', + 'Entrouvert', 'manual', ), ] @@ -315,7 +314,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, 'infrastructuredepublik', u'Infrastructure de Publik Documentation', [author], 1)] +man_pages = [(master_doc, 'infrastructuredepublik', 'Infrastructure de Publik Documentation', [author], 1)] # If true, show URL addresses after external links. # @@ -331,7 +330,7 @@ texinfo_documents = [ ( master_doc, 'InfrastructuredePublik', - u'Infrastructure de Publik Documentation', + 'Infrastructure de Publik Documentation', author, 'InfrastructuredePublik', 'One line description of project.', diff --git a/sysadmin-doc/tools/despan.py b/sysadmin-doc/tools/despan.py index adc45d7..dbe2079 100644 --- a/sysadmin-doc/tools/despan.py +++ b/sysadmin-doc/tools/despan.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- """ despan.py @@ -7,7 +6,7 @@ Pandoc filter to convert all regular text to uppercase. Code, link URLs, etc. are not affected. """ -from pandocfilters import toJSONFilter, Str +from pandocfilters import Str, toJSONFilter def despan(key, value, format, meta):