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