Subversion Repositories havirt

Rev

Rev 20 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 rodolico 1
#!/usr/bin/env perl
2
 
3
# All functions related to maniplating/reporting on cluster
4
# part of havirt.
5
 
6
# Copyright 2024 Daily Data, Inc.
7
# 
8
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 
9
# conditions are met:
10
#
11
#   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
12
#   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
13
#   in the documentation and/or other materials provided with the distribution.
14
#   Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
15
#   from this software without specific prior written permission.
16
# 
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
18
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 
24
# v0.0.1 20240602 RWR
25
# Initial setup
26
 
27
package cluster;
28
 
29
use warnings;
30
use strict;  
31
 
32
# define the version number
33
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
34
use version;
19 rodolico 35
our $VERSION = version->declare("1.0.0");
8 rodolico 36
 
37
 
38
use Data::Dumper;
39
 
40
use Exporter;
41
 
42
our @ISA = qw( Exporter );
43
our @EXPORT = qw( 
44
                  &list
45
                );
46
 
11 rodolico 47
sub help {
48
   my @return;
49
   push @return, 'cluster status';
50
   push @return, "\t[--format|-f screen|tsv] - displays some stats on cluster resources used";
51
   return join( "\n", @return ) . "\n";
52
}
53
 
10 rodolico 54
sub status {
55
   my $return = '';
13 rodolico 56
   &main::readDB();
10 rodolico 57
   my @header = ('Node','Threads','Memory','Domains','vcpu','mem_used' );
58
   my @data;
59
   my $usedmem = 0;
60
   my $usedcpu = 0;
61
   my $availmem = 0;
62
   my $availcpu = 0;
63
   my $totalDomains = 0;
13 rodolico 64
   foreach my $node (sort keys %{ $main::statusDB->{'node'} } ) {
10 rodolico 65
      my $memory = 0;
66
      my $vcpus = 0;
67
      my $count = 0;
13 rodolico 68
      foreach my $domain ( keys %{ $main::statusDB->{'nodePopulation'}->{$node}->{'running'} } ) {
69
         $memory += $main::statusDB->{'virt'}->{$domain}->{'memory'};
70
         $vcpus += $main::statusDB->{'virt'}->{$domain}->{'vcpu'};
10 rodolico 71
         $count++;
72
      }
13 rodolico 73
      push @data, [ $node,$main::statusDB->{'node'}->{$node}->{cpu_count},$main::statusDB->{'node'}->{$node}->{memory},$count,$vcpus,$memory ];
10 rodolico 74
      $usedmem += $memory;
75
      $usedcpu += $vcpus;
76
      $totalDomains += $count;
13 rodolico 77
      $availmem += $main::statusDB->{'node'}->{$node}->{memory};
78
      $availcpu += $main::statusDB->{'node'}->{$node}->{cpu_count};
10 rodolico 79
   } # outer for
80
   push @data, [ 'Total',$availcpu,$availmem,$totalDomains,$usedcpu,$usedmem ];
81
   return &main::report( \@header, \@data );
82
}