Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / btrfs_device_stats @ 09b88141

Historique | Voir | Annoter | Télécharger (5,35 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
Must be run as root.
15

    
16
 [btrfs_device_stats]
17
 user root
18

    
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
 #%# capabilities=autoconf
31

    
32
=head1 LICENSE
33

    
34
LGPLv3
35

    
36
=cut
37
"""
38

    
39

    
40
# 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

    
69
    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

    
77
    print("")
78

    
79
    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

    
90
        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

    
104
        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

    
116
    fsid = str(fs.fsid).replace('-', '_')
117
    devices = fs.devices()
118

    
119
    for this_device in devices:
120
        this_dev_stat = fs.dev_stats(this_device.devid, False)
121

    
122
        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

    
130
        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

    
138
        print("multigraph btrfs_device_stats_" + fsid + "." + str(this_device.devid))
139

    
140
        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

    
148
        print("")
149

    
150
    print("multigraph btrfs_device_stats_" + fsid)
151

    
152
    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

    
160
    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)