Projet

Général

Profil

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

root / plugins / disk / btrfs_device_usage @ 6f0e91f8

Historique | Voir | Annoter | Télécharger (3,76 ko)

1
#!/usr/bin/env python3
2

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

    
60
    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

    
68
    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
        print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
73
              ".label " + this_dev_name)
74

    
75
    print("")
76

    
77
    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
    print("graph_info This graph shows percentage used by btrfs on every \
84
          device. Maesured in percentage of device capacity.")
85

    
86
    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
        print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
91
              ".label " + this_dev_name)
92
        print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".warning 95")
93
        print("btrfs_percent_" + fsid + "_" + str(this_device.devid) + ".critical 98")
94

    
95
    print("")
96

    
97

    
98
def munin_values(fs):
99
    fsid = str(fs.fsid).replace('-', '_')
100
    devices = fs.devices()
101

    
102
    print("multigraph btrfs_device_usage_byte_" + fsid)
103

    
104
    for this_device in devices:
105
        this_dev_info = fs.dev_info(this_device.devid)
106
        print("btrfs_bytes_" + fsid + "_" + str(this_device.devid) +
107
              ".value " + str(this_dev_info.bytes_used))
108

    
109
    print("")
110

    
111
    # Reset device iterator
112
    devices = fs.devices()
113

    
114
    print("multigraph btrfs_device_usage_percent_" + fsid)
115

    
116
    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
        print("btrfs_percent_" + fsid + "_" + str(this_device.devid) +
120
              ".value " + str(round(usage, 2)))
121

    
122
    print("")
123

    
124

    
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)