From 5bf4dddb43c5518e5540ed13bb1c63008823b51f Mon Sep 17 00:00:00 2001 From: Golikov Alexander Date: Tue, 12 Jan 2021 16:16:30 +0300 Subject: [PATCH] Added TextFileCollector, SVCSCollector now enabled for all zones --- README.md | 2 ++ solaris_exporter.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 789b9ee..392c6d4 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ May be it also will work on x86 platform, but this is not tested. - 2020 Feb 04. Added UpTime in UpTimeCollector. - 2020 Feb 09. Added DiskErrorCollector, ZpoolCollector, FmadmCollector, SVCSCollector, FCinfoCollector - 2020 Dec 17. Added PrtdiagCollector, MetaStatCollector, MetaDBCollector + - 2021 Jan 05. Added TextFileCollector, SVCSCollector now enabled for all zones (Thanks to Marcel Peter) ## Provides info about: - Solaris Zones CPU Usage with processor sets info (PerZoneCpuCollector); @@ -29,6 +30,7 @@ May be it also will work on x86 platform, but this is not tested. - Zpool devices health via 'zpool status' command (ZpoolCollector) - prtdiag -v return code(PrtdiagCollector) - Solaris Volume Manager disk status (MetaStatCollector, MetaDBCollector). + - Get info from text files *.prom in folder provided by text_file_path var (TextFileCollector). ## Grafana dashboard. Dashboard config is located in file grafana-dashboard-solaris.json diff --git a/solaris_exporter.py b/solaris_exporter.py index 50fd720..adaeb34 100644 --- a/solaris_exporter.py +++ b/solaris_exporter.py @@ -1,10 +1,13 @@ #!/usr/bin/python """ sparc-exporter -version 1.0 +version v2021Jan05 2020 Jan 31. Initial 2020 Feb 04. Added UpTime in UpTimeCollector. 2020 Feb 09. Added DiskErrorCollector, ZpoolCollector, FmadmCollector, SVCSCollector, FCinfoCollector + 2020 Dec 17. Added PrtdiagCollector, MetaStatCollector, MetaDBCollector + 2021 Jan 05. Added TextFileCollector, SVCSCollector now enabled for all zones (Thanks to Marcel Peter) + Written by Alexander Golikov for collecting SPARC Solaris metrics for Prometheus. Tested on Solaris 11.3.25, 11.4.4, 10u11(limited) SPARC. @@ -25,6 +28,8 @@ - System Services health via 'svcs -x' command (SVCSCollector); - Whole system health via 'fmadm faulty' (FmadmCollector), requires pfexec of '/usr/sbin/fmadm'. - Zpool devices health via 'zpool status' command (ZpoolCollector) + - Solaris Volume Manager disk status (MetaStatCollector, MetaDBCollector). + - Get info from text files *.prom in folder provided by text_file_path var (TextFileCollector). Installation. To use this exporter you need python2.7 and its modules prometheus_client, psutil. @@ -73,10 +78,13 @@ import psutil from psutil import _psutil_sunos as cext import os -from prometheus_client.core import REGISTRY, Counter, Gauge, GaugeMetricFamily, CounterMetricFamily +from prometheus_client.core import REGISTRY, Counter, Gauge, GaugeMetricFamily, CounterMetricFamily, UntypedMetricFamily +from prometheus_client.parser import text_string_to_metric_families from prometheus_client import start_http_server +from glob import glob exporter_port = 9100 +text_file_path = '/opt/solaris_exporter/' dictionaries_refresh_interval_sec = 600 disk_operations_dictionary = { 'reads': 'number of read operations', @@ -925,6 +933,25 @@ def collect(self): yield prtdiag +class TextFileCollector(object): + """ + Read Input from a textfile to include in output. Thanks to Marcel Peter + """ + TextFileCollector_run_time = Gauge('solaris_exporter_textfile_processing', 'Time spent processing request') + + def collect(self): + with self.TextFileCollector_run_time.time(): + fpath = text_file_path + fnames = glob(fpath + '*.prom') + for file_name_r in fnames: + # filename to open for read + with open(file_name_r, 'r') as text_object: + output = text_object.read() + for family in text_string_to_metric_families(output): + yield family + text_object.close + + # replace start_http_server() method to capture error messages in my_http_error_handler() # remove this to revert to prometheus_client.start_http_server from BaseHTTPServer import HTTPServer @@ -967,6 +994,8 @@ def my_http_error_handler(request, client_address): UpTimeCollector(), NetworkCollector(), DiskSpaceCollector(), + SVCSCollector(), + TextFileCollector(), ] zones, rc, timeouted = run_shell_command('/usr/sbin/zoneadm list -icp', 3) @@ -991,7 +1020,6 @@ def my_http_error_handler(request, client_address): DiskErrorCollector(), ZpoolCollector(), FCinfoCollector(), - SVCSCollector(), FmadmCollector(), PrtdiagCollector(), MetaDBCollector(),