#!/usr/bin/perl -w use constant TREND_DOWN => 0; use constant TREND_DOWN_WEAK => 1; use constant TREND_FLAT => 2; use constant TREND_UP_WEAK => 3; use constant TREND_UP => 4; use constant PDP_STEP => 300; # 86400 seconds per day, 365 days a year, 300 second PDP step value my $data_steps = 86400 * 365 / PDP_STEP; my %stats = ( 'temp' => 100, 'load' => 0.05, 'fan' => 2000, 'disk' => 1000000000, 'disk2' => 1000000000, 'w_bytes' => 0, 'r_bytes' => 0 ); # Jan 1, 2009 00:00:00 PST my $timestamp = 1230796800; my $create_cmd = "rrdtool create sysinfo.rrd --start $timestamp --step 300 \\ DS:load:GAUGE:600:0:U \\ DS:temperature:GAUGE:600:0:500 \\ DS:cpu_fan:GAUGE:600:0:U \\ DS:disk_used:GAUGE:600:0:U \\ DS:disk_change:DERIVE:600:U:U \\ DS:disk2_used:GAUGE:600:0:U \\ DS:disk2_change:DERIVE:600:U:U \\ DS:bytes_written:COUNTER:600:0:U \\ DS:bytes_read:COUNTER:600:0:U \\ RRA:AVERAGE:0.5:1:8928 \\ RRA:MIN:0.5:1:8928 \\ RRA:MAX:0.5:1:8928 \\ RRA:AVERAGE:0.5:3:8640 \\ RRA:AVERAGE:0.5:12:8760"; print STDOUT "$create_cmd\n"; `$create_cmd`; for (my $i=0; $i<$data_steps; $i++) { # increment the timestamp $timestamp += PDP_STEP; # determine the general trend my $trend = int(rand(TREND_UP + 1)); # depending on the trend, adjust the stats appropriately if ($trend == TREND_DOWN) { $stats{'temp'} -= int(rand(5)) if $stats{'temp'} >= 70; $stats{'load'} -= int(rand(400)) / 100; $stats{'fan'} -= int(rand(100)) if $stats{'fan'} >= 1500; $stats{'disk'} -= int(rand(10000000)); $stats{'disk2'} -= int(rand(10000000)); $stats{'w_bytes'} += int(rand(1000000)); $stats{'r_bytes'} += int(rand(3000000)); $stats{'load'} = 0.01 if $stats{'load'} <= 0.00; $stats{'disk'} = 0 if $stats{'disk'} <= 0; $stats{'disk2'} = 0 if $stats{'disk2'} <= 0; } elsif ($trend == TREND_DOWN_WEAK) { $stats{'temp'} -= int(rand(2)) if $stats{'temp'} >= 70; $stats{'load'} -= int(rand(100)) / 100; $stats{'fan'} -= int(rand(25)) if $stats{'fan'} >= 1500; $stats{'disk'} -= int(rand(1000000)); $stats{'w_bytes'} += int(rand(2000000)); $stats{'r_bytes'} += int(rand(6000000)); $stats{'load'} = 0.01 if $stats{'load'} <= 0.00; $stats{'disk'} = 0 if $stats{'disk'} <= 0; $stats{'disk2'} = 0 if $stats{'disk2'} <= 0; } elsif ($trend == TREND_UP_WEAK) { $stats{'temp'} += int(rand(2)) if $stats{'temp'} <= 200; $stats{'load'} += int(rand(100)) / 100 if $stats{'load'} <= 100; $stats{'fan'} += int(rand(25)) if $stats{'fan'} <= 3500; $stats{'disk'} += int(rand(1000000)); $stats{'disk2'} += int(rand(1000000)); $stats{'w_bytes'} += int(rand(3000000)); $stats{'r_bytes'} += int(rand(9000000)); } elsif ($trend == TREND_UP) { $stats{'temp'} += int(rand(5)) if $stats{'temp'} <= 200; $stats{'load'} += int(rand(300)) / 100 if $stats{'load'} <= 100; $stats{'fan'} += int(rand(100)) if $stats{'fan'} <= 3500; $stats{'disk'} += int(rand(10000000)); $stats{'disk2'} += int(rand(10000000)); $stats{'w_bytes'} += int(rand(4000000)); $stats{'r_bytes'} += int(rand(12000000)); } # update the RRD with the new data `rrdtool update sysinfo.rrd $timestamp:$stats{load}:$stats{temp}:$stats{fan}:$stats{disk}:$stats{disk}:$stats{disk2}:$stats{disk2}:$stats{w_bytes}:$stats{r_bytes}`; }