Commit 09eeb9a1 authored by Leigh Stoller's avatar Leigh Stoller

Add a script to create a bar graph of free/inuse nodes (by type).

The only reason it is here, is cause it uses gnuplot.
parent 105c42e1
#
# Copyright (c) 2009 University of Utah and the Flux Group.
# Copyright (c) 2009-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -29,7 +29,7 @@ SUBDIR = node_usage
include $(OBJDIR)/Makeconf
ifeq ($(NODE_USAGE_SUPPORT),1)
LIBEXEC_NODE_USAGE = analy mk-plots refresh analy2 gather publish mk-php-pages get-start-date
LIBEXEC_NODE_USAGE = analy mk-plots refresh analy2 gather publish mk-php-pages get-start-date freenodes
else
LIBEXEC_NODE_USAGE =
endif
......
#!/usr/bin/perl
#
# Copyright (c) 2009-2015 University of Utah and the Flux Group.
#
# {{{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/>.
#
# }}}
#
use English;
use Getopt::Std;
use Data::Dumper;
use Carp;
use POSIX;
use strict;
use warnings;
our @free_types;
require "@prefix@/etc/node_usage.conf";
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use emdb;
use EmulabConstants;
chdir "@prefix@/data/node_usage";
my $date = POSIX::strftime("%m/%d/20%y %H:%M:%S %Z", localtime(time()));
#
# Initialize the counts by type.
#
my %total = ();
my %free = ();
foreach my $type (@free_types) {
my $count = 0;
my $query_result =
DBQueryWarn("select count(*) from nodes where type='$type'");
if ($query_result) {
($count) = $query_result->fetchrow_array();
}
$total{$type} = $count;
$count = 0;
$query_result =
DBQueryFatal("select count(a.node_id) from nodes as a ".
"left join reserved as b on a.node_id=b.node_id ".
"left join nodetypeXpid_permissions as p ".
" on a.type=p.type ".
"where b.node_id is null and a.type='$type' and ".
" a.reserved_pid is null and ".
" p.pid is null and ".
" (a.eventstate='" . TBDB_NODESTATE_ISUP . "' or ".
" a.eventstate='" . TBDB_NODESTATE_POWEROFF . "' or ".
" a.eventstate='" . TBDB_NODESTATE_PXEWAIT . "')");
if ($query_result) {
($count) = $query_result->fetchrow_array();
}
$free{$type} = $count;
}
open(DAT, ">freenodes.dat")
or die("Could open freenodes.dat for writing");
print DAT "Type\tInuse\tFree\n";
foreach my $type (@free_types) {
my $free = $free{$type};
my $inuse = $total{$type} - $free{$type};
print DAT "$type\t$inuse\t$free\n";
}
close(DAT);
open(PLOT, "|/usr/local/bin/gnuplot")
or die("Could not start gnuplot");
print PLOT "set terminal svg\n";
print PLOT "set output 'freenodes.svg'\n";
print PLOT "set title '$date'\n";
print PLOT "set boxwidth 0.9 relative\n";
print PLOT "set xlabel \"Node Type\"\n";
print PLOT "set style fill solid 1 border lt -1\n";
print PLOT "set style data histogram\n";
print PLOT "set style histogram rowstacked\n";
print PLOT "plot 'freenodes.dat' using 2 ti col, '' using 3:xtic(1) ti col\n";
close(PLOT)
or die("Error running gnuplot");
......@@ -37,6 +37,9 @@ $NODE_USAGE_DB = 'node_usage';
["d820s", [qw(d820)], 1346155200]
);
# List of nodes to put into current free bar graph.
@free_types = ('pc600', 'pc850', 'pc3000', 'd710', 'd820');
#
# PHP page header and footer for main page
#
......
#!/bin/sh
#
# Copyright (c) 2009 University of Utah and the Flux Group.
# Copyright (c) 2009-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -26,5 +26,5 @@ cd @prefix@/data/node_usage/
mkdir -p @prefix@/www/node_usage/
cp *.png index.php usage.php @prefix@/www/node_usage/
cp *.png *.svg index.php usage.php @prefix@/www/node_usage/
#!/bin/sh
#
# Copyright (c) 2009 University of Utah and the Flux Group.
# Copyright (c) 2009-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -29,6 +29,7 @@ cd @prefix@/libexec/node_usage
./gather
./analy
./analy2
./freenodes
./mk-plots
./mk-php-pages
./publish
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment