| 1 | package Lemonldap::Cluster::Status; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||
| 13 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | # This allows declaration use Lemonldap::Cluster::Status ':all'; | ||||||||||||||||||||
| 16 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||
| 17 | # will save memory. | ||||||||||||||||||||
| 18 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | ) ] ); | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | our @EXPORT = qw( | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # Preloaded methods go here. | ||||||||||||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 33 | 0 | my $that =shift; | |||||||||||||||||||
| 34 | 0 | ▶ | my $class = ref($that)|| $that ; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | my $self ={}; | |||||||||||||||||||
| 37 | 0 | bless ($self,$class); | |||||||||||||||||||
| 38 | 0 | %$self= @_; | |||||||||||||||||||
| 39 | #### init nb node #### | ||||||||||||||||||||
| 40 | 0 | my $cp; | |||||||||||||||||||
| 41 | my @nodes; | ||||||||||||||||||||
| 42 | 0 | foreach (keys %$self ) { | |||||||||||||||||||
| 43 | 0 | ▶ | next if /^ADMIN/i ; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | $cp++ ; | |||||||||||||||||||
| 45 | 0 | push @nodes,$_; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | $self->{NODES} = $cp; | |||||||||||||||||||
| 50 | 0 | $self->{anode} =\@nodes; | |||||||||||||||||||
| 51 | ##### | ||||||||||||||||||||
| 52 | #### init time ### | ||||||||||||||||||||
| 53 | 0 | $self->{TIME} = localtime(); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | ##### | ||||||||||||||||||||
| 56 | 0 | $self->{VERSION}= $VERSION; | |||||||||||||||||||
| 57 | #### load nodes infos | ||||||||||||||||||||
| 58 | #### | ||||||||||||||||||||
| 59 | 0 | my %result; | |||||||||||||||||||
| 60 | 0 | my @NOEUD = @{$self->{anode} }; | |||||||||||||||||||
| 61 | 0 | foreach (@NOEUD) { | |||||||||||||||||||
| 62 | ## | ||||||||||||||||||||
| 63 | 0 | my $retour = collect($self->{$_}); | |||||||||||||||||||
| 64 | 0 | $result{$_} = $retour; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 0 | $self->{RESULT} = \%result; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | return $self; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | ▶ | sub PrintHtml { | ||||||||||||||||||
|
Subroutine
PrintHtml: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 75 | 0 | my $self =shift; | |||||||||||||||||||
| 76 | ### formate unit #### | ||||||||||||||||||||
| 77 | 0 | my $t= $self->{TMB} ; | |||||||||||||||||||
| 78 | 0 | my $unite='MB' ; | |||||||||||||||||||
| 79 | 0 | ▶ | if ($t > 1023 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 0 | $unite = 'GB'; | |||||||||||||||||||
| 81 | 0 | $t= $t / 1024 ; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | 0 | $t = sprintf("%.2f",$t); | |||||||||||||||||||
| 84 | 0 | my $tr =$self->{TREQUEST}; | |||||||||||||||||||
| 85 | 0 | my $ta = $self->{ACCESSES} ; | |||||||||||||||||||
| 86 | # $ta=~ s/(\d{3})$/\.$1/; | ||||||||||||||||||||
| 87 | # $ta=~ s/^(\d+)(\d{3})/$1\.$2/; | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | my $message= <<DEBUT; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | <html> | ||||||||||||||||||||
| 93 | <HEAD> | ||||||||||||||||||||
| 94 | <TITLE>Cluster Apache Status</TITLE> | ||||||||||||||||||||
| 95 | </HEAD> | ||||||||||||||||||||
| 96 | <BODY> | ||||||||||||||||||||
| 97 | <H1>Cluster Apache Status for $self->{ADMIN} Group</H1> | ||||||||||||||||||||
| 98 | Lemonldap::Cluster::Status version: $self->{VERSION}<br> | ||||||||||||||||||||
| 99 | <hr> | ||||||||||||||||||||
| 100 | Current Time: $self->{TIME}<br> | ||||||||||||||||||||
| 101 | Number of Nodes: $self->{TNODES} : Status : $self->{STATUS}<br> | ||||||||||||||||||||
| 102 | Total accesses: $ta - Total Traffic: $t $unite<br> | ||||||||||||||||||||
| 103 | CPU Usage: min: $self->{MIN}% max: $self->{MAX}% ave : $self->{MOY}% CPU load<br> | ||||||||||||||||||||
| 104 | $tr requests currently being processed, $self->{IDLE} idle servers<br> | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | <p> | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | <table border=0> | ||||||||||||||||||||
| 110 | <tr><th>Server<th>Address<th>Req<th>Idle<th>CPU<th>Accesses<th>Traffic</tr> | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | DEBUT | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | #suite | ||||||||||||||||||||
| 117 | 0 | my $sum = $self->{SUMMARY} ; | |||||||||||||||||||
| 118 | 0 | my %hs= %$sum; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | my $ligne; | |||||||||||||||||||
| 121 | 0 | foreach (keys %hs ) { | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | my $pu =$hs{$_}{cpu}; | |||||||||||||||||||
| 124 | 0 | $pu= sprintf("%.3f",$pu); | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | my $tr = $hs{$_}{traffic}; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | if ($tr > 1023) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | 0 | $tr= $tr/ 1024 ; | |||||||||||||||||||
| 130 | 0 | $tr= sprintf("%.2fGB",$tr); | |||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||
| 132 | 0 | $tr.="MB"; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | 0 | $ligne .= "<td>$_<td>$self->{$_}<td>$hs{$_}{request}<td>"; | |||||||||||||||||||
| 135 | 0 | $ligne.="$hs{$_}{idle}<td align=right>$pu%<td align=right>$hs{$_}{accesses}<td align=right>$tr</tr>\n"; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | $message.=$ligne; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | $message.=<<tIN; | |||||||||||||||||||
| 142 | </table> | ||||||||||||||||||||
| 143 | <hr> | ||||||||||||||||||||
| 144 | tIN | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | ▶ | if ( $self->{STATUS} ne "NORMAL" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 0 | $message.=<<sy; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | SERVER NO AVAILABLE<p> | ||||||||||||||||||||
| 150 | sy | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | my $hu= $self->{RESULT} ; | |||||||||||||||||||
| 153 | 0 | my $li; | |||||||||||||||||||
| 154 | 0 | foreach (keys %$hu ) { | |||||||||||||||||||
| 155 | 0 | ▶ | if ($hu->{$_} =~ /^UN/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | 0 | $li.="$_ $self->{$_}<br>"; | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | 0 | $message.=$li; | |||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | $message.=<<FIN; | |||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | </BODY> | ||||||||||||||||||||
| 167 | </HTML> | ||||||||||||||||||||
| 168 | FIN | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | return $message; | |||||||||||||||||||
| 172 | 0 | 1; | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | 0 | ▶ | sub collect { | ||||||||||||||||||
|
Subroutine
collect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 179 | 0 | my $node =shift; | |||||||||||||||||||
| 180 | 0 | my $browser =LWP::UserAgent->new(); | |||||||||||||||||||
| 181 | 0 | my $url= "http://$node/server-status"; | |||||||||||||||||||
| 182 | 0 | my $response = $browser->get($url); | |||||||||||||||||||
| 183 | 0 | ▶ | return "UNAVAILABLE" unless $response->is_success(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 184 | 0 | my $content = $response->content(); | |||||||||||||||||||
| 185 | 0 | return $content ; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | 0 | ▶ | sub analyze { | ||||||||||||||||||
|
Subroutine
analyze: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||
| 192 | 0 | my $self = shift; | |||||||||||||||||||
| 193 | 0 | my $host =$self->{RESULT} ; | |||||||||||||||||||
| 194 | 0 | my %res; | |||||||||||||||||||
| 195 | my $ta; | ||||||||||||||||||||
| 196 | 0 | $self->{MIN} = 999; | |||||||||||||||||||
| 197 | 0 | $self->{MAX} =0; | |||||||||||||||||||
| 198 | ########## | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | 0 | my $cp; | |||||||||||||||||||
| 201 | my $tres; | ||||||||||||||||||||
| 202 | 0 | my $tchiffre; | |||||||||||||||||||
| 203 | 0 | my $ti; | |||||||||||||||||||
| 204 | 0 | my $tcpu; | |||||||||||||||||||
| 205 | 0 | foreach (keys %$host) { | |||||||||||||||||||
| 206 | 0 | ▶ | next if $host->{$_} =~ /^UNA/ ; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 207 | 0 | $cp++; | |||||||||||||||||||
| 208 | ### request #### | ||||||||||||||||||||
| 209 | 0 | (my $resquest )= ($host->{$_}=~ /(\d+) requests curr/) ; | |||||||||||||||||||
| 210 | 0 | $res{$_}{request}= $resquest-1; # -1 : request for server-status | |||||||||||||||||||
| 211 | 0 | $tres +=$resquest-1; | |||||||||||||||||||
| 212 | ### traffic ### | ||||||||||||||||||||
| 213 | 0 | (my $chiffre,my $unite) = ($host->{$_}=~ /Total Traffic: (.+?) (MB|GB|kB|B)/); | |||||||||||||||||||
| 214 | 0 | ▶ | if ($unite eq 'GB') { $chiffre = $chiffre * 1024 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 215 | 0 | ▶ | if ($unite eq 'B') { $chiffre =0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 216 | 0 | ▶ | if ($unite eq 'kB') { $chiffre=$chiffre / 1024 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 217 | 0 | $chiffre =sprintf ("%.2f",$chiffre); | |||||||||||||||||||
| 218 | 0 | $tchiffre += $chiffre; | |||||||||||||||||||
| 219 | 0 | $res{$_}{traffic} = $chiffre; | |||||||||||||||||||
| 220 | ### accesses ### | ||||||||||||||||||||
| 221 | 0 | (my $accesses) = ($host->{$_}=~ /Total accesses: (\d+)/) ; | |||||||||||||||||||
| 222 | 0 | $res{$_}{accesses} = $accesses ; | |||||||||||||||||||
| 223 | 0 | $ta += $accesses; | |||||||||||||||||||
| 224 | ### idle ### | ||||||||||||||||||||
| 225 | 0 | (my $idle) = ($host->{$_}=~ /(\d+) idle servers/) ; | |||||||||||||||||||
| 226 | 0 | $res{$_}{idle} = $idle +1 ; | |||||||||||||||||||
| 227 | 0 | $ti += $idle +1 ; | |||||||||||||||||||
| 228 | ### CPU ### | ||||||||||||||||||||
| 229 | 0 | (my $cpu) = ($host->{$_} =~ /Usage.+-(.+)% CPU load/); | |||||||||||||||||||
| 230 | 0 | $tcpu+= $cpu; | |||||||||||||||||||
| 231 | 0 | $res{$_}{cpu} =$cpu; | |||||||||||||||||||
| 232 | 0 | ▶ | $self->{MIN} = $cpu if $cpu < $self->{MIN}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 233 | 0 | ▶ | $self->{MAX} = $cpu if $cpu > $self->{MAX}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | } | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | 0 | $self->{SUMMARY} = \%res; | |||||||||||||||||||
| 240 | #### totalization ### | ||||||||||||||||||||
| 241 | 0 | $self->{STATUS} ="NORMAL"; | |||||||||||||||||||
| 242 | 0 | ▶ | if ($self->{NODES} != $cp) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 243 | 0 | $self->{STATUS} = 'WARNING'; } | |||||||||||||||||||
| 244 | 0 | $self->{ACCESSES} = $ta ; | |||||||||||||||||||
| 245 | 0 | $self->{TNODES} = "$cp/$self->{NODES}"; | |||||||||||||||||||
| 246 | 0 | $self->{TREQUEST} = $tres; | |||||||||||||||||||
| 247 | 0 | $self->{TMB} = $tchiffre; | |||||||||||||||||||
| 248 | 0 | $self->{IDLE} = $ti; | |||||||||||||||||||
| 249 | 0 | $self->{CPU} = $tcpu; | |||||||||||||||||||
| 250 | 0 | $self->{MOY}=0; | |||||||||||||||||||
| 251 | 0 | ▶ | $self->{MOY} = $self->{CPU} / $cp if $cp ; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 252 | 0 | $self->{MOY} = sprintf ("%.3f",$self->{MOY}); | |||||||||||||||||||
| 253 | 0 | $self->{MIN} = sprintf ("%.3f",$self->{MIN}); | |||||||||||||||||||
| 254 | 0 | $self->{MAX} = sprintf ("%.3f",$self->{MAX}); | |||||||||||||||||||
| 255 | 0 | return 1; | |||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | } | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 1 | 1; | |||||||||||||||||||
| 266 | __END__ | ||||||||||||||||||||