Line 71... |
Line 71... |
71 |
push @return, "\tin maintenance mode";
|
71 |
push @return, "\tin maintenance mode";
|
72 |
|
72 |
|
73 |
return join( "\n", @return ) . "\n";
|
73 |
return join( "\n", @return ) . "\n";
|
74 |
}
|
74 |
}
|
75 |
|
75 |
|
- |
|
76 |
sub getClusterStats {
|
- |
|
77 |
my $return = {};
|
- |
|
78 |
foreach my $node (sort keys %{ $main::statusDB->{'node'} } ) {
|
- |
|
79 |
$return->{'nodes'}->{$node}->{'node_memory'} = $main::statusDB->{'node'}->{$node}->{'memory'};
|
- |
|
80 |
$return->{'nodes'}->{$node}->{'node_vcpu'} = $main::statusDB->{'node'}->{$node}->{'cpu_count'};
|
- |
|
81 |
$return->{'nodes'}->{$node}->{'node_maintenance'} = $main::statusDB->{'node'}->{$node}->{'maintenance'};
|
- |
|
82 |
|
- |
|
83 |
$return->{'nodes'}->{$node}->{'domain_memory'} = 0;
|
- |
|
84 |
$return->{'nodes'}->{$node}->{'domain_vcpu'} = 0;
|
- |
|
85 |
$return->{'nodes'}->{$node}->{'domain_count'} = 0;
|
- |
|
86 |
foreach my $domain ( keys %{ $main::statusDB->{'nodePopulation'}->{$node}->{'running'} } ) {
|
- |
|
87 |
$return->{'nodes'}->{$node}->{'domain_memory'} += $main::statusDB->{'virt'}->{$domain}->{'memory'};
|
- |
|
88 |
$return->{'nodes'}->{$node}->{'domain_vcpu'} += $main::statusDB->{'virt'}->{$domain}->{'vcpu'};
|
- |
|
89 |
$return->{'nodes'}->{$node}->{'domain_count'}++;
|
- |
|
90 |
$return->{'nodes'}->{$node}->{'domains'}->{$domain}->{'memory'} = $main::statusDB->{'virt'}->{$domain}->{'memory'};
|
- |
|
91 |
$return->{'nodes'}->{$node}->{'domains'}->{$domain}->{'vcpu'} = $main::statusDB->{'virt'}->{$domain}->{'vcpu'};
|
- |
|
92 |
}
|
- |
|
93 |
if ( ! $main::statusDB->{'node'}->{$node}->{'maintenance'} ) { # do not include node resources if maintenance set
|
- |
|
94 |
$return->{'total_memory'} += $return->{'nodes'}->{$node}->{'node_memory'};
|
- |
|
95 |
$return->{'total_vcpu'} += $return->{'nodes'}->{$node}->{'node_vcpu'};
|
- |
|
96 |
}
|
- |
|
97 |
$return->{'total_count'} += $return->{'nodes'}->{$node}->{'domain_count'};
|
- |
|
98 |
$return->{'domain_memory'} += $return->{'nodes'}->{$node}->{'domain_memory'};
|
- |
|
99 |
$return->{'domain_vcpu'} += $return->{'nodes'}->{$node}->{'domain_vcpu'};
|
- |
|
100 |
|
- |
|
101 |
}
|
- |
|
102 |
return $return;
|
- |
|
103 |
}
|
- |
|
104 |
|
76 |
sub status {
|
105 |
sub status {
|
77 |
my $return = '';
|
106 |
my $return = '';
|
78 |
&main::readDB();
|
107 |
&main::readDB();
|
79 |
my @header = ('Node','Threads','Memory','Domains','vcpu','mem_used', 'Status' );
|
108 |
my @header = ('Node','Threads','Memory','Domains','vcpu','mem_used', 'Status' );
|
80 |
my @data;
|
109 |
my @data;
|
Line 209... |
Line 238... |
209 |
push @return, "No new entries";
|
238 |
push @return, "No new entries";
|
210 |
}
|
239 |
}
|
211 |
return join( "\n", @return ) . "\n";
|
240 |
return join( "\n", @return ) . "\n";
|
212 |
} # updateISCITargets
|
241 |
} # updateISCITargets
|
213 |
|
242 |
|
- |
|
243 |
# Creates a balance report to show the user what went on
|
- |
|
244 |
# $cluster is a hash created by sub getClusterStats, and possibly modified by
|
- |
|
245 |
# the calling process
|
- |
|
246 |
sub showBalanceReport {
|
- |
|
247 |
my $cluster = shift;
|
- |
|
248 |
my $variance = 0;
|
- |
|
249 |
my $count = 0;
|
- |
|
250 |
my @header = ('Node','Threads','Memory(G)','Domains','vcpu_alloc','mem_alloc(G)', 'vcpu%', 'mem%', 'Status', 'StdDev' );
|
- |
|
251 |
my @data;
|
- |
|
252 |
foreach my $node ( sort keys %{ $cluster->{'nodes'} } ) {
|
- |
|
253 |
# get standard deviation
|
- |
|
254 |
my $stddev = $cluster->{'nodes'}->{$node}->{'node_maintenance'} ? 0 :
|
- |
|
255 |
(
|
- |
|
256 |
( $cluster->{'nodes'}->{$node}->{'domain_memory'} / $cluster->{'nodes'}->{$node}->{'node_memory'} * 100 ) -
|
- |
|
257 |
( $cluster->{'domain_memory'} / $cluster->{'total_memory'} * 100 )
|
- |
|
258 |
) ** 2;
|
- |
|
259 |
|
- |
|
260 |
push @data, [
|
- |
|
261 |
$node,
|
- |
|
262 |
$cluster->{'nodes'}->{$node}->{'node_vcpu'},
|
- |
|
263 |
sprintf( '%d', $cluster->{'nodes'}->{$node}->{'node_memory'}/1024/1024 ),
|
- |
|
264 |
$cluster->{'nodes'}->{$node}->{'domain_count'},
|
- |
|
265 |
$cluster->{'nodes'}->{$node}->{'domain_vcpu'},
|
- |
|
266 |
$cluster->{'nodes'}->{$node}->{'domain_memory'}/1024/1024,
|
- |
|
267 |
sprintf( '%2.0f%%', $cluster->{'nodes'}->{$node}->{'domain_vcpu'} / $cluster->{'nodes'}->{$node}->{'node_vcpu'} * 100 ),
|
- |
|
268 |
sprintf( '%2.0f%%', $cluster->{'nodes'}->{$node}->{'domain_memory'} / $cluster->{'nodes'}->{$node}->{'node_memory'} * 100 ),
|
- |
|
269 |
$cluster->{'nodes'}->{$node}->{'node_maintenance'} ? 'Maintenance' : '',
|
- |
|
270 |
sprintf( "%d", $stddev )
|
- |
|
271 |
];
|
- |
|
272 |
$variance += $stddev;
|
- |
|
273 |
$count++;
|
- |
|
274 |
}
|
- |
|
275 |
push @data, [
|
- |
|
276 |
'All',
|
- |
|
277 |
$cluster->{'total_vcpu'},
|
- |
|
278 |
sprintf( '%d', $cluster->{'total_memory'}/1024/1024 ),
|
- |
|
279 |
$cluster->{'total_count'},
|
- |
|
280 |
$cluster->{'domain_vcpu'},
|
- |
|
281 |
$cluster->{'domain_memory'}/1024/1024,
|
- |
|
282 |
sprintf( '%2.0f%%', $cluster->{'domain_vcpu'} / $cluster->{'total_vcpu'} * 100 ),
|
- |
|
283 |
sprintf( '%2.0f%%', $cluster->{'domain_memory'} / $cluster->{'total_memory'} * 100 ),
|
- |
|
284 |
''
|
- |
|
285 |
];
|
- |
|
286 |
return &main::report( \@header, \@data ),sprintf( "%d", $variance / $count );
|
- |
|
287 |
}
|
- |
|
288 |
|
- |
|
289 |
# attempt to balance the domains on the active (maintenance = false) nodes
|
- |
|
290 |
# basically, we take what is currently working, and calculate the variance
|
- |
|
291 |
# of it (see https://en.wikipedia.org/wiki/Standard_deviation). If that is
|
- |
|
292 |
# over about a 10, we move things around, if possible, then check our variance
|
- |
|
293 |
# again.
|
214 |
sub balance {
|
294 |
sub balance {
|
- |
|
295 |
&main::readDB();
|
- |
|
296 |
# get the current cluster status
|
- |
|
297 |
my $cluster = &getClusterStats();
|
- |
|
298 |
# for development, turn on verbose
|
- |
|
299 |
$main::config->{'flags'}->{'verbose'} = 1;
|
- |
|
300 |
# show user what it looks like at first
|
- |
|
301 |
if ( $main::config->{'flags'}->{'verbose'} ) {
|
- |
|
302 |
print "Starting Status\n\n";
|
- |
|
303 |
my ($report, $variance) = &showBalanceReport( $cluster) ;
|
- |
|
304 |
print $report;
|
- |
|
305 |
print "Variance is $variance\n";
|
- |
|
306 |
}
|
- |
|
307 |
|
- |
|
308 |
die;
|
- |
|
309 |
#die Dumper( $cluster ) . "\n";
|
215 |
return "This function not implemented yet\n";
|
310 |
return "This function not implemented yet\n";
|
216 |
}
|
311 |
}
|
- |
|
312 |
|