Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:post-factum:monitoring
apcups-exporter
_service:obs_scm:apcups-exporter-src.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:apcups-exporter-src.obscpio of Package apcups-exporter
07070100000000000081A400000000000000000000000165FE147F0000018A000000000000000000000000000000000000002D00000000apcups-exporter-src/98-apcups-exporter.rulesACTION!="remove", SUBSYSTEM=="usb", ATTRS{idVendor}=="051d", ATTRS{idProduct}=="0002", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/devices/apcups", MODE="0660", OWNER="apcups-exporter", GROUP="apcups-exporter" ACTION!="remove", KERNEL=="hiddev*", ATTRS{idVendor}=="051d", ATTRS{idProduct}=="0002", MODE="0660", OWNER="apcups-exporter", GROUP="apcups-exporter", SYMLINK+="apcups-hid" 07070100000001000081ED00000000000000000000000165FE147F0000092F000000000000000000000000000000000000002400000000apcups-exporter-src/apcups-exporter#!/usr/bin/env python import fcntl import os import signal import struct import time from prometheus_client import start_http_server, Gauge, REGISTRY for i in list(REGISTRY._collector_to_names.keys()): REGISTRY.unregister(i) HIDIOCINITREPORT = 0x4805 HIDIOCGUSAGE = 0xc018480b HID_REPORT_TYPE_FEATURE = 3 HID_REPORT_ID_REMAININGCAPACITY = 0x22 HID_REPORT_ID_RUNTIMETOEMPTY = 0x23 HID_REPORT_ID_BATTERYVOLTAGE = 0x26 HID_REPORT_ID_LINEVOLTAGE = 0x31 HID_REPORT_ID_LOAD = 0x50 AUE_POLL_INTERVAL = 30 AUE_METRICS_PORT = 64905 APCUPS_REMAINING_CAPACITY = Gauge('apcups_remaining_capacity', 'APC UPS remaining capacity in percents') APCUPS_RUN_TIME_TO_EMPTY = Gauge('apcups_run_time_to_empty', 'APC UPS run time to empty in seconds') APCUPS_LINE_VOLTAGE = Gauge('apcups_line_voltage', 'APC UPS line voltage in volts') APCUPS_BATTERY_VOLTAGE = Gauge('apcups_battery_voltage', 'APC UPS battery voltage in volts') APCUPS_LOAD_PERCENTAGE = Gauge('apcups_load_percentage', 'APC UPS load in percents') fd = None def get_value(fd, id): buf = struct.pack("IIIIIi", HID_REPORT_TYPE_FEATURE, id, 0, 0, 0, 0) buf = fcntl.ioctl(fd, HIDIOCGUSAGE, buf) uref = struct.unpack("IIIIIi", buf) return uref[5] def poll_device(): fcntl.ioctl(fd, HIDIOCINITREPORT, 0) remaining_capacity = int(get_value(fd, HID_REPORT_ID_REMAININGCAPACITY)) run_time_to_empty = int(get_value(fd, HID_REPORT_ID_RUNTIMETOEMPTY)) line_voltage = int(get_value(fd, HID_REPORT_ID_LINEVOLTAGE)) battery_voltage = float(get_value(fd, HID_REPORT_ID_BATTERYVOLTAGE)) / 100 load_percentage = int(get_value(fd, HID_REPORT_ID_LOAD)) APCUPS_REMAINING_CAPACITY.set(remaining_capacity) APCUPS_RUN_TIME_TO_EMPTY.set(run_time_to_empty) APCUPS_LINE_VOLTAGE.set(line_voltage) APCUPS_BATTERY_VOLTAGE.set(battery_voltage) APCUPS_LOAD_PERCENTAGE.set(load_percentage) def graceful_exit(): fd.close() exit(os.EX_OK) def sigterm_handler(_signo, _stack_frame): graceful_exit() if __name__ == '__main__': signal.signal(signal.SIGINT, sigterm_handler) signal.signal(signal.SIGTERM, sigterm_handler) fd = open("/dev/apcups-hid", "r") ready = False while True: poll_device() if not ready: ready = True start_http_server(AUE_METRICS_PORT) time.sleep(AUE_POLL_INTERVAL) 07070100000002000081A400000000000000000000000165FE147F0000039F000000000000000000000000000000000000003200000000apcups-exporter-src/apcups-exporter-proxy.service[Unit] Requires=apcups-exporter-proxy.socket After=apcups-exporter-proxy.socket JoinsNamespaceOf=apcups-exporter.service BindsTo=apcups-exporter.service [Service] User=apcups-exporter Group=apcups-exporter CapabilityBoundingSet= RestrictAddressFamilies=AF_INET RestrictNamespaces=true IPAddressAllow=localhost IPAddressDeny=any NoNewPrivileges=true PrivateDevices=true PrivateUsers=true ProtectClock=true ProtectControlGroups=true ProtectHome=true ProtectKernelLogs=true ProtectKernelModules=true ProtectKernelTunables=true ProtectProc=invisible ProcSubset=pid ProtectSystem=strict RestrictSUIDSGID=true SystemCallArchitectures=native SystemCallFilter=@system-service SystemCallFilter=~@privileged @resources RestrictRealtime=true LockPersonality=true MemoryDenyWriteExecute=true RemoveIPC=true UMask=0066 ProtectHostname=true ExecStart=/usr/lib/systemd/systemd-socket-proxyd 127.0.0.1:64905 PrivateTmp=yes PrivateNetwork=yes 07070100000003000081A400000000000000000000000165FE147F00000044000000000000000000000000000000000000003100000000apcups-exporter-src/apcups-exporter-proxy.socket[Unit] BindsTo=apcups-exporter.service [Socket] ListenStream=64905 07070100000004000081A400000000000000000000000165FE147F000003DC000000000000000000000000000000000000002C00000000apcups-exporter-src/apcups-exporter.service[Unit] Description=Poll APC UPS device and export Prometheus metrics After=sys-subsystem-usb-devices-apcups.device BindsTo=sys-subsystem-usb-devices-apcups.device Requires=apcups-exporter-proxy.socket [Service] User=apcups-exporter Group=apcups-exporter RemoveIPC=true CapabilityBoundingSet= NoNewPrivileges=true ProtectKernelLogs=true ProtectControlGroups=true ProtectKernelModules=true PrivateMounts=true SystemCallArchitectures=native MemoryDenyWriteExecute=true RestrictNamespaces=true RestrictSUIDSGID=true ProtectHostname=true LockPersonality=true ProtectKernelTunables=true RestrictAddressFamilies=AF_INET RestrictRealtime=true ProtectSystem=strict ProtectProc=invisible ProcSubset=pid ProtectHome=true PrivateNetwork=true IPAddressAllow=localhost IPAddressDeny=any PrivateUsers=true PrivateTmp=true SystemCallFilter=@system-service SystemCallFilter=~@resources @privileged UMask=0066 ExecStart=/usr/bin/apcups-exporter [Install] WantedBy=sys-subsystem-usb-devices-apcups.device 07070100000005000081A400000000000000000000000165FE147F00000043000000000000000000000000000000000000002D00000000apcups-exporter-src/apcups-exporter.sysusersu apcups-exporter - "APC UPS exporter" - - g apcups-exporter - - - 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!12 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor