root / plugins / disk / btrfs_device_stats @ 7bf77a00
Historique | Voir | Annoter | Télécharger (5,13 ko)
| 1 | 7bf77a00 | HaseHarald | #!/usr/bin/python3 |
|---|---|---|---|
| 2 | # |
||
| 3 | # This file contains a munin-plugin to gather btrfs statistics per device. |
||
| 4 | # |
||
| 5 | # This is free software: you can redistribute it and/or modify |
||
| 6 | # it under the terms of the GNU Lesser General Public License as published by |
||
| 7 | # the Free Software Foundation, either version 3 of the License, or |
||
| 8 | # (at your option) any later version. |
||
| 9 | # |
||
| 10 | # This is distributed in the hope that it will be useful, |
||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | # GNU Lesser General Public License for more details. |
||
| 14 | # |
||
| 15 | # You should have received a copy of the GNU Lesser General Public License |
||
| 16 | # along with this plugin. If not, see <http://www.gnu.org/licenses/>. |
||
| 17 | |||
| 18 | |||
| 19 | import btrfs |
||
| 20 | import sys |
||
| 21 | |||
| 22 | |||
| 23 | def munin_config(fs): |
||
| 24 | fsid = str(fs.fsid).replace('-', '_')
|
||
| 25 | print("multigraph btrfs_device_stats_" + fsid)
|
||
| 26 | print("graph_args --base 1000 -l 0")
|
||
| 27 | print("graph_vlabel total btrfs attribute value")
|
||
| 28 | print("graph_title btrfs total device stats for " + fs.path)
|
||
| 29 | print("graph_category disk")
|
||
| 30 | print("graph_info This graph shows the total stats of devices used by btrfs")
|
||
| 31 | |||
| 32 | print("corruption_errs_total.label Corruption Errors")
|
||
| 33 | print("flush_errs_total.label Flush Errors")
|
||
| 34 | print("generation_errs_total.label Generation Errors")
|
||
| 35 | print("read_errs_total.label Read Errors")
|
||
| 36 | print("write_errs_total.label Write Errors")
|
||
| 37 | print("nr_items_total.label Nr. of Items")
|
||
| 38 | print("flags_total.label Nr. of Flags")
|
||
| 39 | |||
| 40 | print("")
|
||
| 41 | |||
| 42 | devices = fs.devices() |
||
| 43 | for this_device in devices: |
||
| 44 | this_dev_info = fs.dev_info(this_device.devid) |
||
| 45 | this_dev_name = this_dev_info.path.replace('/dev/', '')
|
||
| 46 | print("multigraph btrfs_device_stats_" + fsid + "." + str(this_device.devid))
|
||
| 47 | print("graph_args --base 1000 -l 0")
|
||
| 48 | print("graph_vlabel btrfs attribute value")
|
||
| 49 | print("graph_title btrfs device stats for " + this_dev_name)
|
||
| 50 | print("graph_category disk")
|
||
| 51 | print("graph_info This graph shows stats of devices used by btrfs")
|
||
| 52 | |||
| 53 | print("corruption_errs.label Corruption Errors")
|
||
| 54 | print("corruption_errs.warming 1")
|
||
| 55 | print("flush_errs.label Flush Errors")
|
||
| 56 | print("flush_errs.warming 1")
|
||
| 57 | print("generation_errs.label Generation Errors")
|
||
| 58 | print("generation_errs.warming 1")
|
||
| 59 | print("read_errs.label Read Errors")
|
||
| 60 | print("read_errs.warming 1")
|
||
| 61 | print("write_errs.label Write Errors")
|
||
| 62 | print("write_errs.warming 1")
|
||
| 63 | print("nr_items.label Nr. of Items")
|
||
| 64 | print("flags.label Nr. of Flags")
|
||
| 65 | print("flags.warming 1")
|
||
| 66 | |||
| 67 | print("")
|
||
| 68 | |||
| 69 | |||
| 70 | def munin_values(fs): |
||
| 71 | corruption_errs_total = 0 |
||
| 72 | flush_errs_total = 0 |
||
| 73 | generation_errs_total = 0 |
||
| 74 | read_errs_total = 0 |
||
| 75 | write_errs_total = 0 |
||
| 76 | nr_items_total = 0 |
||
| 77 | flags_total = 0 |
||
| 78 | |||
| 79 | fsid = str(fs.fsid).replace('-', '_')
|
||
| 80 | devices = fs.devices() |
||
| 81 | |||
| 82 | for this_device in devices: |
||
| 83 | this_dev_info = fs.dev_info(this_device.devid) |
||
| 84 | this_dev_name = this_dev_info.path.replace('/dev/', '')
|
||
| 85 | this_dev_stat = fs.dev_stats(this_device.devid, False) |
||
| 86 | |||
| 87 | corruption_errs = this_dev_stat.corruption_errs |
||
| 88 | flush_errs = this_dev_stat.flush_errs |
||
| 89 | generation_errs = this_dev_stat.generation_errs |
||
| 90 | read_errs = this_dev_stat.read_errs |
||
| 91 | write_errs = this_dev_stat.write_errs |
||
| 92 | nr_items = this_dev_stat.nr_items |
||
| 93 | flags = this_dev_stat.flags |
||
| 94 | |||
| 95 | corruption_errs_total = corruption_errs_total + corruption_errs |
||
| 96 | flush_errs_total = flush_errs_total + flush_errs |
||
| 97 | generation_errs_total = generation_errs_total + generation_errs |
||
| 98 | read_errs_total = read_errs_total + read_errs |
||
| 99 | write_errs_total = write_errs_total + write_errs |
||
| 100 | nr_items_total = nr_items_total + nr_items |
||
| 101 | flags_total = flags_total + flags |
||
| 102 | |||
| 103 | print("multigraph btrfs_device_stats_" + fsid + "." + str(this_device.devid))
|
||
| 104 | |||
| 105 | print("corruption_errs.value " + str(corruption_errs))
|
||
| 106 | print("flush_errs.value " + str(flush_errs))
|
||
| 107 | print("generation_errs.value " + str(generation_errs))
|
||
| 108 | print("read_errs.value " + str(read_errs))
|
||
| 109 | print("write_errs.value " + str(write_errs))
|
||
| 110 | print("nr_items.value " + str(nr_items))
|
||
| 111 | print("flags.value " + str(flags))
|
||
| 112 | |||
| 113 | print("")
|
||
| 114 | |||
| 115 | print("multigraph btrfs_device_stats_" + fsid)
|
||
| 116 | |||
| 117 | print("corruption_errs_total.value " + str(corruption_errs_total))
|
||
| 118 | print("flush_errs_total.value " + str(flush_errs_total))
|
||
| 119 | print("generation_errs_total.value " + str(generation_errs_total))
|
||
| 120 | print("read_errs_total.value " + str(read_errs_total))
|
||
| 121 | print("write_errs_total.value " + str(write_errs_total))
|
||
| 122 | print("nr_items_total.value " + str(nr_items_total))
|
||
| 123 | print("flags_total.value " + str(flags_total))
|
||
| 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) |
