mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
32_SYSSTAT.pm: try to use /proc/uptime instead of uptime first (by viegener)
git-svn-id: https://svn.fhem.de/fhem/trunk@8640 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0469da297e
commit
47da593550
@ -596,15 +596,51 @@ SYSSTAT_getUptime($)
|
||||
return $uptime;
|
||||
}
|
||||
|
||||
my $uptime = SYSSTAT_readFile($hash,"/proc/uptime","");
|
||||
if($uptime) {
|
||||
|
||||
$uptime = $1 if ( $uptime && $uptime =~ /^\s*([0-9.]+)\s+([0-9.]+)/ );
|
||||
|
||||
if( AttrVal($name, "uptime", 0) != 2 ) {
|
||||
# cut off partial seconds
|
||||
$uptime = int( $uptime );
|
||||
my $seconds = $uptime % 60;
|
||||
$uptime = int($uptime / 60);
|
||||
my $minutes = $uptime % 60;
|
||||
$uptime = int($uptime / 60);
|
||||
|
||||
my $hours = $uptime % 24;
|
||||
my $days = int($uptime / 24);
|
||||
|
||||
$uptime = sprintf( "%d days, %d:%.2d", $days, $hours, $minutes);
|
||||
Log3 $name, 4, "$name: uptime returned :$uptime: via proc-uptime file "; # JVI
|
||||
}
|
||||
|
||||
# fallback if by any reason parsing /proc/uptime does not work
|
||||
} else {
|
||||
my $uptime = SYSSTAT_readCmd($hash,"uptime",0);
|
||||
|
||||
$uptime = $1 if( $uptime && $uptime =~ m/[[:alpha:]]{2}\s+(((\d+)\D+,?\s+)?(\d+):(\d+))/ );
|
||||
############# match uptime time statement with the different formats seen on linux
|
||||
# examples
|
||||
# 18:52:21 up 26 days, 21:08, 2 users, load average: 0.04, 0.03, 0.05
|
||||
# 18:52:21 up 26 days, 55 min, 1 user, load average: 0.05, 0.05, 0.05
|
||||
# 18:52:21 up 55 min, 1 user, load average: 0.05, 0.05, 0.05
|
||||
# 18:52:21 up 21:08, 1 user, load average: 0.05, 0.05, 0.05
|
||||
#
|
||||
# complex expression to match only the time parts of the uptime result
|
||||
# $1 is complete up time information of uptime result
|
||||
# $2 is # days part of the uptime
|
||||
# $3 just the # from the "# days"" part or nothing if no days are given
|
||||
# $4 is complete hour/minutes or # min information
|
||||
# $5 is hours part if hours:min are given
|
||||
# $6 is minutes part if hours:min are given
|
||||
# $7 is minutes if # min is given
|
||||
$uptime = $1 if ( $uptime && $uptime =~ m/[[:alpha:]]{2}\s*(((\d*)\s*[[:alnum:]]*,?)?\s+((\d+):(\d+)|(\d+)\s+[[:alpha:]]+in[[:alpha:]]*)),?/ );
|
||||
$uptime = "0 days, $uptime" if( $uptime && !$2);
|
||||
|
||||
if( AttrVal($name, "uptime", 0) == 2 ) {
|
||||
my $days = $3?$3:0;
|
||||
my $hours = $4;
|
||||
my $minutes = $5;
|
||||
my $hours = $5?$5:0;
|
||||
my $minutes = $6?$6:$7;
|
||||
|
||||
$uptime = $days * 24;
|
||||
$uptime += $hours;
|
||||
@ -612,6 +648,8 @@ SYSSTAT_getUptime($)
|
||||
$uptime += $minutes;
|
||||
$uptime *= 60;
|
||||
}
|
||||
Log3 $name, 4, "$name: uptime returned :$uptime: via cmdline "; # JVI
|
||||
}
|
||||
|
||||
return $uptime;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user