summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpbuetow (lxpbuetow) <puppet@mx.buetow.org>2011-12-21 17:21:24 +0100
committerpbuetow (lxpbuetow) <puppet@mx.buetow.org>2011-12-21 17:21:24 +0100
commit893d719c63a5489e8f3f1cf8d552f8c28b232098 (patch)
tree0cd0ab93fbde6fb03e71f3c23dbc7d0f60cc1e5f
parent69dba57432b48925d8a56e05f2d1e877a1f55aa3 (diff)
Add rudimentary --cluster option which can parse /etc/clusters from clusterssh
-rw-r--r--WISHLIST1
-rwxr-xr-xloadbars27
2 files changed, 26 insertions, 2 deletions
diff --git a/WISHLIST b/WISHLIST
index aeabd86..46f1d9f 100644
--- a/WISHLIST
+++ b/WISHLIST
@@ -1,6 +1,5 @@
* Stats for other stuff (e.g. memory, inodes..., disk usage)
* Dynamic/online resizing of the window
-* Rudimentary support for /etc/clusters, the Cluster-SSH configuration file
* Adding and removing hosts online
* .deb for Debian and Ubuntu
* Allow sshusername@hostname in --hosts
diff --git a/loadbars b/loadbars
index c1c7650..84b8c10 100755
--- a/loadbars
+++ b/loadbars
@@ -80,6 +80,7 @@ sub debugsay (@) { say "Loadbars::DEBUG: $_" for @_; return undef }
sub sum (@) { my $sum = 0; $sum += $_ for @_; return $sum }
sub null ($) { my $arg = shift; return defined $arg ? $arg : 0 }
sub set_togglecpu_regexp () { $C{cpuregexp} = $C{togglecpu} ? 'cpu ' : 'cpu' }
+sub error ($) { die shift, "\n" }
sub parse_cpu_line ($) {
my ($name, %load);
@@ -573,6 +574,7 @@ END
average_hot_up => { menupos => 4, cmd => 'a', help => 'Increases number of samples for calculating avg. by 1', mode => 1 },
average_hot_dn => { menupos => 5, cmd => 'y', help => 'Decreases number of samples for calculating avg. by 1', mode => 1 },
+ cluster => { menupos => 6, help => 'Cluster name from /etc/clusters', var => \$C{cluster}, mode => 6, type => 's' },
configuration => { menupos => 6, cmd => 'c', help => 'Show current configuration', mode => 4 },
factor => { menupos => 7, help => 'Set graph scale factor (1.0 means 100%)', mode => 6, type => 's' },
@@ -684,6 +686,27 @@ END
return (\$hosts, $closure);
}
+sub get_cluster_hosts ($) {
+ my $cluster = shift;
+ my $confile = '/etc/clusters';
+
+ open my $fh, $confile or error "$!: $confile";
+ my $hosts;
+
+ while (<$fh>) {
+ if (/^$cluster\s*(.*)/) {
+ $hosts = $1;
+ last;
+ }
+ }
+
+ close $fh;
+
+ error "No such cluster in $confile: $cluster" unless defined $hosts;
+
+ return split /\s+/, $hosts;
+}
+
sub main () {
my ($hosts, $dispatch) = dispatch_table;
my $usage;
@@ -699,13 +722,15 @@ sub main () {
my @hosts = split ',', $$hosts;
- if (@hosts) {
+ if (@hosts || defined $C{cluster}) {
+ push @hosts, get_cluster_hosts $C{cluster} if defined $C{cluster};
system 'ssh-add';
} else {
@hosts = 'localhost';
}
+
my @threads = create_threads @hosts;
main_loop $dispatch, @threads;
}