| 133 | | for ( @$values ) { |
|---|
| 134 | | $ds{$_->[0]} = $_->[2] || 0; |
|---|
| 135 | | } |
|---|
| 136 | | |
|---|
| 137 | | debug(4, "INSERT RRDs::update ". join ' ', %ds); |
|---|
| 138 | | $rrd->update($Config{rrddir}.'/'.$file, $time, %ds); |
|---|
| 139 | | debug(2, "INSERT RRDs::update ERR " . RRDs::error) if RRDs::error; |
|---|
| | 128 | debug(4, "INSERT RRDs::update ". join ' ', %$values); |
|---|
| | 129 | #Â Need to eval because RRD::Simple will croak on error |
|---|
| | 130 | eval { $rrd->update($file, $time, %$values) }; |
|---|
| | 131 | # This is not required because the $rrd->update will check for errors and die, which is caught |
|---|
| | 132 | #debug(2, "INSERT RRDs::update ERR1 " . RRDs::error) if RRDs::error; |
|---|
| 158 | | my $label = $a->rrdlabel; |
|---|
| 159 | | push @graphs, [ $label, "GAUGE", $a->value ]; |
|---|
| 160 | | my $shorter_label = substr($label, 0, 14); |
|---|
| 161 | | push @graphs, [ $shorter_label."_warn", "GAUGE", $a->threshold->warning->end ] if ($a->threshold->warning->is_set); |
|---|
| 162 | | push @graphs, [ $shorter_label."_crit", "GAUGE", $a->threshold->critical->end ] if ($a->threshold->critical->is_set); |
|---|
| | 154 | push @metrics, { metric => $a->clean_label, dstype => "GAUGE", value => $a->value, threshold => $a->threshold }; |
|---|
| 202 | | my $S = parseperfdata(%P); |
|---|
| 203 | | for my $s ( @$S ) { |
|---|
| 204 | | my $rrd = createrrd($P{hostname}, $P{servicedescr}, $P{lastcheck}-1, $s); |
|---|
| 205 | | rrdupdate($rrd, $P{lastcheck}, $s); |
|---|
| | 193 | my $result = parseperfdata(%P); |
|---|
| | 194 | |
|---|
| | 195 | next unless @{$result->{list}}; |
|---|
| | 196 | |
|---|
| | 197 | # If old file exists, update the old fashioned way - this can be dropped in Opsview 4 |
|---|
| | 198 | my $old_filename = urlencode($P{hostname}."_".$P{servicedescr}."_".$result->{dbname}) . '.rrd'; |
|---|
| | 199 | if ( -e "$Config{rrddir}/$old_filename" ) { |
|---|
| | 200 | my $ds = {}; |
|---|
| | 201 | for ( @{$result->{list}} ) { |
|---|
| | 202 | #$ds->{$_->[0]} = $_->[2] || 0; |
|---|
| | 203 | $ds->{$_->{metric}} = $_->{value}; |
|---|
| | 204 | } |
|---|
| | 205 | rrdupdate("$Config{rrddir}/$old_filename", $P{lastcheck}, $ds); |
|---|
| | 206 | } else { |
|---|
| | 207 | for my $s ( @{$result->{list}} ) { |
|---|
| | 208 | my $rrddir = join("/", $Config{rrddir}, urlencode($P{hostname}), urlencode($P{servicedescr}), urlencode($s->{metric})); |
|---|
| | 209 | my $values_filename = "$rrddir/value.rrd"; |
|---|
| | 210 | if (! -e $values_filename) { |
|---|
| | 211 | make_rrd_dir( $Config{rrddir}, urlencode($P{hostname}), urlencode($P{servicedescr}), urlencode($s->{metric}) ); |
|---|
| | 212 | my @ds = ($values_filename, "--start", $P{lastcheck}-1); |
|---|
| | 213 | my $u = $s->{dstype} eq 'DERIVE' ? '0' : 'U' ; |
|---|
| | 214 | push @ds, |
|---|
| | 215 | "DS:value:".$s->{dstype}.":$Config{heartbeat}:$u:U", |
|---|
| | 216 | "RRA:AVERAGE:0.5:1:600", |
|---|
| | 217 | "RRA:AVERAGE:0.5:6:700", |
|---|
| | 218 | "RRA:AVERAGE:0.5:24:775", |
|---|
| | 219 | "RRA:AVERAGE:0.5:288:797"; |
|---|
| | 220 | debug(4, "INSERT RRDs::create @ds"); |
|---|
| | 221 | RRDs::create(@ds); |
|---|
| | 222 | debug(2, "INSERT RRDs::create ERR " . RRDs::error) if RRDs::error; |
|---|
| | 223 | } |
|---|
| | 224 | # Update values.rrd |
|---|
| | 225 | my @ds = ($values_filename, "$P{lastcheck}:".$s->{value}); |
|---|
| | 226 | debug(4, "INSERT RRDs::update @ds"); |
|---|
| | 227 | RRDs::update(@ds); |
|---|
| | 228 | debug(2, "INSERT RRDs::update ERR " . RRDs::error) if RRDs::error; |
|---|
| | 229 | |
|---|
| | 230 | my %data; |
|---|
| | 231 | if ($s->{threshold}) { |
|---|
| | 232 | if ($s->{threshold}->warning->is_set) { |
|---|
| | 233 | $data{warning_end} = $s->{threshold}->warning->end; |
|---|
| | 234 | } |
|---|
| | 235 | if ($s->{threshold}->critical->is_set) { |
|---|
| | 236 | $data{critical_end} = $s->{threshold}->critical->end; |
|---|
| | 237 | } |
|---|
| | 238 | } |
|---|
| | 239 | if (%data) { |
|---|
| | 240 | # We need to create the rrd. If RRD::Simple does it, will choose large retention periods |
|---|
| | 241 | my $thresholds_rrd = "$rrddir/thresholds.rrd"; |
|---|
| | 242 | if (! -e $thresholds_rrd) { |
|---|
| | 243 | # We duplicate this section. In future, we may have different parameters for threshold storage |
|---|
| | 244 | my @ds = ($thresholds_rrd, "--start", $P{lastcheck}-1); |
|---|
| | 245 | my $u = $s->{dstype} eq 'DERIVE' ? '0' : 'U' ; |
|---|
| | 246 | push @ds, |
|---|
| | 247 | "DS:warning_end:".$s->{dstype}.":$Config{heartbeat}:$u:U", |
|---|
| | 248 | "DS:critical_end:".$s->{dstype}.":$Config{heartbeat}:$u:U", |
|---|
| | 249 | "RRA:AVERAGE:0.5:1:600", |
|---|
| | 250 | "RRA:AVERAGE:0.5:6:700", |
|---|
| | 251 | "RRA:AVERAGE:0.5:24:775", |
|---|
| | 252 | "RRA:AVERAGE:0.5:288:797"; |
|---|
| | 253 | debug(4, "INSERT RRDs::create::thresholds @ds"); |
|---|
| | 254 | RRDs::create(@ds); |
|---|
| | 255 | debug(2, "INSERT RRDs::create::thresholds ERR " . RRDs::error) if RRDs::error; |
|---|
| | 256 | } |
|---|
| | 257 | # Update thresholds.rrd - use RRD::Simple because may extend in future with other threshold information |
|---|
| | 258 | rrdupdate( $thresholds_rrd, $P{lastcheck}, \%data ); |
|---|
| | 259 | } |
|---|
| | 260 | } |
|---|