forked from Sysdeploy/collectd-btrfs
Cleanup
- simplify - variable syntax
This commit is contained in:
parent
a4461af76f
commit
1f53f2c3f8
|
@ -1,30 +1,27 @@
|
||||||
import collectd
|
import re
|
||||||
|
|
||||||
import btrfs
|
import btrfs
|
||||||
|
import collectd
|
||||||
|
|
||||||
PLUGIN = 'btrfs'
|
PLUGIN = 'btrfs'
|
||||||
TYPE_STATS = "stats"
|
TYPE_STATS = "device_stats"
|
||||||
|
|
||||||
mount_paths = []
|
|
||||||
|
|
||||||
def configure_callback(conf):
|
|
||||||
"""
|
|
||||||
Populate mount_paths
|
|
||||||
"""
|
|
||||||
global mount_paths
|
|
||||||
mount_paths = [path for path in btrfs.utils.mounted_filesystem_paths()]
|
|
||||||
collectd.info("btrfs: config done. mount_paths: {}".format(mount_paths))
|
|
||||||
|
|
||||||
def read_callback():
|
def read_callback():
|
||||||
"""Read Btrfs device information and dispatch values to collectd."""
|
"""Read Btrfs device information and dispatch values to collectd."""
|
||||||
metric = collectd.Values()
|
metric = collectd.Values()
|
||||||
metric.plugin = PLUGIN
|
metric.plugin = PLUGIN
|
||||||
|
mount_paths = btrfs.utils.mounted_filesystem_paths()
|
||||||
for path in mount_paths:
|
for path in mount_paths:
|
||||||
try:
|
try:
|
||||||
with btrfs.FileSystem(path) as fs:
|
with btrfs.FileSystem(path) as fs:
|
||||||
for device in list(fs.devices()):
|
for device in list(fs.devices()):
|
||||||
stats = fs.dev_stats(device.devid)
|
stats = fs.dev_stats(device.devid)
|
||||||
dev_info = fs.dev_info(device.devid)
|
dev_info = fs.dev_info(device.devid)
|
||||||
metric.plugin_instance = dev_info.path
|
metric.plugin_instance = re.sub(
|
||||||
|
r'[^a-zA-Z0-9]',
|
||||||
|
r'-',
|
||||||
|
dev_info.path)[1:]
|
||||||
for counter, value in stats.counters.items():
|
for counter, value in stats.counters.items():
|
||||||
metric.type_instance = counter
|
metric.type_instance = counter
|
||||||
metric.dispatch(TYPE_STATS, [value])
|
metric.dispatch(TYPE_STATS, [value])
|
||||||
|
@ -34,5 +31,4 @@ def read_callback():
|
||||||
|
|
||||||
if __name__ != "__main__":
|
if __name__ != "__main__":
|
||||||
# Register callbacks
|
# Register callbacks
|
||||||
collectd.register_config(configure_callback)
|
|
||||||
collectd.register_read(read_callback)
|
collectd.register_read(read_callback)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user