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