in reply to clusters with hashes
This seems like a rather poorly defined problem. Let me try to reconstruct what you are trying to do:
So one way to address this problem is to have a hash keyed by server name, and each hash entry's value is a reference to an array of values (server_name, CPU utilization).
Try something like this (untested) code to accumulate total CPU usage:
use strict; use warnings; my %server_hash = ( 'server1' => ['cluster1',0], 'server2' => ['cluster1',0], 'server3' => ['cluster2',0], 'server4' => ['cluster2',0] ); my %cluster_totals = (); foreach my $this_server(keys %server_hash) { $server_hash{$this_server}->[1] = getCPUUtilization($this_server); $cluster_totals{$server_hash{$this_server}->[0]} += $server_hash{$th +is_server}->[1]; } foreach (keys %cluster_totals) { print "Cluster: $_ \t $cluster_totals{$_}\n"; }
Granted, I'm using an extra hash where I probably don't need to, and this solution is off-the-cuff. But it might provide you with a starting point. The nice thing about a hash of array references is that it is extensible when you need to store yet another attribute of the server.
|
|---|