root / plugins / disk / btrfs_device_stats @ 6c7ad652
Historique | Voir | Annoter | Télécharger (5,35 ko)
| 1 | bffbc23a | HaseHarald | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 6f0e91f8 | HaseHarald | |
| 3 | |||
| 4 | """ |
||
| 5 | =pod |
||
| 6 | |||
| 7 | =head1 NAME |
||
| 8 | |||
| 9 | btrfs_device_stats - Script to monitor btrfs device statistics |
||
| 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_stats] |
| 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 | 7bf77a00 | 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 | |||
| 60 | def munin_config(fs): |
||
| 61 | fsid = str(fs.fsid).replace('-', '_')
|
||
| 62 | print("multigraph btrfs_device_stats_" + fsid)
|
||
| 63 | print("graph_args --base 1000 -l 0")
|
||
| 64 | print("graph_vlabel total btrfs attribute value")
|
||
| 65 | print("graph_title btrfs total device stats for " + fs.path)
|
||
| 66 | print("graph_category disk")
|
||
| 67 | print("graph_info This graph shows the total stats of devices used by btrfs")
|
||
| 68 | bffbc23a | HaseHarald | |
| 69 | 7bf77a00 | HaseHarald | print("corruption_errs_total.label Corruption Errors")
|
| 70 | print("flush_errs_total.label Flush Errors")
|
||
| 71 | print("generation_errs_total.label Generation Errors")
|
||
| 72 | print("read_errs_total.label Read Errors")
|
||
| 73 | print("write_errs_total.label Write Errors")
|
||
| 74 | print("nr_items_total.label Nr. of Items")
|
||
| 75 | print("flags_total.label Nr. of Flags")
|
||
| 76 | bffbc23a | HaseHarald | |
| 77 | 7bf77a00 | HaseHarald | print("")
|
| 78 | bffbc23a | HaseHarald | |
| 79 | 7bf77a00 | HaseHarald | devices = fs.devices() |
| 80 | for this_device in devices: |
||
| 81 | this_dev_info = fs.dev_info(this_device.devid) |
||
| 82 | this_dev_name = this_dev_info.path.replace('/dev/', '')
|
||
| 83 | print("multigraph btrfs_device_stats_" + fsid + "." + str(this_device.devid))
|
||
| 84 | print("graph_args --base 1000 -l 0")
|
||
| 85 | print("graph_vlabel btrfs attribute value")
|
||
| 86 | print("graph_title btrfs device stats for " + this_dev_name)
|
||
| 87 | print("graph_category disk")
|
||
| 88 | print("graph_info This graph shows stats of devices used by btrfs")
|
||
| 89 | bffbc23a | HaseHarald | |
| 90 | 7bf77a00 | HaseHarald | print("corruption_errs.label Corruption Errors")
|
| 91 | print("corruption_errs.warming 1")
|
||
| 92 | print("flush_errs.label Flush Errors")
|
||
| 93 | print("flush_errs.warming 1")
|
||
| 94 | print("generation_errs.label Generation Errors")
|
||
| 95 | print("generation_errs.warming 1")
|
||
| 96 | print("read_errs.label Read Errors")
|
||
| 97 | print("read_errs.warming 1")
|
||
| 98 | print("write_errs.label Write Errors")
|
||
| 99 | print("write_errs.warming 1")
|
||
| 100 | print("nr_items.label Nr. of Items")
|
||
| 101 | print("flags.label Nr. of Flags")
|
||
| 102 | print("flags.warming 1")
|
||
| 103 | bffbc23a | HaseHarald | |
| 104 | 7bf77a00 | HaseHarald | print("")
|
| 105 | |||
| 106 | |||
| 107 | def munin_values(fs): |
||
| 108 | corruption_errs_total = 0 |
||
| 109 | flush_errs_total = 0 |
||
| 110 | generation_errs_total = 0 |
||
| 111 | read_errs_total = 0 |
||
| 112 | write_errs_total = 0 |
||
| 113 | nr_items_total = 0 |
||
| 114 | flags_total = 0 |
||
| 115 | bffbc23a | HaseHarald | |
| 116 | 7bf77a00 | HaseHarald | fsid = str(fs.fsid).replace('-', '_')
|
| 117 | devices = fs.devices() |
||
| 118 | bffbc23a | HaseHarald | |
| 119 | 7bf77a00 | HaseHarald | for this_device in devices: |
| 120 | this_dev_stat = fs.dev_stats(this_device.devid, False) |
||
| 121 | bffbc23a | HaseHarald | |
| 122 | 7bf77a00 | HaseHarald | corruption_errs = this_dev_stat.corruption_errs |
| 123 | flush_errs = this_dev_stat.flush_errs |
||
| 124 | generation_errs = this_dev_stat.generation_errs |
||
| 125 | read_errs = this_dev_stat.read_errs |
||
| 126 | write_errs = this_dev_stat.write_errs |
||
| 127 | nr_items = this_dev_stat.nr_items |
||
| 128 | flags = this_dev_stat.flags |
||
| 129 | bffbc23a | HaseHarald | |
| 130 | 7bf77a00 | HaseHarald | corruption_errs_total = corruption_errs_total + corruption_errs |
| 131 | flush_errs_total = flush_errs_total + flush_errs |
||
| 132 | generation_errs_total = generation_errs_total + generation_errs |
||
| 133 | read_errs_total = read_errs_total + read_errs |
||
| 134 | write_errs_total = write_errs_total + write_errs |
||
| 135 | nr_items_total = nr_items_total + nr_items |
||
| 136 | flags_total = flags_total + flags |
||
| 137 | bffbc23a | HaseHarald | |
| 138 | 7bf77a00 | HaseHarald | print("multigraph btrfs_device_stats_" + fsid + "." + str(this_device.devid))
|
| 139 | bffbc23a | HaseHarald | |
| 140 | 7bf77a00 | HaseHarald | print("corruption_errs.value " + str(corruption_errs))
|
| 141 | print("flush_errs.value " + str(flush_errs))
|
||
| 142 | print("generation_errs.value " + str(generation_errs))
|
||
| 143 | print("read_errs.value " + str(read_errs))
|
||
| 144 | print("write_errs.value " + str(write_errs))
|
||
| 145 | print("nr_items.value " + str(nr_items))
|
||
| 146 | print("flags.value " + str(flags))
|
||
| 147 | bffbc23a | HaseHarald | |
| 148 | 7bf77a00 | HaseHarald | print("")
|
| 149 | bffbc23a | HaseHarald | |
| 150 | 7bf77a00 | HaseHarald | print("multigraph btrfs_device_stats_" + fsid)
|
| 151 | bffbc23a | HaseHarald | |
| 152 | 7bf77a00 | HaseHarald | print("corruption_errs_total.value " + str(corruption_errs_total))
|
| 153 | print("flush_errs_total.value " + str(flush_errs_total))
|
||
| 154 | print("generation_errs_total.value " + str(generation_errs_total))
|
||
| 155 | print("read_errs_total.value " + str(read_errs_total))
|
||
| 156 | print("write_errs_total.value " + str(write_errs_total))
|
||
| 157 | print("nr_items_total.value " + str(nr_items_total))
|
||
| 158 | print("flags_total.value " + str(flags_total))
|
||
| 159 | bffbc23a | HaseHarald | |
| 160 | 7bf77a00 | HaseHarald | print("")
|
| 161 | |||
| 162 | |||
| 163 | def main(): |
||
| 164 | for path in btrfs.utils.mounted_filesystem_paths(): |
||
| 165 | with btrfs.FileSystem(path) as fs: |
||
| 166 | if len(sys.argv) > 1 and sys.argv[1] == "config": |
||
| 167 | munin_config(fs) |
||
| 168 | else: |
||
| 169 | munin_values(fs) |
||
| 170 | |||
| 171 | |||
| 172 | if __name__ == "__main__": |
||
| 173 | main() |
||
| 174 | |||
| 175 | exit(0) |
