root / plugins / disk / btrfs_device_usage @ 09b88141
Historique | Voir | Annoter | Télécharger (3,79 ko)
| 1 | bffbc23a | HaseHarald | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 6f0e91f8 | HaseHarald | |
| 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 | 3f92394b | HaseHarald | Must be run as root. |
| 15 | |||
| 16 | 09b88141 | Lars Kruse | [btrfs_device_usage] |
| 17 | user root |
||
| 18 | 6f0e91f8 | HaseHarald | |
| 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 | 3f92394b | HaseHarald | #%# capabilities=autoconf |
| 31 | 6f0e91f8 | HaseHarald | |
| 32 | =head1 LICENSE |
||
| 33 | |||
| 34 | LGPLv3 |
||
| 35 | |||
| 36 | =cut |
||
| 37 | """ |
||
| 38 | |||
| 39 | |||
| 40 | 10f2d97f | HaseHarald | # 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 | 7d220d0a | HaseHarald | |
| 60 | 10f2d97f | HaseHarald | def munin_config(fs): |
| 61 | fsid = str(fs.fsid).replace('-', '_')
|
||
| 62 | bffbc23a | HaseHarald | |
| 63 | 10f2d97f | HaseHarald | 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 | bffbc23a | HaseHarald | |
| 71 | 10f2d97f | HaseHarald | 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 | 675dedf1 | HaseHarald | print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
|
| 76 | bffbc23a | HaseHarald | ".label " + this_dev_name) |
| 77 | |||
| 78 | 10f2d97f | HaseHarald | print("")
|
| 79 | bffbc23a | HaseHarald | |
| 80 | 10f2d97f | HaseHarald | 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 | 7d220d0a | HaseHarald | print("graph_info This graph shows percentage used by btrfs on every \
|
| 87 | bffbc23a | HaseHarald | device. Maesured in percentage of device capacity.") |
| 88 | |||
| 89 | 10f2d97f | HaseHarald | 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 | 675dedf1 | HaseHarald | print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
|
| 94 | bffbc23a | HaseHarald | ".label " + this_dev_name) |
| 95 | 7d220d0a | HaseHarald | print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".warning 95")
|
| 96 | print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".critical 98")
|
||
| 97 | bffbc23a | HaseHarald | |
| 98 | 10f2d97f | HaseHarald | print("")
|
| 99 | |||
| 100 | 7d220d0a | HaseHarald | |
| 101 | 10f2d97f | HaseHarald | def munin_values(fs): |
| 102 | fsid = str(fs.fsid).replace('-', '_')
|
||
| 103 | devices = fs.devices() |
||
| 104 | bffbc23a | HaseHarald | |
| 105 | 10f2d97f | HaseHarald | print("multigraph btrfs_device_usage_byte_" + fsid)
|
| 106 | bffbc23a | HaseHarald | |
| 107 | 10f2d97f | HaseHarald | for this_device in devices: |
| 108 | this_dev_info = fs.dev_info(this_device.devid) |
||
| 109 | 675dedf1 | HaseHarald | print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
|
| 110 | bffbc23a | HaseHarald | ".value " + str(this_dev_info.bytes_used)) |
| 111 | |||
| 112 | 10f2d97f | HaseHarald | print("")
|
| 113 | bffbc23a | HaseHarald | |
| 114 | 10f2d97f | HaseHarald | # Reset device iterator |
| 115 | devices = fs.devices() |
||
| 116 | bffbc23a | HaseHarald | |
| 117 | 10f2d97f | HaseHarald | print("multigraph btrfs_device_usage_percent_" + fsid)
|
| 118 | bffbc23a | HaseHarald | |
| 119 | 10f2d97f | HaseHarald | 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 | 675dedf1 | HaseHarald | print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
|
| 123 | bffbc23a | HaseHarald | ".value " + str(round(usage, 2))) |
| 124 | |||
| 125 | 10f2d97f | HaseHarald | print("")
|
| 126 | bffbc23a | HaseHarald | |
| 127 | 10f2d97f | HaseHarald | |
| 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) |
