From 09eeb9a15115bd2462eadc34d36f51a2af4be409 Mon Sep 17 00:00:00 2001 From: Leigh B Stoller Date: Thu, 2 Apr 2015 08:49:25 -0600 Subject: [PATCH] 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. --- node_usage/GNUmakefile.in | 4 +- node_usage/freenodes.in | 101 ++++++++++++++++++++++++++++++++ node_usage/node_usage.conf.utah | 3 + node_usage/publish.in | 4 +- node_usage/refresh.in | 3 +- 5 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 node_usage/freenodes.in diff --git a/node_usage/GNUmakefile.in b/node_usage/GNUmakefile.in index 9fdda2ac6..7025f6c4d 100644 --- a/node_usage/GNUmakefile.in +++ b/node_usage/GNUmakefile.in @@ -1,5 +1,5 @@ # -# 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 diff --git a/node_usage/freenodes.in b/node_usage/freenodes.in new file mode 100644 index 000000000..f1bef2e0f --- /dev/null +++ b/node_usage/freenodes.in @@ -0,0 +1,101 @@ +#!/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 . +# +# }}} +# +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"); diff --git a/node_usage/node_usage.conf.utah b/node_usage/node_usage.conf.utah index 71ac9f337..2c8062392 100644 --- a/node_usage/node_usage.conf.utah +++ b/node_usage/node_usage.conf.utah @@ -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 # diff --git a/node_usage/publish.in b/node_usage/publish.in index 792c792ba..b82caf261 100755 --- a/node_usage/publish.in +++ b/node_usage/publish.in @@ -1,6 +1,6 @@ #!/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/ diff --git a/node_usage/refresh.in b/node_usage/refresh.in index 630224ac6..9b5f165d8 100755 --- a/node_usage/refresh.in +++ b/node_usage/refresh.in @@ -1,6 +1,6 @@ #!/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 -- GitLab