[go: up one dir, main page]

Menu

[e3e510]: / disk / disk.pl  Maximize  Restore  History

Download this file

208 lines (178 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - disk.pl
#
# Webmin Sysstats Module
# Copyright (C) 2002 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###############################################################################
use strict;
use warnings;
no warnings 'redefine';
use RRDs;
use English '-no_match_vars';
use FindBin;
# to be used alone or from sysstat.pl without warning
# because require verify the path
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use lib "$FindBin::Bin/../..";
## no critic (RequireBarewordIncludes)
require 'sysstats-aquisition-lib.pl';
## use critic
}
my $module_name;
my $EMPTY = EMPTY();
# used for rrd names
#my %type_name = ( bloc => $EMPTY, inode => 'i', );
###############################################################################
# caches : use get_df from sysstats-gen-lib
# only 2 calls by run
my $bloc_cache = get_df();
my $inode_cache = get_df('-i');
###############################################################################
# ask the system info on file system
sub read_df($;$) {
my $vol = shift @_; # file system
my $opt = shift @_ || $EMPTY; # options : -i for inodes
my @res = ($opt) ? @{$inode_cache} : @{$bloc_cache};
# search for vol in cache
my $value;
foreach my $ligne (@res) {
my @tab = split_awk($ligne);
my $last_col = $#tab;
if ( $tab[$last_col] eq $vol ) {
$value = $ligne;
last;
}
}
if ( !$value ) {
warning("volume $vol not mounted");
return;
}
else {
return $value;
}
}
###############################################################################
# main
###############################################################################
my %config;
read_file_cached( 'config', \%config );
$module_name = $config{'name'};
debug( "run $module_name version " . $config{'version'} );
my %codes = action_load( \%config );
my $pre = $config{'pre'};
my $vol_num = 1;
while ( exists $config{ $pre . $vol_num } ) {
my @tab = split /,/, $config{ $pre . $vol_num };
my $real_vol_num = $tab[0];
my $vol = $tab[1];
my $runstop = $tab[3];
my $bloc_capa = 'U';
my $inode_capa = 'U';
# a call for each scanned fs to avoid unwanted time-out on nfs
if ( is_param_runstop($runstop) ) {
# blocs
#######
# on linux :
# Sys. de fich. 1024-blocks Used Available Capacity Monté sur
# /dev/sda8 9621848 1399180 7733892 16% /mnt/data
# on bsd
# Filesystem 1024-blocks Used Avail Capacity Mounted on
# /dev/ad3s1d 2008622 457044 1390890 25% /var
my $df = read_df($vol);
if ( defined $df ) {
my @liste = split_awk($df);
my $bloc_capac = $liste[4];
# check for % to check output format
if ( $bloc_capac =~ m/^(\d+)%/ ) {
$bloc_capa = $1;
# old obsolete code
# the filesystem reserve space for root (default 5%)
# total = used + avail + reserved
# so to match real capacity, we have to use
# used + reserved = total - avail
debug(
"$module_name $vol ($real_vol_num) blocs :capacity=$bloc_capa%"
);
action_param( $vol . '_b', $bloc_capa, \%codes );
}
else {
warning("bad output for blocs : $df");
}
}
else {
warning("$vol ($real_vol_num) blocs : no value from df");
}
# inodes
########
# on linux : 5 fields
# Sys. de fich. Inodes IUtil. ILib. %IUti. Monté sur
# /dev/sda10 1228800 225276 1003524 19% /
# on bsd : much more
# Filesystem 1024-blocks Used Avail Capacity iused ifree %iused Mounted on
# /dev/ad3s1d 2008622 457044 1390890 25% 20799 261823 7% /var
# on reiserfs
# /dev/md3 0 0 0 - /home
$df = read_df( $vol, '-i' );
if ( defined $df ) {
my @liste = split_awk($df);
my $last_col = $#liste;
my $inode_capac = $liste[ $last_col - 1 ];
if ( $inode_capac =~ m/^(\d+)%/ ) {
$inode_capa = $1;
debug(
"$module_name $vol ($real_vol_num) inodes : capacity=$inode_capa%"
);
action_param( $vol . '_i', $inode_capa, \%codes );
}
elsif ( $inode_capac eq DASH() ) {
debug("no inodes value on $df");
}
else {
warning("bad output for inodes : $df");
}
}
else {
debug(
"$module_name $vol ($real_vol_num) inodes : no value from df");
}
}
else {
debug("aquisition for $vol stopped");
}
# the format of stored data was changed with 0.24 release
# to avoid several rrd file for one parameter : 1.rrd i1.rrd
# to be able to graph 'old' data, we keep the 2 database for
# at least a year
# and the graph sub use the following algo
# if bloc <= 100
# then new data
# else old data
my $rrdbase = $real_vol_num . '.rrd';
RRDs::update( $rrdbase, "N:$bloc_capa:$inode_capa" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase database : $ERR") if $ERR;
# old inodes rrd contains the same data for compatibility with old schema
# may be suppress in 2012, one year after webminstat 2.0
# $rrdbase = $type_name{'inode'} . $real_vol_num . '.rrd';
# if ( -f $rrdbase ) {
#
# RRDs::update( $rrdbase, "N:$bloc_capa:$inode_capa" );
# $ERR = RRDs::error();
# warning("ERROR while updating $rrdbase database : $ERR") if $ERR;
# }
$vol_num++;
}