File Coverage

blib/lib/IBM/StorageSystem/Node.pm
Criterion Covered Total %
statement 33 76 43.4
branch 0 6 0.0
condition 0 4 0.0
subroutine 11 15 73.3
pod 0 1 0.0
total 44 102 43.1


line stmt bran cond sub pod time code
1             package IBM::StorageSystem::Node;
2              
3 1     1   5 use strict;
  1         2  
  1         30  
4 1     1   4 use warnings;
  1         2  
  1         22  
5              
6 1     1   576 use IBM::StorageSystem::Statistic::Node::Memory;
  1         2  
  1         27  
7 1     1   1006 use IBM::StorageSystem::Statistic::Node::CPU;
  1         2  
  1         26  
8 1     1   581 use IBM::StorageSystem::Statistic::Node::DiskRead;
  1         3  
  1         24  
9 1     1   502 use IBM::StorageSystem::Statistic::Node::DiskWrite;
  1         2  
  1         26  
10 1     1   5 use Carp qw(croak);
  1         1  
  1         40  
11 1     1   4 use Scalar::Util qw(weaken);
  1         1  
  1         81  
12              
13             our $VERSION = '0.02';
14             our @ATTR = qw( CTDB_status connection_status CTDB_IP_address daemon_IP_address
15             daemon_version description GPFS_status hostname
16             IP is_cache is_manager is_quorum
17             last_updated monitoring_enabled OS_family OS_name
18             product_version recovery_master role serial_number
19             username version
20             );
21              
22             foreach my $attr ( @ATTR ) {
23             {
24 1     1   5 no strict 'refs';
  1         1  
  1         136  
25             *{ __PACKAGE__ .'::'. $attr } = sub {
26 0     0     my( $self, $val ) = @_;
27 0 0         $val =~ s/\#/no/ if $val;
28 0 0         $self->{$attr} = $val if $val;
29 0           return $self->{$attr}
30             }
31             }
32             }
33              
34             our $STATS = {
35             memory => {
36             cmd => '-g memory_stats',
37             class => 'IBM::StorageSystem::Statistic::Node::Memory'
38             },
39             cpu => {
40             cmd => '-g cpu_stats',
41             class => 'IBM::StorageSystem::Statistic::Node::CPU'
42             }
43             };
44              
45             foreach my $stat ( keys %{ $STATS } ) {
46             {
47 1     1   4 no strict 'refs';
  1         2  
  1         151  
48             *{ __PACKAGE__ .'::'. $stat } = sub {
49 0     0     my( $self, $t ) = @_;
50 0   0       $t ||= 'minute';
51 0           my $stats = $self->{__ibm}->__lsperfdata(
52             cmd => "$STATS->{$stat}->{cmd} -t $t -n $self->{hostname}",
53             class => $STATS->{$stat}->{class}
54             );
55 0           return $stats
56             }
57             }
58             }
59              
60             foreach my $m ( qw(reads writes) ) {
61             {
62 1     1   5 no strict 'refs';
  1         1  
  1         574  
63             *{ __PACKAGE__ .'::disk_'. $m } = sub {
64 0     0     my( $self, $t ) = @_;
65 0   0       $t ||= 'minute';
66 0           my $stats = IBM::StorageSystem::StatisticsSet->new;
67 0           my( $headers, @stats ) = split( /\n/,
68             $self->{__ibm}->__cmd( "lsperfdata -g disk_$m -t $t -n $self->{hostname}" ) );
69             # disk_reads and disk_writes perfdata stats use non-parsable CSV for the column headers
70             # This neccesitates the ugliness below
71 0           pop @stats;
72 0           my @cols = split /\[#\]/, $headers;
73 0           my @f = ( split /,/, shift @cols )[0,1,3];
74            
75 0           for ( @cols ) { push @f, ( split /,/ )[2] }
  0            
76              
77 0           @cols = map { s/^ *//;
  0            
78 0           s/ *$//;
79 0           s/ /_/g;
80 0           s/-/_/g;
81 0           lc($_)
82             } @f;
83              
84 0           foreach my $stat ( @stats ) {
85 0           my @values = split /,/, $stat;
86 0           ( my $m = 'IBM::StorageSystem::Statistic::Node::Disk' . ucfirst $m ) =~ s/s$//;
87 0           my $s = $m->new;
88 0           my $c = 0;
89              
90 0           foreach my $col ( @cols ) {
91 0           $s->$col( $values[$c++] );
92             }
93              
94 0           $stats->__push( $s )
95             }
96              
97 0           return $stats
98             }
99             }
100             }
101              
102             sub new {
103 0     0 0   my( $class, $ibm, %args ) = @_;
104 0           my $self = bless {}, $class;
105 0           weaken( $self->{__ibm} = $ibm );
106              
107 0 0         defined $args{Hostname} or croak 'Constructor failed: mandatory Hostname argument not supplied';
108              
109             # Modify the passed arg attribute names for nicer formatting - lower cased except for acronyms
110 0           foreach my $attr ( keys %args ) {
111 0           my $mattr = lc $attr;
112              
113 0           foreach my $s ( qw(ctdb gpfs ip os) ) {
114 0           my $u = uc $s;
115 0           $mattr =~ s/(^|_)($s)/$1$u/g
116             }
117              
118 0           $self->{$mattr} = $args{$attr}
119             }
120              
121 0           return $self;
122             }
123              
124             1;
125              
126             __END__