| 1 | package MooseFS::Disk; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | extends 'MooseFS::Server'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | has HDtime => ( | ||||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||
| 11 | 0 | ▶ | default => sub { 'max' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 12 | 1 | ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | has HDperiod => ( | ||||||||||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | default => sub { 'min' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=26 SCAR=65.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my $inforef; | |||||||||||||||||||||||||||
| 22 | 0 | for my $ip ( keys %{ $self->info } ) { | |||||||||||||||||||||||||||
| 23 | 0 | my $port = $self->info->{$ip}->{port}; | |||||||||||||||||||||||||||
| 24 | 0 | my $ns = IO::Socket::INET->new( | |||||||||||||||||||||||||||
| 25 | PeerAddr => $ip, | ||||||||||||||||||||||||||||
| 26 | PeerPort => $port, | ||||||||||||||||||||||||||||
| 27 | Proto => 'tcp', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | 0 | print $ns pack('(LL)>', 600, 0); | |||||||||||||||||||||||||||
| 30 | 0 | my $nheader = $self->myrecv($ns, 8); | |||||||||||||||||||||||||||
| 31 | 0 | my ($ncmd, $nlength) = unpack('(LL)>', $nheader); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( $ncmd == 601 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | my $data = $self->myrecv($ns, $nlength); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | while ( $nlength > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($entrysize) = unpack("S>", substr($data, 0, 2)); | |||||||||||||||||||||||||||
| 36 | 0 | my $entry = substr($data, 2, $entrysize); | |||||||||||||||||||||||||||
| 37 | 0 | $data = substr($data, 2+$entrysize); | |||||||||||||||||||||||||||
| 38 | 0 | $nlength -= 2 + $entrysize; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $plen = ord(substr($entry, 0, 1)); | |||||||||||||||||||||||||||
| 41 | 0 | my $ip_path = sprintf "%s:%u:%s", $ip, $port, substr($entry, 1, $plen); | |||||||||||||||||||||||||||
| 42 | 0 | my ($flags, $errchunkid, $errtime, $used, $total, $chunkscnt) = unpack("(CQLQQL)>", substr($entry, $plen+1, 33)); | |||||||||||||||||||||||||||
| 43 | 0 | my ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $usecfsyncsum, $rops, $wops, $fsyncops, $usecreadmax, $usecwritemax, $usecfsyncmax); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($entrysize == $plen + 34 + 144 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($self->HDperiod eq 'min' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 48 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $rops, $wops, $usecreadmax, $usecwritemax) = unpack("(QQQQLLLL)>", substr($entry, $plen+34, 48)); | |||||||||||||||||||||||||||
| 49 | } elsif ($self->HDperiod eq 'hour') { | ||||||||||||||||||||||||||||
| 50 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $rops, $wops, $usecreadmax, $usecwritemax) = unpack("(QQQQLLLL)>", substr($entry, $plen+34+48, 48)); | |||||||||||||||||||||||||||
| 51 | } elsif ($self->HDperiod eq 'day') { | ||||||||||||||||||||||||||||
| 52 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $rops, $wops, $usecreadmax, $usecwritemax) = unpack("(QQQQLLLL)>", substr($entry, $plen+34+48+48, 48)); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } elsif ( $entrysize == $plen + 34 + 192 ) { | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($self->HDperiod eq 'min' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 58 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $usecfsyncsum, $rops, $wops, $fsyncops, $usecreadmax, $usecwritemax, $usecfsyncmax) = unpack("(QQQQQLLLLLL)>", substr($entry, $plen+34, 64)); | |||||||||||||||||||||||||||
| 59 | } elsif ($self->HDperiod eq 'hour') { | ||||||||||||||||||||||||||||
| 60 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $usecfsyncsum, $rops, $wops, $fsyncops, $usecreadmax, $usecwritemax, $usecfsyncmax) = unpack("(QQQQQLLLLLL)>", substr($entry, $plen+34+64, 64)); | |||||||||||||||||||||||||||
| 61 | } elsif ($self->HDperiod eq 'day') { | ||||||||||||||||||||||||||||
| 62 | 0 | ($rbytes, $wbytes, $usecreadsum, $usecwritesum, $usecfsyncsum, $rops, $wops, $fsyncops, $usecreadmax, $usecwritemax, $usecfsyncmax) = unpack("(QQQQQLLLLLL)>", substr($entry, $plen+34+64+64, 64)); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my ($rtime, $wtime, $fsynctime); | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($self->HDtime eq 'avg') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($rops > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $rtime = $usecreadsum/$rops; | |||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 0 | $rtime = 0; | |||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($wops > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $wtime = $usecwritesum/$wops; | |||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||
| 78 | 0 | $wtime = 0; | |||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($fsyncops > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $fsynctime = $usecfsyncsum/$fsyncops; | |||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||
| 84 | 0 | $fsynctime = 0; | |||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 0 | $rtime = $usecreadmax; | |||||||||||||||||||||||||||
| 88 | 0 | $wtime = $usecwritemax; | |||||||||||||||||||||||||||
| 89 | 0 | $fsynctime = $usecfsyncmax; | |||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $status; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($flags == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 94 | 0 | $status = 'marked for removal'; | |||||||||||||||||||||||||||
| 95 | } elsif ($flags == 2) { | ||||||||||||||||||||||||||||
| 96 | 0 | $status = 'damaged'; | |||||||||||||||||||||||||||
| 97 | } elsif ($flags == 3) { | ||||||||||||||||||||||||||||
| 98 | 0 | $status = 'damaged, marked for removal'; | |||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | $status = 'ok'; | |||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $lerror; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($errtime == 0 and $errchunkid == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$errtime == 0 and $errchunkid == 0
MC/DC0%0/2
$errtime == 0 and $errchunkid == 0
$errtime == 0
$errchunkid == 0
Truth table0%0/3
A and B
A= $errtime == 0B= $errchunkid == 0
| |||||||||||||||||||||||||||||
| 105 | 0 | $lerror = 'no errors'; | |||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||
| 107 | 0 | $lerror = localtime($errtime); | |||||||||||||||||||||||||||
| 108 | }; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $rbsize = $rops > 0 ? $rbytes / $rops : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $wbsize = $wops > 0 ? $wbytes / $wops : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $percent_used = $total > 0 ? ($used * 100.0) / $total : '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $rbw = $usecreadsum > 0 ? $rbytes * 1000000 / $usecreadsum : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $wbw = $usecwritesum + $usecfsyncsum > 0 ? $wbytes *1000000 / ($usecwritesum + $usecfsyncsum) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | $self->info->{$ip} = { | |||||||||||||||||||||||||||
| 117 | ip_path => $ip_path, | ||||||||||||||||||||||||||||
| 118 | flags => $flags, | ||||||||||||||||||||||||||||
| 119 | errchunkid => $errchunkid, | ||||||||||||||||||||||||||||
| 120 | errtime => $errtime, | ||||||||||||||||||||||||||||
| 121 | used => $used, | ||||||||||||||||||||||||||||
| 122 | total => $total, | ||||||||||||||||||||||||||||
| 123 | chunkscount => $chunkscnt, | ||||||||||||||||||||||||||||
| 124 | rbw => $rbw, | ||||||||||||||||||||||||||||
| 125 | wbw => $wbw, | ||||||||||||||||||||||||||||
| 126 | rtime => $rtime, | ||||||||||||||||||||||||||||
| 127 | wtime => $wtime, | ||||||||||||||||||||||||||||
| 128 | fsynctime => $fsynctime, | ||||||||||||||||||||||||||||
| 129 | read_ops => $rops, | ||||||||||||||||||||||||||||
| 130 | write_ops => $wops, | ||||||||||||||||||||||||||||
| 131 | fsyncops => $fsyncops, | ||||||||||||||||||||||||||||
| 132 | read_bytes => $rbytes, | ||||||||||||||||||||||||||||
| 133 | write_bytes => $wbytes, | ||||||||||||||||||||||||||||
| 134 | usecreadsum => $usecreadsum, | ||||||||||||||||||||||||||||
| 135 | usecwritesum => $usecwritesum, | ||||||||||||||||||||||||||||
| 136 | status => $status, | ||||||||||||||||||||||||||||
| 137 | lerror => $lerror, | ||||||||||||||||||||||||||||
| 138 | rbsize => $rbsize, | ||||||||||||||||||||||||||||
| 139 | wbsize => $wbsize, | ||||||||||||||||||||||||||||
| 140 | percent_used => $percent_used, | ||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | close($ns); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | 1; | |||||||||||||||||||||||||||