mk-plots.in 3.89 KB
Newer Older
1
#!/usr/bin/perl
2
#
Leigh B Stoller's avatar
Leigh B Stoller committed
3
# Copyright (c) 2009-2015 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
#
24

25 26 27 28 29 30 31
use strict;

our @to_plot;
require "@prefix@/etc/node_usage.conf";

my $num = @to_plot;

Leigh B Stoller's avatar
Leigh B Stoller committed
32 33 34 35 36 37
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use emutil;

my $debug = 0;

38
chdir "@prefix@/data/node_usage";
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

sub true {1}
sub false {0}

#my $TERMINAL = "postscript eps enhanced color";
#my $EXT = "eps";
my $TERMINAL = "png";
my $EXT = "png";
my $LW = 2;

sub plot ( $@ ) {
    my ($what, %ops) = @_;
    open F, ">node_usage-$what.gpl";

    print F "set terminal $TERMINAL\n";
    print F "set grid\n" unless defined $ops{grid} and !$ops{grid};
    print F "\n"; 

    if ($ops{timefmt}) {
        print F "set xdata time\n";
        print F "set timefmt '$ops{timefmt}'\n";
    }
    print F "set format x \"$ops{format_x}\"\n" if defined $ops{format_x};
    foreach my $o (qw(size xrange xtics)) {
        print F "set $o $ops{$o}\n" if defined $ops{$o};
    }
    print F "set xlabel '$ops{xlabel}'\n" if defined $ops{xlabel};
    print F "\n";

    my $lw = $ops{lw};
    $lw = $LW unless defined $lw;

    print F "set output 'node_avail-$what.$EXT'\n";
    print F "set ylabel 'Available Nodes'\n";
73 74 75 76 77 78 79 80 81
    my $i = 2;
    my @plot_lines;
    foreach (@to_plot) {
	my $label = $_->[0];
	push @plot_lines,
	     "'node_usage-$what.dat' using 1:$i title '$label' with lines lw $lw";
	$i++;
    }
    print F "plot ", join(",\\\n     ", @plot_lines), "\n\n";
82 83

    print F "set output 'node_usage-$what.$EXT'\n";
84 85 86 87 88 89 90 91 92 93
    print F "set ylabel 'Node Usage %'\n";
    undef @plot_lines;
    foreach (@to_plot) {
	my $label = $_->[0];
	my $j = $i - $num;
	push @plot_lines,
	     "'node_usage-$what.dat' using 1:(100*\$$i/(\$$j+\$$i)) title '$label' with lines lw $lw";
	$i++;
    }
    print F "plot ", join(",\\\n     ", @plot_lines), "\n\n";
94 95
    close F;

Leigh B Stoller's avatar
Leigh B Stoller committed
96 97 98 99 100
    my $output =
	emutil::ExecQuiet("/usr/local/bin/gnuplot node_usage-$what.gpl");
    if (($? || $debug) && $output ne "") {
	print STDERR $output;
    }
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

plot("hourly_last2weeks",timefmt=>'%Y-%m-%d_%H:$M', format_x=>'%a\n%m/%d');
plot("weekly", timefmt=>'%Y-%m-%d');
plot("daily_last2months", timefmt=>'%Y-%m-%d');
plot("daily", timefmt=>'%Y-%m-%d', size=>'2,1');
plot("monthly", timefmt=>'%Y-%m', format_x=>'%m/%y');
plot("yearly", grid=>false, xlabel => 'Year', xtics=>1);
plot("by_hour", xrange=>"[0:23]",
     xtics=>"('Midnight' 0,'4 am' 4, '8 am' 8, 'Noon' 12, '4 pm' 16, '8 pm' 20, '11 pm' 23)");
#plot("by_hour", xrange=>"[0:23]",
#     xtics=>("('Midnight' 0,'' 1 1, '' 2 1, '' 3 1, ".
#             "'4 am' 4, '' 5 1, '' 6 1, ''7 1, ".
#             "'8 am' 8, '' 9 1, '' 10 1, '' 11 1, ".
#             "'Noon' 12, '' 13 1, '' 14 1, '' 15 1, ".
#             "'4 pm' 16, '' 17 1, '' 18 1, '' 19 1, ".
#             "'8 pm' 20, '' 21 1, '' 22 1, '11 pm' 23)"));
plot("by_dayofweek", xrange=>"[0:6]",
     xtics=>"('Mon' 0, 'Tues' 1, 'Wed' 2, 'Thurs' 3, 'Fri' 4, 'Sat' 5, 'Sun' 6)");
plot("by_hourofweek", xrange=>"[0:7]",
     xtics=>"('Midnight Mon' 0, 'Tues' 1, 'Wed' 2, 'Thurs' 3, 'Fri' 4, 'Sat' 5, 'Sun' 6)");
plot("by_month", xrange=>"[0:11]",
     xtics=>"('Jan' 0, 'Feb' 1, 'Mar' 2, 'Apr' 3, 'May' 4, 'June' 5, 'July' 6, 'Aug' 7, 'Sep' 8, 'Oct' 9, 'Nov' 10, 'Dec' 11)");
124 125 126 127 128 129 130