Last active
November 8, 2022 16:21
-
-
Save markus-k/42194d5aa6f856c7e21b0acbd23dc2cf to your computer and use it in GitHub Desktop.
prometheus text exporter for hdparm sleep state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # usage: hdparm -C /dev/sd[a-d] | ./sleepstate.py | |
| import sys | |
| hdparm_output = sys.stdin.read() | |
| lines = list(filter(lambda line: line, hdparm_output.splitlines())) | |
| drives = [lines[i : i + 2] for i in range(0, len(lines), 2)] | |
| states = list( | |
| map( | |
| lambda drive: ( | |
| drive[0].rstrip(":"), | |
| drive[1].lstrip().removeprefix("drive state is:").strip(), | |
| ), | |
| drives, | |
| ) | |
| ) | |
| for disk, state in states: | |
| is_sleeping = 1 if state == "standby" else 0 | |
| print(f'hdparm_sleep_state{{disk="{disk}"}} {is_sleeping}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment