1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | use strict; |
3 | | | use warnings; |
4 | | | use diagnostics; |
5 | | | |
6 | | | use lib "../../lib"; |
7 | | | use HotSaNICparser; |
8 | | | use HotSaNICdiagram; |
9 | | | use RRDs; |
10 | | | |
11 | | | # read global settings |
12 | | | # |
13 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
14 | | | my %CONFIG=HotSaNICparser::get_config("../.."); |
15 | | | |
16 | | | my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"}; |
17 | | | |
18 | | | my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME; |
19 | | | if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; } |
20 | | | my $TEMPNAME="$OUTDIR/temp.$IMGFMT"; |
21 | | | |
22 | | | my $FORCE=@ARGV; |
23 | | | my @ITEMS; |
24 | | | |
25 | | | # read module-specific settings |
26 | | | # |
27 | | | foreach (HotSaNICparser::read_settings(".")) { |
28 | | | my ($var,$value)=HotSaNICparser::parse_line($_); |
29 | | | if ($var eq "DRIVE") { |
30 | | | $value =~ s/SNMP://; |
31 | | | push @ITEMS,$value; |
32 | | | } |
33 | | | } |
34 | | | |
35 | | | my $LEGEND="bytes"; |
36 | | | |
37 | | | # generate diagrams |
38 | | | # |
39 | | | foreach (@ITEMS) { |
40 | | | my ($dev,$description)=split /,/; |
41 | | | |
42 | | | $dev =~ s/:.*:/:/; |
43 | | | (my $name = $dev) =~ s/(\/|:)/_/g; |
44 | | | |
45 | | | # if database exists, create images... |
46 | | | if ( -e "./rrd/$name.rrd") { |
47 | | | print "creating images for $dev ($description) ...\n"; |
48 | | | |
49 | | | foreach my $range ("1h","6h","1day","1week","1month","1year") { |
50 | | | my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
51 | | | |
52 | | | my $FILENAME="$OUTDIR/$name-$file.$IMGFMT"; |
53 | | | |
54 | | | my $make=$FORCE; |
55 | | | if ($range eq "1h") { $make++; } |
56 | | | elsif (! -e "$FILENAME") { $make++; } |
57 | | | else { |
58 | | | my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" ); |
59 | | | if (time > ($mtime+$build)) { $make++; } |
60 | | | } |
61 | | | |
62 | | | if ($make>0) { |
63 | | | |
64 | | | my ($prints,$xs,$ys); |
65 | | | |
66 | | | ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v", $LEGEND, |
67 | | | "-s","-$fullrange", "-w",$CONFIG{WIDTH}, "-h",$CONFIG{HEIGHT}, "-a", uc($IMGFMT), |
68 | | | "-l 0", "--alt-autoscale-max", "--title", "free space on $dev - last $descr ($DATESTRING)", |
69 | | | "DEF:max=rrd/$name.rrd:max:MAX", |
70 | | | "DEF:used=rrd/$name.rrd:used:AVERAGE", |
71 | | | "DEF:maxused=rrd/$name.rrd:used:MAX", |
72 | | | "DEF:minused=rrd/$name.rrd:used:MIN", |
73 | | | "CDEF:free=max,used,-", |
74 | | | "CDEF:minfree=max,maxused,-", |
75 | | | "CDEF:maxfree=max,minused,-", |
76 | | | "CDEF:minmax=maxused,minused,-", |
77 | | | "AREA:max#00d000:free", |
78 | | | "GPRINT:free:AVERAGE:(avg\\:%7.2lf %s$LEGEND", |
79 | | | "GPRINT:minfree:MIN:min\\:%7.2lf %s$LEGEND)", |
80 | | | "GPRINT:maxfree:MAX:max\\:%7.2lf %s$LEGEND)\\n", |
81 | | | "AREA:maxused#d0d000:", |
82 | | | "AREA:minused#d00000:used", |
83 | | | "GPRINT:used:AVERAGE:(avg\\:%7.2lf %s$LEGEND", |
84 | | | "GPRINT:minused:MIN:min\\:%7.2lf %s$LEGEND)", |
85 | | | "GPRINT:maxused:MAX:max\\:%7.2lf %s$LEGEND)\\n", |
86 | | | "HRULE:0#000000"; |
87 | | | |
88 | | | rename $TEMPNAME,$FILENAME; |
89 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
90 | | | |
91 | | | } |
92 | | | } |
93 | | | } |
94 | | | else { print " No database found\n Please check if the daemon is running.\n";next; } |
95 | | | print "\n"; |
96 | | | } |
97 | | | exit 0; |
98 | | | |