2012-01-27 14:58:33 +00:00
#!/usr/bin/perl -w
2013-11-06 08:47:31 +00:00
# (c) 2012/2013 Joerg Mann / 1&1 Internet AG
2012-01-27 14:58:33 +00:00
#
2012-08-17 11:23:40 +00:00
# last update at now ...
2012-01-27 14:58:33 +00:00
###
use warnings;
use strict;
use English;
2012-02-15 18:11:47 +00:00
use Getopt::Long;
2012-01-27 14:58:33 +00:00
use Term::ANSIColor;
2012-02-15 18:11:47 +00:00
use Date::Language;
2012-02-22 14:52:02 +00:00
use POSIX qw(strftime);
2012-06-08 09:16:55 +00:00
use File::Basename;
2013-11-06 08:47:31 +00:00
binmode STDOUT, ":utf8";
2012-01-27 14:58:33 +00:00
### defaults
2014-04-11 08:37:12 +00:00
my $version = "0.073e";
2012-12-19 15:31:27 +00:00
my $alife_timeout = "30"; # sec for remote-nodes timeout
2012-09-28 12:27:08 +00:00
my $is_tty = 0;
my $mars_dir = '/mars';
my $himself = `uname -n` or die "cannot determine my network node name\n";
my $clearscreen = `clear`;
2013-11-06 08:47:31 +00:00
my $MarsTreeVer = 0.1;
2012-01-27 14:58:33 +00:00
chomp $himself;
### ARGV
2012-02-15 18:11:47 +00:00
# Optionen in Hash-Ref parsen
my $params = {};
2014-04-11 08:37:12 +00:00
GetOptions( $params, 'help', 'h', 'version', 'v', 'resource=s', 'system', 'interval=i', 'history', 'status' , 'ascii', 'debug' );
2013-11-06 08:47:31 +00:00
#########################################################################################
### terminal settings
my $Color_blue = 'yellow';
my $Color_green = 'green';
my $Color_red = 'red';
my $Gls = "\x{2551}";
my $Glw = "\x{2550}";
my $Gkr = "\x{2560}";
my $Gao = "\x{255A}";
my $Gau = "\x{2554}";
if ( $params->{ascii} ) {
$Gls = "|";
$Glw = "-";
$Gkr = "+";
$Gao = "+";
$Gau = "+";
}
my $Gab = "$Glw$Glw$Glw> ";
my $Gfr = " ";
2012-04-10 16:52:25 +00:00
2013-11-06 08:47:31 +00:00
#########################################################################################
2012-09-28 12:27:08 +00:00
### small help
sub display_help {
my $HelpText = shift;
print "$HelpText\n\n" if ($HelpText);
2012-06-05 14:34:37 +00:00
print "Usage: mars-status [--help]\n";
print "Usage: mars-status [--version]\n";
2014-03-19 11:42:38 +00:00
print "Usage: mars-status (without specification of parameters, an abstract of all the information sent)\n";
2014-04-11 08:37:12 +00:00
print "Usage: mars-status [--resource <RESNAME>] [--interval <seconds>] | [--history] | [--status] | [--debug ] | [--system]\n";
2012-06-05 14:34:37 +00:00
print " --resource : limits the display to the specified resource\n";
print " --interval : refreshes the display every second xxx\n";
print " --history : shows information about the log files, version numbers and their status\n";
2014-04-11 08:37:12 +00:00
print " --status : shows graphical status information about sync, resize, fetch and replay\n";
2013-11-06 08:47:31 +00:00
print " --ascii : display history in ascii code letters\n";
2012-09-28 12:27:08 +00:00
print " --system : display mars-system informations\n";
2012-12-19 15:31:27 +00:00
print " --debug : additional display debug messages\n\n";
2014-03-19 11:42:38 +00:00
print "Usage small include refresh : mars-status --interval 2\n";
2012-12-19 15:31:27 +00:00
print "Usage full, include debug : mars-status --system --history --debug\n\n";
2012-06-05 14:34:37 +00:00
exit;
2012-02-15 18:11:47 +00:00
}
2012-09-28 12:27:08 +00:00
if($params->{help} || $params->{h} ) {
display_help;
}
2012-02-15 18:11:47 +00:00
# Farbe zuruecksetzen
$SIG{INT} = sub {
2012-06-05 14:34:37 +00:00
print color 'reset';
print $clearscreen;
exit;
2012-02-15 18:11:47 +00:00
};
2012-09-28 12:27:08 +00:00
#########################################################################################
2012-01-27 14:58:33 +00:00
### figure out TTY
my $tty = readlink '/dev/stdout';
while ( my $temp = readlink $tty ) {
2012-06-05 14:34:37 +00:00
$tty = $temp;
2012-01-27 14:58:33 +00:00
}
if ( $tty =~ /^\/dev\/pts\// ) {
2012-06-05 14:34:37 +00:00
$is_tty = 1;
2012-01-27 14:58:33 +00:00
} elsif ( $tty =~ /^\/dev\/tty/ ) {
2012-06-05 14:34:37 +00:00
$is_tty = 1;
2012-01-27 14:58:33 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
#########################################################################################
2012-01-27 14:58:33 +00:00
### print color
2012-06-05 14:34:37 +00:00
sub print_screen {
2012-09-28 12:27:08 +00:00
my $Text = shift;
my $Color = shift;
my $Level = shift;
2014-03-19 11:42:38 +00:00
$Color = 'FAINT' if (!$Color);
print color "$Color" if ( $is_tty );
print "$Text";
print color 'reset' if ( $is_tty );
2012-01-27 14:58:33 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
#########################################################################################
### read link
sub check_link {
my $dir = shift;
my $result = readlink $dir;
if ( !$result ) {
return 0;
} else {
return $result;
}
}
#########################################################################################
2012-01-27 14:58:33 +00:00
### read links
sub convert_link {
2012-06-05 14:34:37 +00:00
my $link = shift;
2012-12-13 15:02:37 +00:00
$link = check_link "$link";
2012-06-08 09:16:55 +00:00
if (( !$link ) || ( $link eq 0 )) {
2013-11-06 08:47:31 +00:00
print_screen "off", "$Color_red";
2012-06-05 14:34:37 +00:00
} else {
2012-12-19 15:31:27 +00:00
print_screen "on", "$Color_green";
2012-06-05 14:34:37 +00:00
}
return $link;
2012-01-27 14:58:33 +00:00
}
2012-09-28 12:27:08 +00:00
2012-01-27 14:58:33 +00:00
#########################################################################################
### sub display resource-partner
sub display_partner {
2012-12-13 15:02:37 +00:00
my %p = @_;
my $PRes = $p{ressource};
my $PName = $p{nodename};
my $PSize = $p{ressource_size};
my $ref_ResPartner = $p{res_partner};
my $ref_AULogfile = $p{res_AULogfile};
my $PStatus = check_link "$mars_dir/$PRes/primary";
my $PDevice = check_link "$mars_dir/$PRes/device-$PName";
my $Ljoined = check_link "$mars_dir/$PRes/device-$himself";
2012-06-05 14:34:37 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check status
2012-06-05 14:34:37 +00:00
if ( $PStatus eq $PName ) {
2014-03-19 11:42:38 +00:00
print_screen "Primary", "$Color_blue bold";
2012-06-05 14:34:37 +00:00
} else {
2012-01-27 14:58:33 +00:00
if ( $PDevice eq 0 ) {
2013-11-06 08:47:31 +00:00
print_screen "not joined","$Color_red";
2012-09-28 12:27:08 +00:00
print_screen "not joined\n",'', 'Rmonitor';
2013-11-06 08:47:31 +00:00
print_screen " -> Resource is not joined to this node\n", "$Color_red";
2012-09-28 12:27:08 +00:00
return;
2012-06-05 14:34:37 +00:00
} else {
2014-03-19 11:42:38 +00:00
print_screen "Secondary", "$Color_blue bold";
2012-01-27 14:58:33 +00:00
}
2012-06-05 14:34:37 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check alive
2012-06-05 14:34:37 +00:00
my @PAlive = lstat("$mars_dir/alive-$PName");
2012-12-13 15:02:37 +00:00
if ( !$PAlive[9] ) { $PAlive[9] = 0 };
2012-06-05 14:34:37 +00:00
my $PAlive = time()- $PAlive[9] - $alife_timeout;
2012-09-28 12:27:08 +00:00
print_screen ", System", '';
2012-06-05 14:34:37 +00:00
if ( $PAlive > 1 ) {
2014-03-19 11:42:38 +00:00
print_screen " unknown (last message before $PAlive sec) !!!", "$Color_red";
2012-06-05 14:34:37 +00:00
} else {
2014-03-19 11:42:38 +00:00
print_screen " alive", "$Color_green";
2012-06-05 14:34:37 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check device
2014-03-19 11:42:38 +00:00
# disk-device
my $DiskDev = check_link "$mars_dir/$PRes/data-$PName";
print_screen "\n\tDevice : Disk-Device ";
print_screen "$DiskDev", "$Color_blue";
# resize
2012-09-28 12:27:08 +00:00
my $ASize = check_link "$mars_dir/$PRes/actsize-$PName";
if ( $PSize eq $ASize) {
2014-03-19 11:42:38 +00:00
print_screen ", not enlarged";
2012-09-28 12:27:08 +00:00
} else {
2014-03-19 11:42:38 +00:00
print_screen ", resize active","$Color_red bold";
2012-09-28 12:27:08 +00:00
}
2012-08-17 11:23:40 +00:00
2014-03-19 11:42:38 +00:00
# mars-device
my $MarsDev = "/dev/mars/$PDevice";
my $Temp = "";
if ( $PName eq $himself ) { # himself
if ( $PName eq $PStatus) { # himself=primary
print_screen ", used as Mars-Device ";
print_screen "$MarsDev", "$Color_blue";
if ( stat( $MarsDev) ) {
open my $fh, '<', '/proc/mounts' or die $!;
$MarsDev = ( grep { /^$MarsDev / } <$fh> )[0];
if ( $MarsDev ) {
$MarsDev = ( split / /, $MarsDev )[1];
print_screen "\n\t\t---> WORK: mounted as $MarsDev", "$Color_blue";
} else {
print_screen "\n\t\t---> TODO: enable to mount", "$Color_green";
}
} else {
print_screen "\n\t\t---> HINT: unable to mount, mars is starting or defective", "$Color_red";
}
} else { # himself secondary
if ( stat( $MarsDev) ) {
open my $fh, '<', '/proc/mounts' or die $!;
$MarsDev = ( grep { /^$MarsDev / } <$fh> )[0];
if ( !$MarsDev ) {
print_screen "\n\t\t---> HINT: Mars-Device on Secondary available", "$Color_red";
}
}
}
}
if ( $PSize ne $ASize) {
print_screen "\n\t\t---> HINT: resizing used ($PSize != $ASize)","$Color_red";
2012-06-05 14:34:37 +00:00
}
$$ref_ResPartner++;
2012-12-13 15:02:37 +00:00
##########################################################################
### check sync
2012-09-28 12:27:08 +00:00
### sync - status
2012-08-17 11:23:40 +00:00
my $PSyncsize = check_link "$mars_dir/$PRes/syncstatus-$PName";
2014-02-05 13:37:35 +00:00
my $SStatus = sprintf ("%.2f", ($PSyncsize / $PSize * 100));
2014-03-19 11:42:38 +00:00
print_screen (sprintf "\n\tSync : %s bytes (%.3fTB) synced = ", $PSyncsize, ( $PSyncsize/1024/1024/1024/1024));
2012-09-28 12:27:08 +00:00
### sync - speed
2012-12-13 15:02:37 +00:00
my $SSpeed = check_link "$mars_dir/$PRes/actual-$PName/sync_rate";
2014-03-19 11:42:38 +00:00
$SSpeed = sprintf ("%.3f", $SSpeed / 1024 / 1024);
2014-02-05 13:37:35 +00:00
my $SEndTime = ($PSize - $PSyncsize ) / 1024 / 1024 / 1024;
2014-03-19 11:42:38 +00:00
if ( $SSpeed eq "0.000" ) {
2012-09-28 12:27:08 +00:00
$SSpeed = "%";
} else {
2014-02-05 13:37:35 +00:00
$SEndTime = sprintf ("%.2f", $SEndTime / $SSpeed / 60);
2014-03-19 11:42:38 +00:00
$SSpeed = "%, at $SSpeed gb/s (done in $SEndTime min)";
2012-09-28 12:27:08 +00:00
}
2014-03-27 07:53:27 +00:00
### sync - connect
my $SConnect = check_link "$mars_dir/$PRes/actual-$PName/msg-inf-sync";
$SConnect =~ s/.*\@//;
$SConnect =~ s/\'.*//;
2012-09-28 12:27:08 +00:00
### sync - results
if ( $SStatus < 100) {
print_screen "$SStatus$SSpeed\n";
2014-03-27 07:53:27 +00:00
print_screen "\t\t---> WORK: Sync in progress = ($SStatus% < 100.00%)", "$Color_blue";
if ( "$SConnect" ne "OK" ){
print_screen ", transfered from $SConnect\n", "$Color_blue";
} else {
print_screen "\n";
}
2012-09-28 12:27:08 +00:00
} else {
2012-12-19 15:31:27 +00:00
print_screen "$SStatus$SSpeed\n", "$Color_green";
2012-08-17 11:23:40 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
2012-09-28 12:27:08 +00:00
### TODO: work by resize ...
2012-08-17 11:23:40 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check logfile
2012-09-28 12:27:08 +00:00
### logfile - status
2012-06-05 14:34:37 +00:00
my @PLogFile = split (',', check_link "$mars_dir/$PRes/replay-$PName" );
my @PLogLink = split ("-", $PLogFile[0]);
my $PLogName = "$PLogLink[0]-$PLogLink[1]";
my $PLogSize = -s "$mars_dir/$PRes/$PLogFile[0]";
2012-09-28 12:27:08 +00:00
if ( !$PLogFile[1] ) {
$PLogFile[1] = 0; $PLogFile[2] = 0;
}
2012-12-13 15:02:37 +00:00
$PLogSize = 0.0001 if (( !$PLogSize ) || ( $PLogSize eq 0 ));
2012-09-28 12:27:08 +00:00
my $LogSpeed = check_link "$mars_dir/$PRes/actual-$PName/file_rate";
2012-12-13 15:02:37 +00:00
$LogSpeed = sprintf ("%.2f", $LogSpeed / 1024 / 1024);
2012-12-20 11:43:43 +00:00
### TODO:
### logfile - delay
2012-09-28 12:27:08 +00:00
### logfile - results
2014-04-11 08:37:12 +00:00
print_screen (sprintf "\tFetch : %s bytes (%.3fGB) in ", $PLogSize, ( $PLogSize/1024/1024/1024 ));
2012-12-19 15:31:27 +00:00
print_screen "$PLogName", "$Color_green";
2012-12-13 15:02:37 +00:00
print_screen " active";
2014-02-05 13:37:35 +00:00
print_screen ", received with $LogSpeed gb/s" if ( $LogSpeed ne "0.00" );
2012-12-13 15:02:37 +00:00
print_screen "\n";
2012-09-28 12:27:08 +00:00
if ( $Ljoined eq "0" || $PLogSize eq "0.0001" ) {
2014-03-19 11:42:38 +00:00
print_screen "\t\t---> WORK: Logfile wait for starting ...\n", "$Color_blue";
2012-09-28 12:27:08 +00:00
}
if ( ( $ref_AULogfile ) && !($PLogName eq $ref_AULogfile) ) {
2013-11-06 08:47:31 +00:00
print_screen "\t\t---> HINT: Logfile Version not actual = ($PLogName ! $ref_AULogfile)\n", "$Color_red";
2012-06-05 14:34:37 +00:00
}
2012-01-27 14:58:33 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check replay ...
2012-09-28 12:27:08 +00:00
### replay - status
2012-06-05 14:34:37 +00:00
my $RStatus = sprintf("%.2f", ( $PLogFile[1] / $PLogSize * 100));
2012-12-13 15:02:37 +00:00
$RStatus = 0 if ( $Ljoined eq "0" || $PLogSize eq "1" );
$RStatus = 99.99 if (( $PLogFile[1] ne $PLogSize ) && ( $RStatus eq "100.00" ));
2014-04-11 08:37:12 +00:00
print_screen sprintf ("\tReplay : %s bytes (%.3fGB) now replayed, Todo %d, completed ",
2013-11-06 08:47:31 +00:00
$PLogFile[1], ( $PLogFile[1]/1024/1024/1024 ), $PLogFile[2]);
2012-09-28 12:27:08 +00:00
### replay - speed
2012-12-19 15:31:27 +00:00
my $RSpeed = check_link "$mars_dir/$PRes/actual-$PName/replay_rate";
$RSpeed = sprintf ("%.2f", $RSpeed / 1024 / 1024);
2012-09-28 12:27:08 +00:00
if ( $RSpeed eq "0.00" ) {
$RSpeed = "%";
} else {
2014-03-19 11:42:38 +00:00
$RSpeed = "%, at $RSpeed gb/s";
2012-09-28 12:27:08 +00:00
}
2012-08-17 11:23:40 +00:00
2014-03-27 07:53:27 +00:00
### replay - connect
my $RConnect = check_link "$mars_dir/$PRes/actual-$PName/msg-inf-fetch";
$RConnect =~ s/.*\@//;
$RConnect =~ s/\'.*//;
2012-09-28 12:27:08 +00:00
### replay - results
if (( $RStatus < 1 ) && ( $PLogSize != 0.0001 )) {
print_screen "$RStatus$RSpeed\n";
2013-11-06 08:47:31 +00:00
print_screen "\t\t---> HINT: Replay not started, Logfile inactive = (Size: $PLogSize)\n", "$Color_red";
2012-08-17 11:23:40 +00:00
2012-09-28 12:27:08 +00:00
} elsif (( $RStatus < 100 ) && ( $PLogSize != 0.0001 )) {
print_screen "$RStatus$RSpeed\n";
2014-03-27 07:53:27 +00:00
print_screen "\t\t---> WORK: Replay in progress = ($RStatus% < 100.00%)", "$Color_blue";
if ( "$RConnect" ne "OK" ){
print_screen ", transfered from $RConnect\n", "$Color_blue";
} else {
print_screen "\n";
}
2014-04-11 08:37:12 +00:00
print_screen "\t\t---> WORK: Replay now $PLogName\n", "$Color_blue";
2012-09-28 12:27:08 +00:00
} elsif ( $PLogFile[2] > 0 ) {
$RStatus = sprintf("%.2f", ($PLogFile[1]-$PLogFile[2])/$PLogFile[1] * 100);
2013-11-06 08:47:31 +00:00
print_screen "$RStatus$RSpeed\n", "$Color_red";
2012-01-27 14:58:33 +00:00
2012-09-28 12:27:08 +00:00
} elsif ( $PLogSize = 0.0001 ) {
$RStatus = "100.00";
2012-12-19 15:31:27 +00:00
print_screen "$RStatus$RSpeed\n", "$Color_green";
2012-06-05 14:34:37 +00:00
2012-09-28 12:27:08 +00:00
} else {
2012-12-19 15:31:27 +00:00
print_screen "$RStatus% $RSpeed\n", "$Color_green";
2012-09-28 12:27:08 +00:00
}
2012-01-27 14:58:33 +00:00
2014-03-27 07:53:27 +00:00
2012-12-05 15:53:59 +00:00
### replay - hints
if ($PLogFile[2] != 0) {
2014-03-19 11:42:38 +00:00
print_screen "\t\t---> WORK: Replay-Todo is actualy $PLogFile[2], ", "$Color_blue";
2012-12-05 15:53:59 +00:00
if ( $PLogFile[2] < 0 ) {
2013-11-06 08:47:31 +00:00
print_screen "replaying backwards ??? Check this !!!\n", "$Color_red";
2012-12-05 15:53:59 +00:00
} elsif ( $PLogFile[2] > 0 ) {
print_screen "mars it's working ...\n";
} else {
2013-11-06 08:47:31 +00:00
print_screen "replaying working unknown ... Check this !!!\n", "$Color_red";
2012-12-05 15:53:59 +00:00
}
}
2012-06-05 14:34:37 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check actual
2012-09-28 12:27:08 +00:00
my $ActStatus = check_link "$mars_dir/$PRes/actual-$PName/is-primary";
2014-03-19 11:42:38 +00:00
my $ActDevice = check_link "$mars_dir/$PRes/actual-$PName/device-$PDevice";
print_screen "\tActual : Status=";
2012-09-28 12:27:08 +00:00
if ( $ActStatus eq 1 ) {
2014-03-19 11:42:38 +00:00
print_screen "Primary", "$Color_green";
print_screen ", used Device=";
# hack for multiple linkversions
if ( $ActDevice eq "off") {
if ( convert_link "$mars_dir/$PRes/actual-$PName/device-$PDevice" eq "off" ) {
print_screen "on", "$Color_red";
} else {
print_screen "on", "$Color_green";
}
} else {
print_screen "on", "$Color_green";
}
2012-09-28 12:27:08 +00:00
} else {
2014-03-19 11:42:38 +00:00
print_screen "Secondary", "$Color_green";
print_screen ", Syncstatus=";
2012-09-28 12:27:08 +00:00
convert_link "$mars_dir/$PRes/actual-$PName/copy-syncstatus-$PName";
print_screen ", Logfileupdate=";
convert_link "$mars_dir/$PRes/actual-$PName/logfile-update";
2012-06-05 14:34:37 +00:00
}
2014-03-19 11:42:38 +00:00
print_screen ", Attached=";
convert_link "$mars_dir/$PRes/actual-$PName/is-attached";
print_screen "\n";
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check switches
2012-09-28 12:27:08 +00:00
my $SWStatus;
2014-04-11 08:37:12 +00:00
print_screen "\tSwitch : Attach=";
2014-02-05 13:37:35 +00:00
if ( readlink "$mars_dir/$PRes/todo-$PName/attach" eq 1 ) { ### Use of uninitialized value in string
2012-12-19 15:31:27 +00:00
print_screen "on", "$Color_green";
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
print_screen "off", "$Color_red";
2012-09-28 12:27:08 +00:00
}
print_screen " [masked:" if ( $ActStatus eq 1 );
print_screen " Connect=";
2014-02-05 13:37:35 +00:00
if ( readlink "$mars_dir/$PRes/todo-$PName/connect" eq 1 ) { ### Use of uninitialized value in string
2012-12-19 15:31:27 +00:00
print_screen "on", "$Color_green";
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
print_screen "off", "$Color_red";
2012-09-28 12:27:08 +00:00
}
print_screen " Sync=";
2014-02-05 13:37:35 +00:00
if ( readlink "$mars_dir/$PRes/todo-$PName/sync" eq 1 ) { ### Use of uninitialized value in string
2012-12-19 15:31:27 +00:00
print_screen "on", "$Color_green";
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
print_screen "off", "$Color_red";
2012-09-28 12:27:08 +00:00
}
print_screen " AllowReplay=" ;
2014-02-05 13:37:35 +00:00
if ( readlink "$mars_dir/$PRes/todo-$PName/allow-replay" eq 1 ) { ### Use of uninitialized value in string
2012-12-19 15:31:27 +00:00
print_screen "on", "$Color_green";
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
print_screen "off", "$Color_red";
2012-09-28 12:27:08 +00:00
}
print_screen "]" if ( $ActStatus eq 1 );
print_screen "\n";
2012-06-05 14:34:37 +00:00
return $PLogName;
2012-01-27 14:58:33 +00:00
}
2012-09-28 12:27:08 +00:00
#########################################################################################
### check ressources
sub check_ressource {
opendir my $dirhandle, $mars_dir or die "Cannot open $mars_dir: $!";
my @resources = grep { /^res/ && -d "$mars_dir/$_" } readdir $dirhandle;
if ( !@resources ) {
2013-11-06 08:47:31 +00:00
print_screen "---> HINT: no resources found\n", "$Color_red";
2012-09-28 12:27:08 +00:00
next;
}
2012-12-13 15:02:37 +00:00
### read resources
2012-09-28 12:27:08 +00:00
foreach my $res (@resources) {
2012-12-13 15:02:37 +00:00
my $ResPartner = 0;
my $res_name = $res;
$res_name =~ s/^resource-//;
2012-09-28 12:27:08 +00:00
if ( $params->{'resource'} ) {
if (!( $params->{'resource'} eq $res_name)) {
next;
}
}
2012-12-13 15:02:37 +00:00
my $res_size = check_link "$mars_dir/$res/size";
2012-09-28 12:27:08 +00:00
if ( $res_size eq 0 ) { $res_size = 1 };
2012-12-13 15:02:37 +00:00
my $res_tbsize = ( $res_size) / 1024 / 1024 /1024 / 1024;
my $res_master = check_link "$mars_dir/$res/primary";
2012-09-28 12:27:08 +00:00
if ( $res_master eq 0 ) { $res_master = "unknown" };
print_screen sprintf("-> check resource %s, with %.3fTB, Primary Node is %s\n", $res_name, $res_tbsize, $res_master), 'bold';
### him self
2013-11-06 08:47:31 +00:00
my $himselfip = check_link "$mars_dir/ips/ip-$himself";
print_screen " -> local Node ($himself [$himselfip]) as ",'bold';
2012-09-28 12:27:08 +00:00
my $ActualUsedLogfile = display_partner(
ressource => $res,
nodename => $himself,
ressource_size => $res_size,
res_partner => \$ResPartner,
res_AULogfile => "",
);
# end him self
### joined (und nicht monitor)...
2014-03-19 11:42:38 +00:00
if ( $ResPartner eq 1 ) {
2012-09-28 12:27:08 +00:00
### partners
opendir my $server_dh, "$mars_dir/$res" or die "Cannot open $mars_dir/$res: $!";
my @servers = grep { /^data/ && readlink "$mars_dir/$res/$_" } readdir $server_dh;
@servers = sort (@servers);
foreach my $partner (@servers) {
$partner =~ s/^data-//;
if ( $partner eq $himself ) { next; }
2013-12-05 14:18:17 +00:00
$himselfip = check_link "$mars_dir/ips/ip-$partner";
2013-11-06 08:47:31 +00:00
print_screen " -> remote Node ($partner [$himselfip]) as ", 'bold';
2012-09-28 12:27:08 +00:00
display_partner(
ressource => $res,
nodename => $partner,
ressource_size => $res_size,
res_partner => \$ResPartner,
res_AULogfile => $ActualUsedLogfile,
);
}
} # end joined
### modus
if ( $ResPartner eq 0 ) {
2013-11-06 08:47:31 +00:00
print_screen " -> modus for resource $res_name is remote ($ResPartner nodes)\n",'bold';
2012-09-28 12:27:08 +00:00
} elsif ( $ResPartner eq 1 ) {
2013-11-06 08:47:31 +00:00
print_screen " -> modus for resource $res_name is standalone ($ResPartner node)\n",'bold';
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
print_screen " -> modus for resource $res_name is clustered ($ResPartner nodes)\n ",'bold';
2012-09-28 12:27:08 +00:00
}
### resources history
if ( $params->{'history'} ) {
check_logfile( $res, $ResPartner );
}
2014-04-11 08:37:12 +00:00
if ( $params->{'status'} ) {
check_status( $res, $ResPartner );
}
2012-09-28 12:27:08 +00:00
2012-12-05 15:53:59 +00:00
### check resources debug
if ($params->{'debug'}) {
2013-11-06 08:47:31 +00:00
print_screen " -> Debug for $res\n", 'bold';
2012-12-13 15:02:37 +00:00
my $debug_res;
2014-03-27 07:53:27 +00:00
### TODO: small hack, read files ...
$debug_res = check_debugfile("$res", "1.info"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("$res", "2.warn"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("$res", "3.error"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("$res", "4.fatal"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("$res", "5.total"); print_screen "$debug_res" if ( $debug_res );
2012-12-05 15:53:59 +00:00
}
2012-09-28 12:27:08 +00:00
} # end foreach
}
2014-04-11 08:37:12 +00:00
#########################################################################################
###
sub check_status {
my $LResource = shift;
print_screen " -> Cluster Status - Resource $LResource\n", 'bold';
my $StatusFaktor = 100;
my $StatusNode = "";
my $StatusSize = 0;
my $StatusDummy = 0;
my $StatusDevice = 0;
# read logfile-size from primary
my $StaPrimary = check_link ( "$mars_dir/$LResource/primary" );
my @PrimarySize = <$mars_dir/$LResource/version-*$StaPrimary>;
foreach my $PrimarySize (@PrimarySize) {
my $LogFile = $PrimarySize;
$LogFile =~ s/.*version-//;
$LogFile = -s "$mars_dir/$LResource/log-$LogFile";
if ( !$LogFile ) { $LogFile = 0 };
$PrimarySize = check_link ( $PrimarySize );
$PrimarySize =~ s/:.*//;
$PrimarySize =~ s/.*,//;
if ( $StatusDummy < 1 ) { $StatusDummy = $PrimarySize; }
if ( $LogFile > $PrimarySize ) {
$StatusSize = $StatusSize + $LogFile;
} else {
$StatusSize = $StatusSize + $PrimarySize;
}
}
### read master-device-size
my @Size = <$mars_dir/$LResource/*size*>;
foreach my $Size ( @Size) {
$Size = check_link ($Size);
if ( $StatusDevice < $Size ) {
$StatusDevice = $Size;
}
}
my $StatusLineA = "\tStatus Resize/Sync |";
my $StatusLineB;
for (my $i=1; $i<$StatusFaktor; $i+=1) {
$StatusLineA = $StatusLineA."#";
}
print_screen "$StatusLineA\n", "$Color_blue";
### read device-size by nodes
my @NodeSize = <$mars_dir/$LResource/actsize-*>;
foreach my $NodeSize (@NodeSize) {
$StatusLineA = "";
$StatusLineB = "";
my @NodeName = split("-",$NodeSize);
$StatusNode = $NodeName[2];
my $NodeActs = sprintf("%d", (check_link "$mars_dir/$LResource/actsize-$StatusNode") / $StatusDevice * $StatusFaktor);
my $NodeSync = sprintf("%d", (check_link "$mars_dir/$LResource/syncstatus-$StatusNode") / $StatusDevice * $StatusFaktor);
for (my $i=2; $i<$NodeActs; $i+=1) {
$StatusLineA = $StatusLineA.">";
}
$StatusLineA = $StatusLineA."R";
for (my $i=2; $i<$NodeSync; $i+=1) {
$StatusLineB = $StatusLineB.">";
}
$StatusLineB = $StatusLineB."S";
### print out
for (my $i=length($StatusNode); $i<20; $i+=1) {
$StatusNode = $StatusNode." ";
}
print "\t$StatusNode|$StatusLineA\n |$StatusLineB\n";
}
### search all versions from primary
my $StatusLineC = "\n\tStatus Replay/Fetch ";
my $StatusLineD = "\tLogfile-Version ";
my @Version = <$mars_dir/$LResource/version-*$StaPrimary>;
foreach my $Version (@Version) {
my $VersionNr = $Version;
$VersionNr =~ s/^.*version-([0-9]+)-.*$/$1/;
my @VersionDetail = split (',', check_link "$Version" );
my $VersionLogFile = $VersionDetail[1];
my $VersionLogSize = $VersionDetail[2];
$VersionLogSize =~ s/:.*//;
$VersionLogSize = $VersionLogSize / $StatusSize * $StatusFaktor;
$StatusLineC = $StatusLineC."|";
for (my $i=2; $i<$VersionLogSize; $i+=1) {
$StatusLineC = $StatusLineC."#";
}
$StatusLineD = $StatusLineD."|".$VersionNr;
for (my $i=11; $i<$VersionLogSize; $i+=1) {
$StatusLineD = $StatusLineD." ";
}
}
print_screen "$StatusLineC#\n", "$Color_blue";
print "$StatusLineD\n";
### search via nodes
my @Replay = <$mars_dir/$LResource/replay-*>;
foreach my $StatusNode (@Replay) {
$StatusLineC = "";
$StatusLineD = "";
my $NodeReplay = 0;
my $NodeFetch = $StatusDummy / $StatusSize * $StatusFaktor;
$StatusNode =~ s/.*-//;
my @Version = <$mars_dir/$LResource/version-*$StatusNode>;
foreach my $Version (@Version) {
my $NodeSize = check_link ( $Version );
$Version =~ s/.*version-//;
$Version =~ s/-.*//;
### use replay
my @ReplaySize = split(",",check_link ( "$mars_dir/$LResource/replay-$StatusNode" ));
my $ReplayLink = $ReplaySize[0];
my $ReplayVers = "log-$Version-";
if ( $ReplayLink =~ m/$ReplayVers/i ) {
$NodeSize = $ReplaySize[1];
} else {
$NodeSize =~ s/:.*//;
$NodeSize =~ s/.*,//;
}
$NodeSize = sprintf("%d",$NodeSize / $StatusSize * $StatusFaktor);
$NodeReplay = $NodeSize + $NodeReplay;
$StatusLineC = $StatusLineC."|";
for ( my $i=1; $i<$NodeSize; $i+=1 ) {
$StatusLineC = $StatusLineC.">";
}
### use fetch
my $LogSize = 0;
my @LogFile = <$mars_dir/$LResource/log-$Version-*>;
foreach my $LogFile (@LogFile) {
$LogSize = -s $LogFile;
}
$LogSize = sprintf("%d",$LogSize / $StatusSize * $StatusFaktor);
$NodeFetch = $LogSize + $NodeFetch;
if ( !$LogSize ) { $LogSize = $NodeSize };
$StatusLineD = $StatusLineD."|";
for (my $i=1; $i<$LogSize; $i+=1) {
$StatusLineD = $StatusLineD.">";
}
}
## select replay rest
if ( $NodeReplay < 100 ) {
$NodeReplay = sprintf("%d",$NodeReplay);
$StatusLineC = $StatusLineC."R";
for ( my $i=$NodeReplay; $i<99; $i+=1 ) {
$StatusLineC = $StatusLineC."!";
}
} else {
$StatusLineC = $StatusLineC."R";
}
### select fetch rest
if ( $NodeFetch < 100 ) {
$NodeFetch = sprintf("%d",$NodeFetch);
$StatusLineD = $StatusLineD."F";
for ( my $i=$NodeFetch; $i<99; $i+=1 ) {
$StatusLineD = $StatusLineD."!";
}
} else {
$StatusLineD = $StatusLineD."F";
}
### print out
for (my $i=length($StatusNode); $i<20; $i+=1) {
$StatusNode = $StatusNode." ";
}
print "\t$StatusNode$StatusLineC\n\t $StatusLineD\n";
}
}
2012-01-27 14:58:33 +00:00
#########################################################################################
###
sub check_logfile {
2012-06-05 14:34:37 +00:00
my $LResource = shift;
my $LPartner = shift;
2013-11-06 08:47:31 +00:00
my $LastVersionNr = "0";
print_screen " -> History Replay/Status\n", 'bold';
2012-06-05 14:34:37 +00:00
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
### search all version's
my @Version = <$mars_dir/$LResource/version-*>;
foreach my $Version (@Version) {
my $VersionNr = $Version;
$VersionNr =~ s/^.*version-([0-9]+)-.*$/$1/;
if ( "$LastVersionNr" eq "$VersionNr" ) {
next; # same Versionnr -> next
} else {
$LastVersionNr = $VersionNr;
}
print_screen "\t$Gls\n", "$Color_red";
print_screen "\t$Gkr$Gab", "$Color_red";
print_screen "Vers.$VersionNr", "$Color_blue";
### check logfile
my @LogFile = <$mars_dir/$LResource/log-$VersionNr-*>;
my $LogFile = $LogFile[0];
my $LogSize = 0;
my $LogHost = "";
if ( $LogFile) {
### found logfile
$LogSize = -s "$LogFile";
$LogHost = $LogFile;
$LogHost =~ s/.*log-([0-9]+)-//;
if ( !$LogSize ) { $LogSize = 0; }
### logfile stat
my @LogStat = stat ( $LogFile );
$LogStat[10] = gmtime($LogStat[10]);
### quickfix times ...
if ($LogStat[9] > $LogStat[8]) {
$LogStat[9] = $LogStat[9] - $LogStat[8];
} else {
$LogStat[9] = $LogStat[8] - $LogStat[9];
}
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
print_screen " $Gab", "$Color_red";
print_screen sprintf("Logfile Size: $LogSize bytes (%.3fGB) by %s from %s, include hypothetically %s sec\n", ($LogSize /1024/1024/1024), $LogHost, $LogStat[10], $LogStat[9]), "$Color_blue";
} else {
### not found logfile
print_screen " $Gab", "$Color_red";
print_screen "old Version, Logfile is deleted ...\n", "$Color_blue";
}
### check sources
my $VersionFileCount = 0;
my $VersionErrorSize = 0;
my $VersionErrorChk = 0;
my $VersionLastChk = 0;
my @VersionFile = <$mars_dir/$LResource/version-$VersionNr*>;
2014-03-19 11:42:38 +00:00
my $VersionNode = "";
2013-11-06 08:47:31 +00:00
foreach my $VersionFile (@VersionFile) {
my @VersionDetail = check_link "$VersionFile";
@VersionDetail = split (',|:', "@VersionDetail" );
my $VersionSource = $VersionFile;
$VersionSource =~ s/.*[0-9]-//;
### add counter for node-check
$VersionFileCount++;
### 0 chksum log now / 1 name log now / 2 size log now / 3 chksum log old / 4 name log old / 5 size log old
if ( $VersionSource eq $LogHost ) {
# primary
if ( ($VersionFileCount eq $LPartner) || ($VersionFileCount > 1) ) {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gao$Gab", "$Color_red";
} else {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gao$Gab", "$Color_red";
}
2014-03-19 11:42:38 +00:00
$VersionNode = "Primary \t ";
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
} elsif ( $LogHost eq "" ) {
# none
if ( $VersionFileCount eq $LPartner ) {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gao$Gab", "$Color_red";
} else {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gkr$Gab", "$Color_red";
}
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
} else {
2013-12-05 14:18:17 +00:00
# secondary
2013-11-06 08:47:31 +00:00
if ( $VersionFileCount eq $LPartner ) {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr$Gfr $Gao$Gab", "$Color_red";
} elsif ( $VersionFileCount > 1 ) {
2013-12-05 14:18:17 +00:00
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gls$Gfr$Gkr$Gab", "$Color_red";
2013-11-06 08:47:31 +00:00
} else {
print_screen "\t$Gls$Gfr$Gls$Gfr$Gfr $Gls$Gfr$Gau$Gab", "$Color_red";
}
2014-03-19 11:42:38 +00:00
$VersionNode = "Secondary";
2013-11-06 08:47:31 +00:00
};
2014-03-19 11:42:38 +00:00
print_screen sprintf ("$VersionNode $VersionSource \tCheck: $VersionDetail[0] \tSize: $VersionDetail[2] bytes (%.3fGB)", $VersionDetail[2] / 1024 / 1024 / 1024 );
2013-11-06 08:47:31 +00:00
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
if ( $LogFile ) {
### size
$LogSize = $VersionDetail[2] if ( $LogSize < $VersionDetail[2] ); # hack, wenn secondary nicht das ganze log hat
if ( $VersionDetail[2] eq 0 ) {
print_screen " ---> replay waiting for start", "$Color_green";
} elsif ( $LogSize eq $VersionDetail[2] ) {
print_screen " ---> replay OK", "$Color_green";
} else {
my $ReplayTodo = ($LogSize - $VersionDetail[2]) / 1024 / 1024 / 1024;
print_screen sprintf (" ---> replay incomplete (Todo %.3fGB)",$ReplayTodo), "$Color_red";
$VersionErrorSize = 1;
}
### chksum
if ( $VersionErrorSize eq 1 ) {
print_screen "\n";
$VersionErrorChk = 1;
} elsif ( $VersionLastChk eq $VersionDetail[0] || $VersionLastChk eq 0 ) {
print_screen ", verify OK\n", "$Color_green";
} else {
### TODO: primary first system ?
print_screen ", verify failed\n", "$Color_red";
$VersionErrorChk = 1;
}
2012-12-19 15:31:27 +00:00
2013-11-06 08:47:31 +00:00
### TODO: failed chksum ?
$VersionLastChk = $VersionDetail[0]; # save for next foreach
2012-12-19 15:31:27 +00:00
} else {
2013-11-06 08:47:31 +00:00
### no logfile found
print_screen "\t(no longer available logfile)\n";
2012-06-05 14:34:37 +00:00
}
2013-11-06 08:47:31 +00:00
2012-06-08 09:16:55 +00:00
### check delete infos
my @DeleteFiles = <$mars_dir/todo-global/delete-*>;
foreach my $DeleteFiles (@DeleteFiles) {
2013-11-06 08:47:31 +00:00
if (( !$DeleteFiles ) || ( !(readlink $DeleteFiles) )) {
2012-07-18 07:40:16 +00:00
$DeleteFiles = "n/a";
} else {
$DeleteFiles = basename (readlink $DeleteFiles);
}
2013-11-06 08:47:31 +00:00
if ( $LogFile && $DeleteFiles eq $LogFile ) {
print_screen "\t$Gls$Gfr$Gkr$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "\t\t---> TODO: LogFile ist marked for delete ($DeleteFiles).\n", "$Color_green";
2012-06-08 09:16:55 +00:00
}
}
2013-11-06 08:47:31 +00:00
} # end foreach $VersionFiles
### same checks
if ( $VersionFileCount ne $LPartner ) {
print_screen "\t$Gls$Gfr$Gkr$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "HINT: Count of Logfiles different = (Cluster has $LPartner Nodes, but only find $VersionFileCount Node)\n", "$Color_red";
2013-11-06 08:47:31 +00:00
}
if ( $VersionErrorSize eq 1 && $VersionErrorChk eq 1) {
# print_screen "\t$Gls$Gfr$Gao$Gab\n", "$Color_red";
} elsif ( $VersionErrorSize eq 1 ) {
print_screen "\t$Gls$Gfr$Gkr$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "HINT: Logfiles has not equal size and same Checksums, ups ... \n","$Color_red";
2013-11-06 08:47:31 +00:00
} elsif ( $VersionErrorSize ne 1 && $VersionErrorChk eq 1 ) {
print_screen "\t$Gls$Gfr$Gkr$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "HINT: Logfiles has not equal Checksums and same size, check for SPLIT-BRAIN\n","$Color_red";
2013-11-06 08:47:31 +00:00
}
2012-09-28 12:27:08 +00:00
2013-11-06 08:47:31 +00:00
if ( `ls -l $mars_dir/$LResource/replay-* | grep $VersionNr` ) {
print_screen "\t$Gls$Gfr$Gao$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "WORK: Version are actual and used. ", "$Color_blue";
2013-11-06 08:47:31 +00:00
if ( $VersionErrorSize ne 1 && $VersionErrorChk ne 1) {
print_screen "Wait for start replay ...\n", "$Color_green";
} else {
print_screen "Replay in progress ...\n", "$Color_green";
}
} elsif ( !$LogFile ) {
print_screen "\t$Gls$Gfr$Gao$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "WORK: Version is deleted the next log-rotate ...\n", "$Color_blue";
2013-11-06 08:47:31 +00:00
} elsif ( !`ls -l $mars_dir/$LResource/replay-* | grep $VersionNr` && $LogFile ) {
print_screen "\t$Gls$Gfr$Gao$Gab", "$Color_red";
2014-03-19 11:42:38 +00:00
print_screen "TODO: Logfiles has all equal Sizes and Checksums, can be deleted ...\n", "$Color_green";
2013-11-06 08:47:31 +00:00
} else {
print "ups ??";
}
2012-09-28 12:27:08 +00:00
2013-11-06 08:47:31 +00:00
} # end foreach $Version
2012-01-27 14:58:33 +00:00
}
2012-06-08 09:16:55 +00:00
2012-02-22 14:52:02 +00:00
#########################################################################################
2012-12-05 15:53:59 +00:00
### check debug-files
sub check_debugfile {
2012-12-20 11:43:43 +00:00
### TODO: Fix Level / diaplying
2012-12-05 15:53:59 +00:00
my $debug_dir = shift;
my $debug_level = shift;
my $debug_file = "$mars_dir/$debug_dir/$debug_level.status";
if ( open (MARS_DEBUG, "< $debug_file") ) {
my $mars_debug = "";
while ( <MARS_DEBUG> ) {
2012-06-05 14:34:37 +00:00
if ( m/^(\d+\.\d+)/ ) {
s/^(\d+\.\d+)/strftime("%a %b %e %H:%M:%S %Y:", localtime($1))/e;
} else {
$_ = localtime(0) . ': ' . $_;
}
2012-12-05 15:53:59 +00:00
s/MARS_DEBUG\s+//;
$mars_debug = "$mars_debug\t$_";
2012-06-05 14:34:37 +00:00
}
2012-12-05 15:53:59 +00:00
close MARS_DEBUG;
return "$mars_debug" if ( $mars_debug ne "");
2012-06-05 14:34:37 +00:00
}
2012-03-09 15:10:48 +00:00
}
2012-02-22 14:52:02 +00:00
#########################################################################################
2012-06-05 14:34:37 +00:00
### info version
sub info_version {
### module
my %mars_info;
open ( my $lsmod_handle,'-|','lsmod | grep mars' ) || die "blub ... $!";
if (!<$lsmod_handle>) {
2013-11-06 08:47:31 +00:00
print_screen "Module Mars not running\n","$Color_red";
2012-06-05 14:34:37 +00:00
sleep(10);
next;
}
open ( my $modinfo_handle, '-|', 'modinfo mars' ) || die "cannot run modinfo mars: $!";
while ( my $line = <$modinfo_handle> ) {
chomp $line;
my ( $key, $value) = split /: +/, $line;
if ( $value) {
$mars_info{$key} = $value;
2012-04-10 16:52:25 +00:00
}
2012-06-05 14:34:37 +00:00
}
if ( $mars_info{author} eq "") {
2013-11-06 08:47:31 +00:00
print_screen "Module Mars not running\n","$Color_red";
2012-06-05 14:34:37 +00:00
next;
}
### status
2012-12-19 15:31:27 +00:00
print_screen "MARS Status - $himself, $version", "$Color_blue";
if ( $params->{'resource'} ) { print_screen ", Ressource: $params->{'resource'}", "$Color_blue"; }
2012-06-08 09:16:55 +00:00
print_screen "\n";
2012-06-05 14:34:37 +00:00
### marsadm
my $MAVersion = qx"marsadm version";
2012-12-19 15:31:27 +00:00
print_screen "MARS Admin - $MAVersion", "$Color_blue";
2012-06-05 14:34:37 +00:00
### module
2012-12-19 15:31:27 +00:00
print_screen "MARS Module - $mars_info{version}\n", "$Color_blue";
2012-06-05 14:34:37 +00:00
### kernel
my $KVersion = '/proc/version';
open my $Kfh, '<', "$KVersion" or die $!;
$KVersion = ( grep { /^Linux/ } <$Kfh> )[0];
$KVersion = ( split / /, $KVersion )[2];
2012-12-19 15:31:27 +00:00
print_screen "MARS Kernel - $KVersion\n", "$Color_blue";
2012-06-05 14:34:37 +00:00
2012-06-08 09:16:55 +00:00
print_screen "-------------------------------------------------------------------------------\n";
2012-06-05 14:34:37 +00:00
}
2012-04-10 16:52:25 +00:00
2012-02-22 14:52:02 +00:00
2012-08-17 11:23:40 +00:00
#########################################################################################
2014-03-19 11:42:38 +00:00
### diskfull
sub check_diskfull {
my @diskfull = glob("$mars_dir/rest-space-*");
my $diskfull_mars = "";
print_screen "-> Cluster Diskspace:", 'bold';
if ( @diskfull ) {
foreach ( @diskfull ) {
my $diskfull_space = check_link "$_";
my $diskfull_system = $_;
$diskfull_system =~ s!/mars/rest-space-!!;
if ( $diskfull_space < 1 ) {
$diskfull_space = sprintf ("%.2f", $diskfull_space / 1024 );
if ( $diskfull_system eq $himself ) {
print_screen "\n\t-> HINT: Local Partition $mars_dir full ($diskfull_space kb Limit) !!! mars is stopping !!!\n->", "$Color_red bold";
$diskfull_mars = "$diskfull_mars,$diskfull_system";
} else {
print_screen "\n\t-> HINT: Remotesystem $diskfull_system have mars-disk full ($diskfull_space kb Limit) !!!\n->", "$Color_red bold";
$diskfull_mars = "$diskfull_mars,$diskfull_system";
}
}
}
}
### TODO: /0
if ( !$diskfull_mars ) {
print_screen " smoothly ", "$Color_green";
}
}
#########################################################################################
### emergency
2012-08-17 11:23:40 +00:00
sub check_jammed {
2013-04-05 11:04:55 +00:00
my $jammed = check_link "$mars_dir/emergency-$himself";
2014-03-19 11:42:38 +00:00
print_screen " Transaktions:", 'bold';
if ( !$jammed ) {
print_screen " smoothly ", "$Color_green";
2012-08-17 11:23:40 +00:00
} else {
2014-03-19 11:42:38 +00:00
print_screen " and Replication not running !!!\n-> ", "$Color_red";
}
}
#########################################################################################
### synclimit
sub check_synclimit {
my $synclimit;
if ( open (MARS_LIMIT, "< /proc/sys/mars/sync_limit") ) {
while (<MARS_LIMIT>) {
$synclimit .= $_;
$synclimit =~ s/[\n\t]//g;
}
close MARS_LIMIT;
}
print_screen " Synclimit:", 'bold';
if ( !$synclimit ) {
print_screen " smoothly ", "$Color_green";
} else {
print_screen " set to $synclimit !!!\n", "$Color_red";
2012-08-17 11:23:40 +00:00
}
}
#########################################################################################
### limit's auslesen ...
sub check_limit {
2012-12-13 15:02:37 +00:00
my $LimitText = shift; # sol-text
my $LimitSolVar = shift; # sol-filename
my $LimitSolEin = shift; # sol-einheit
my $LimitIstVar = shift; # ist-filename
my $LimitIstEin = shift; # ist-einheit
2012-12-05 15:53:59 +00:00
$LimitSolVar = "" if (!$LimitSolVar);
$LimitIstVar = "" if (!$LimitIstVar);
$LimitSolEin = "" if (!$LimitSolEin);
$LimitIstEin = "" if (!$LimitIstEin);
2012-09-28 12:27:08 +00:00
### soll
2012-12-05 15:53:59 +00:00
my $mars_limit_sol;
if ( open (MARS_LIMIT, "< /proc/sys/mars/$LimitSolVar") ) {
2012-08-17 11:23:40 +00:00
while (<MARS_LIMIT>) {
2012-12-05 15:53:59 +00:00
$mars_limit_sol .= $_;
$mars_limit_sol =~ s/[\n\t]//g;
2012-08-17 11:23:40 +00:00
}
close MARS_LIMIT;
}
2013-12-05 14:18:17 +00:00
$mars_limit_sol = 0 if ( !$mars_limit_sol);
2012-09-28 12:27:08 +00:00
### ist
2012-12-05 15:53:59 +00:00
my $mars_limit_ist;
if ( open (MARS_LIMIT, "< /proc/sys/mars/$LimitIstVar") ) {
while (<MARS_LIMIT>) {
$mars_limit_ist .= $_;
$mars_limit_ist =~ s/[\n\t]//g;
2012-09-28 12:27:08 +00:00
}
2012-12-05 15:53:59 +00:00
close MARS_LIMIT;
}
2013-12-05 14:18:17 +00:00
$mars_limit_ist = 0 if ( !$mars_limit_ist);
2012-09-28 12:27:08 +00:00
### presently results
2013-11-06 08:47:31 +00:00
print_screen "$LimitText ", 'bold';
2012-12-05 15:53:59 +00:00
if ( ($LimitSolVar) && !($LimitIstVar) ) {
2013-11-06 08:47:31 +00:00
### sol & lamport_clock
2012-12-05 15:53:59 +00:00
if ( $LimitSolVar eq "lamport_clock" ) {
my $C_Time = $mars_limit_sol;
$C_Time =~ s/CURRENT_TIME=//;
$C_Time =~ s/lamport_now=.*//;
my $L_Time = $mars_limit_sol;
$L_Time =~ s/.*lamport_now=//;
$mars_limit_sol = sprintf("%.2f", $C_Time - $L_Time);
2013-11-06 08:47:31 +00:00
print_screen "$mars_limit_sol $LimitSolEin,";
### restliches
2012-12-05 15:53:59 +00:00
} elsif ( $mars_limit_sol < 1 ) {
2013-11-06 08:47:31 +00:00
print_screen "is now unsed,", "$Color_green";
2012-09-28 12:27:08 +00:00
} else {
2012-12-05 15:53:59 +00:00
print_screen "is set to ";
2013-11-06 08:47:31 +00:00
print_screen "$mars_limit_sol $LimitSolEin,", "$Color_red";
2012-09-28 12:27:08 +00:00
}
2012-12-05 15:53:59 +00:00
} elsif ( !($LimitSolVar) && ($LimitIstVar) ) {
2012-12-13 15:02:37 +00:00
### only ist
2013-11-06 08:47:31 +00:00
print_screen "is actualy ";
2012-12-05 15:53:59 +00:00
if ( $mars_limit_ist < 1 ) {
2013-11-06 08:47:31 +00:00
if ( $LimitIstEin eq "on/off" ) {
print_screen "off,", "$Color_green";
} else {
print_screen "null", "$Color_green";
}
2012-09-28 12:27:08 +00:00
} else {
2013-11-06 08:47:31 +00:00
if ( $LimitIstEin eq "on/off" ) {
print_screen "on,", "$Color_red";
} else {
print_screen "$mars_limit_ist $LimitIstEin,", "$Color_red";
}
2012-09-28 12:27:08 +00:00
}
2013-11-06 08:47:31 +00:00
# TODO fixen !
# } elsif ( ($LimitSolVar) && ($LimitIstVar) && ($mars_limit_sol < 1) ) {
# ### sol & ist = 0
# print_screen "is actualy unused(X),";
2012-12-05 15:53:59 +00:00
} else {
2012-12-13 15:02:37 +00:00
### sol & ist / rest ...
2012-12-05 15:53:59 +00:00
print_screen "is set to ";
2013-11-06 08:47:31 +00:00
print_screen "$mars_limit_sol $LimitSolEin", "$Color_red";
2012-12-05 15:53:59 +00:00
print_screen ", actualy used ";
2013-11-06 08:47:31 +00:00
print_screen "$mars_limit_ist $LimitIstEin,", "$Color_red";
2012-08-17 11:23:40 +00:00
}
2012-12-05 15:53:59 +00:00
2012-08-17 11:23:40 +00:00
}
2013-11-06 08:47:31 +00:00
##############################################################################
### mars-system
sub check_systemstatus {
print_screen "---> Systemdata <---\n", "$Color_blue bold";
### text / sol-file / sol-einheit / ist-file / ist-einheit
2014-02-05 13:37:35 +00:00
check_limit "-> AVG Limit", "loadavg_limit", "loadavg";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Memory Limit", "mem_limit_percent", "%", "mem_used_raw_kb", "kb";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Traffic Limit Client", "traffic_tuning/client_role_traffic_ratelimit_kb", "kb/s", "traffic_tuning/client_role_traffic_rate_kb", "kb/s";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Traffic Limit Server", "traffic_tuning/server_role_traffic_ratelimit_kb", "kb/s", "traffic_tuning/server_role_traffic_rate_kb", "kb/s";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Traffic Writeback", "traffic_tuning/writeback_ratelimit_kb", "kb/s", "traffic_tuning/writeback_rate_kb", "kb/s";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> I/O Writeback", "io_tuning/writeback_ratelimit_kb", "kb/s", "io_tuning/writeback_rate_kb", "kb/s";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Server-IO Limit", "tuning/server_io_limit_kb", "kb/s", "tuning/server_io_rate_kb", "kb/s";
check_limit " Flying IO", "", "", "io_flying_count";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Copy Read: Prio", "copy_read_prio", "";
check_limit " Flying IO", "", "", "copy_read_max_fly";
print "\n";
check_limit "-> Copy Write: Prio", "copy_write_prio", "";
check_limit " Flying IO", "", "", "copy_write_max_fly";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> LoggerMemory", "", "", "logger_mem_used_kb", "kb";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> FreeSpaceLimit LogRotate", "logrot_auto_gb", "gb";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Network-IO-Timeout", "network_io_timeout", "sec";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Clear Page Cache", "", "", "mapfree_period_sec", "sec";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Statusfile Rollover", "", "", "statusfiles_rollover_sec", "sec";
2013-11-06 08:47:31 +00:00
print "\n";
2014-02-05 13:37:35 +00:00
check_limit "-> Modus: Fast Full Sync", "", "", "do_fast_fullsync", "on/off";
check_limit " AIO Sync", "", "", "aio_sync_mode", "on/off";
check_limit " Delay say Overflow", "", "", "delay_say_on_overflow", "on/off";
check_limit " Emergency", "", "", "mars_emergency_mode", "on/off";
check_limit " Logger Resume", "", "", "logger_resume", "on/off";
print "\n";
check_limit "-> LamportClockDifferenz", "lamport_clock", "sec";
check_limit " Mars Port", "mars_port", "";
2013-11-06 08:47:31 +00:00
print "\n";
my $mars_disk_space = `df '$mars_dir' | grep '$mars_dir'| awk '{print \$2}'`;
$mars_disk_space = sprintf("%01.2f", $mars_disk_space / 1024);
check_limit "-> Free-Space-Limit on /mars", "required_free_space_1_gb", "mb (actualy $mars_disk_space mb used)";
print "\n";
}
2012-12-13 15:02:37 +00:00
##############################################################################
2012-06-05 14:34:37 +00:00
### main loop ...
while(1) {
my $dateFormat = Date::Language->new('English');
### version only
if ( $params->{version} || $params->{v}) {
info_version;
exit 0;
}
2013-11-06 08:47:31 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
2012-06-05 14:34:37 +00:00
### main run
print $clearscreen;
2012-12-20 11:43:43 +00:00
print "\nNOTE !!!\n********\nThe author does not guarantee this development-test-alpha-pre-beta-version, it is untested and certainly not fully functional. Use at your own risk ;)\n\n";
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
2013-11-06 08:47:31 +00:00
##########################################################################
### mars-tree-version
my @MarsTreeVersion = <$mars_dir/tree-*>;
foreach my $MarsTreeVersion (@MarsTreeVersion) {
if (check_link "$MarsTreeVersion" ne $MarsTreeVer ) {
print "*** Sorry, unknown Tree-Version of Mars unknown\n";
exit 1;
}
}
2012-12-13 15:02:37 +00:00
##########################################################################
2012-06-05 14:34:37 +00:00
### read mars infos
2012-09-28 12:27:08 +00:00
info_version;
2012-06-05 14:34:37 +00:00
2013-11-06 08:47:31 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
### check system limits
2012-09-28 12:27:08 +00:00
if ( $params->{'system'} ) {
2013-11-06 08:47:31 +00:00
check_systemstatus;
2012-06-05 14:34:37 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
2014-02-05 13:37:35 +00:00
### check system params
2014-03-19 11:42:38 +00:00
check_diskfull;
2014-02-05 13:37:35 +00:00
check_jammed;
2014-03-19 11:42:38 +00:00
check_synclimit;
2012-06-05 14:34:37 +00:00
### check resources
2014-03-19 11:42:38 +00:00
print_screen "\n---> Resources <---\n", "$Color_blue bold";
2012-06-05 14:34:37 +00:00
check_ressource;
2012-12-13 15:02:37 +00:00
##########################################################################
2012-12-05 15:53:59 +00:00
### check global debug
if ($params->{'debug'}) {
2013-11-06 08:47:31 +00:00
print_screen "---> Debug <---\n", "$Color_blue bold";
print_screen "-> Main-Debug:\n", "$Color_red";
2012-12-13 15:02:37 +00:00
my $debug_res;
2014-03-27 07:53:27 +00:00
#$debug_res = check_debugfile("", "1.info"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("", "2.warn"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("", "3.error"); print_screen "$debug_res" if ( $debug_res );
#$debug_res = check_debugfile("", "4.fatal"); print_screen "$debug_res" if ( $debug_res );
$debug_res = check_debugfile("", "5.total"); print_screen "$debug_res" if ( $debug_res );
2012-12-05 15:53:59 +00:00
}
2012-09-28 12:27:08 +00:00
2012-12-13 15:02:37 +00:00
##########################################################################
2012-06-08 09:16:55 +00:00
### end, next loop
2012-06-05 14:34:37 +00:00
print color 'reset';
exit if (not $params->{'interval'});
sleep($params->{'interval'});
2012-08-17 11:23:40 +00:00
2012-01-27 14:58:33 +00:00
}
2013-12-05 14:18:17 +00:00
exit;