root / plugins / disk / btrfs_device_usage @ 09b88141
Historique | Voir | Annoter | Télécharger (3,79 ko)
| 1 |
#!/usr/bin/env python3 |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
""" |
| 5 |
=pod |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
btrfs_device_usage - Script to monitor usage of btrfs devices |
| 10 |
|
| 11 |
=head1 CONFIGURATION |
| 12 |
|
| 13 |
Simply create a symlink in your plugins directory like with any other plugin. |
| 14 |
Must be run as root. |
| 15 |
|
| 16 |
[btrfs_device_usage] |
| 17 |
user root |
| 18 |
|
| 19 |
=head2 DEFAULT CONFIGURATION |
| 20 |
|
| 21 |
=head1 BUGS |
| 22 |
|
| 23 |
=head1 AUTHOR |
| 24 |
|
| 25 |
2019, HaseHarald |
| 26 |
|
| 27 |
=head1 MAGIC MARKERS |
| 28 |
|
| 29 |
#%# family=auto |
| 30 |
#%# capabilities=autoconf |
| 31 |
|
| 32 |
=head1 LICENSE |
| 33 |
|
| 34 |
LGPLv3 |
| 35 |
|
| 36 |
=cut |
| 37 |
""" |
| 38 |
|
| 39 |
|
| 40 |
# This file contains a munin-plugin to gather btrfs statistics per device. |
| 41 |
# |
| 42 |
# This is free software: you can redistribute it and/or modify |
| 43 |
# it under the terms of the GNU Lesser General Public License as published by |
| 44 |
# the Free Software Foundation, either version 3 of the License, or |
| 45 |
# (at your option) any later version. |
| 46 |
# |
| 47 |
# This is distributed in the hope that it will be useful, |
| 48 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 49 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 50 |
# GNU Lesser General Public License for more details. |
| 51 |
# |
| 52 |
# You should have received a copy of the GNU Lesser General Public License |
| 53 |
# along with this plugin. If not, see <http://www.gnu.org/licenses/>. |
| 54 |
|
| 55 |
|
| 56 |
import btrfs |
| 57 |
import sys |
| 58 |
|
| 59 |
|
| 60 |
def munin_config(fs): |
| 61 |
fsid = str(fs.fsid).replace('-', '_')
|
| 62 |
|
| 63 |
print("multigraph btrfs_device_usage_byte_" + fsid)
|
| 64 |
print("graph_title btrfs usage by device in bytes on " + fs.path)
|
| 65 |
print("graph_args --base 1024 -l 0")
|
| 66 |
print("graph_scale yes")
|
| 67 |
print("graph_vlabel bytes")
|
| 68 |
print("graph_category disk")
|
| 69 |
print("graph_info This graph shows bytes used by btrfs on every device")
|
| 70 |
|
| 71 |
devices = fs.devices() |
| 72 |
for this_device in devices: |
| 73 |
this_dev_info = fs.dev_info(this_device.devid) |
| 74 |
this_dev_name = this_dev_info.path.replace('/dev/', '')
|
| 75 |
print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
|
| 76 |
".label " + this_dev_name) |
| 77 |
|
| 78 |
print("")
|
| 79 |
|
| 80 |
print("multigraph btrfs_device_usage_percent_" + fsid)
|
| 81 |
print("graph_title btrfs usage by device in percent on " + fs.path)
|
| 82 |
print("graph_args --base 1000 -l 0")
|
| 83 |
print("graph_scale no")
|
| 84 |
print("graph_vlabel %")
|
| 85 |
print("graph_category disk")
|
| 86 |
print("graph_info This graph shows percentage used by btrfs on every \
|
| 87 |
device. Maesured in percentage of device capacity.") |
| 88 |
|
| 89 |
devices = fs.devices() |
| 90 |
for this_device in devices: |
| 91 |
this_dev_info = fs.dev_info(this_device.devid) |
| 92 |
this_dev_name = this_dev_info.path.replace('/dev/', '')
|
| 93 |
print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
|
| 94 |
".label " + this_dev_name) |
| 95 |
print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".warning 95")
|
| 96 |
print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".critical 98")
|
| 97 |
|
| 98 |
print("")
|
| 99 |
|
| 100 |
|
| 101 |
def munin_values(fs): |
| 102 |
fsid = str(fs.fsid).replace('-', '_')
|
| 103 |
devices = fs.devices() |
| 104 |
|
| 105 |
print("multigraph btrfs_device_usage_byte_" + fsid)
|
| 106 |
|
| 107 |
for this_device in devices: |
| 108 |
this_dev_info = fs.dev_info(this_device.devid) |
| 109 |
print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
|
| 110 |
".value " + str(this_dev_info.bytes_used)) |
| 111 |
|
| 112 |
print("")
|
| 113 |
|
| 114 |
# Reset device iterator |
| 115 |
devices = fs.devices() |
| 116 |
|
| 117 |
print("multigraph btrfs_device_usage_percent_" + fsid)
|
| 118 |
|
| 119 |
for this_device in devices: |
| 120 |
this_dev_info = fs.dev_info(this_device.devid) |
| 121 |
usage = 100.0 * this_dev_info.bytes_used / this_dev_info.total_bytes |
| 122 |
print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
|
| 123 |
".value " + str(round(usage, 2))) |
| 124 |
|
| 125 |
print("")
|
| 126 |
|
| 127 |
|
| 128 |
def main(): |
| 129 |
for path in btrfs.utils.mounted_filesystem_paths(): |
| 130 |
with btrfs.FileSystem(path) as fs: |
| 131 |
if len(sys.argv) > 1 and sys.argv[1] == "config": |
| 132 |
munin_config(fs) |
| 133 |
else: |
| 134 |
munin_values(fs) |
| 135 |
|
| 136 |
|
| 137 |
if __name__ == "__main__": |
| 138 |
main() |
| 139 |
|
| 140 |
exit(0) |
