mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-08 01:14:19 +00:00
statistics2.cgi: for debugging
git-svn-id: https://svn.fhem.de/fhem/trunk@14586 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
de675b4ad0
commit
587db25ae6
@ -27,14 +27,15 @@ visualisation provided by markusbloch
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Time::HiRes qw(time);
|
|
||||||
use DBI;
|
use DBI;
|
||||||
|
use CGI qw(:standard Vars);
|
||||||
|
#use Data::Dumper;
|
||||||
|
use JSON;
|
||||||
|
use POSIX qw(mktime);
|
||||||
|
use Time::HiRes qw(time);
|
||||||
|
|
||||||
use lib "./lib";
|
use lib "./lib";
|
||||||
use Geo::IP;
|
use Geo::IP;
|
||||||
use JSON;
|
|
||||||
use CGI qw(:standard Vars);
|
|
||||||
|
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
sub insertDB();
|
sub insertDB();
|
||||||
sub getLocation();
|
sub getLocation();
|
||||||
@ -52,7 +53,7 @@ my $geoip = $ENV{HTTP_X_FORWARDED_FOR};
|
|||||||
|
|
||||||
my %data = Vars();
|
my %data = Vars();
|
||||||
|
|
||||||
# database stuff
|
# database stuff for statistics
|
||||||
my $datadir = "./data";
|
my $datadir = "./data";
|
||||||
my $dbf = "$datadir/fhem_statistics_2017.sqlite";
|
my $dbf = "$datadir/fhem_statistics_2017.sqlite";
|
||||||
my $dsn = "dbi:SQLite:dbname=$dbf";
|
my $dsn = "dbi:SQLite:dbname=$dbf";
|
||||||
@ -60,6 +61,8 @@ my $dbh;
|
|||||||
my $sth;
|
my $sth;
|
||||||
my $limit = "datetime('now', '-12 months')";
|
my $limit = "datetime('now', '-12 months')";
|
||||||
|
|
||||||
|
# path to working copy
|
||||||
|
my $fhemPathSvn = '/opt/fhem';
|
||||||
|
|
||||||
# ---------- decide target ----------
|
# ---------- decide target ----------
|
||||||
|
|
||||||
@ -85,6 +88,17 @@ sub insertDB() {
|
|||||||
|
|
||||||
$dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) ||
|
$dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) ||
|
||||||
die "Cannot connect: $DBI::errstr";
|
die "Cannot connect: $DBI::errstr";
|
||||||
|
|
||||||
|
my $decoded = decode_json($json);
|
||||||
|
if (defined($decoded->{'system'}{'revision'})) {
|
||||||
|
# replace revision number with revision date
|
||||||
|
my $rev = $decoded->{'system'}{'revision'};
|
||||||
|
my $d = (split(/ /,qx(svn info -r $rev $fhemPathSvn|grep Date:)))[3];
|
||||||
|
my ($year,$mon,$mday) = split(/-/,$d);
|
||||||
|
$decoded->{'system'}{'revdate'} = mktime(0,0,7,$mday,($mon-1),($year-1900),0,0,0);
|
||||||
|
$json = encode_json $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
$sth = $dbh->prepare(q{INSERT OR REPLACE INTO jsonNodes(uniqueID,geo,json) VALUES(?,?,?)});
|
$sth = $dbh->prepare(q{INSERT OR REPLACE INTO jsonNodes(uniqueID,geo,json) VALUES(?,?,?)});
|
||||||
my $result = $sth->execute($uniqueID,$geo,$json);
|
my $result = $sth->execute($uniqueID,$geo,$json);
|
||||||
add2total() if $result;
|
add2total() if $result;
|
||||||
@ -147,7 +161,7 @@ sub doAggregate() {
|
|||||||
|
|
||||||
my $dbInfo = decode_json $dbInfo[3];
|
my $dbInfo = decode_json $dbInfo[3];
|
||||||
my $updated = $dbInfo[1];
|
my $updated = $dbInfo[1];
|
||||||
my $started = $dbInfo->{'submissionsSince'};
|
my $started = substr($dbInfo->{'submissionsSince'},0,10);
|
||||||
my $nodesTotal = $dbInfo->{'submissionsTotal'};
|
my $nodesTotal = $dbInfo->{'submissionsTotal'};
|
||||||
my $nodes12 = 0;
|
my $nodes12 = 0;
|
||||||
|
|
||||||
@ -172,13 +186,30 @@ sub doAggregate() {
|
|||||||
|
|
||||||
# process system data
|
# process system data
|
||||||
$decoded = decode_json( $line[1] );
|
$decoded = decode_json( $line[1] );
|
||||||
|
|
||||||
$res = $decoded->{'system'}{'os'};
|
$res = $decoded->{'system'}{'os'};
|
||||||
$countAll{'system'}{'os'}{$res}++;
|
$countAll{'system'}{'os'}{$res}++;
|
||||||
|
|
||||||
$res = $decoded->{'system'}{'perl'};
|
$res = $decoded->{'system'}{'perl'};
|
||||||
|
$res =~ s/^v//;
|
||||||
$countAll{'system'}{'perl'}{$res}++;
|
$countAll{'system'}{'perl'}{$res}++;
|
||||||
|
|
||||||
$res = $decoded->{'system'}{'release'};
|
$res = $decoded->{'system'}{'release'};
|
||||||
$countAll{'system'}{'release'}{$res}++;
|
$countAll{'system'}{'release'}{$res}++;
|
||||||
($res) = (undef);
|
|
||||||
|
if (defined($decoded->{'system'}{'revdate'})){
|
||||||
|
$res = $decoded->{'system'}{'revdate'};
|
||||||
|
my $age = sprintf("%.0f",(time - $res)/86400);
|
||||||
|
$countAll{'system'}{'age'}{'0'}++ if ($age <= 1);
|
||||||
|
$countAll{'system'}{'age'}{'7'}++ if ($age > 1 && $age <= 7);
|
||||||
|
$countAll{'system'}{'age'}{'30'}++ if ($age > 7 && $age <= 30);
|
||||||
|
$countAll{'system'}{'age'}{'180'}++ if ($age > 30 && $age <= 180);
|
||||||
|
$countAll{'system'}{'age'}{'365'}++ if ($age > 180);
|
||||||
|
} else {
|
||||||
|
$countAll{'system'}{'age'}{'unknown'}++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = undef;
|
||||||
|
|
||||||
# process modules and model data
|
# process modules and model data
|
||||||
my @keys = keys %{$decoded};
|
my @keys = keys %{$decoded};
|
||||||
@ -221,8 +252,7 @@ sub viewStatistics() {
|
|||||||
print $q->header( -type => "application/json",
|
print $q->header( -type => "application/json",
|
||||||
-Content_length => length($json)); # for gzip/deflate
|
-Content_length => length($json)); # for gzip/deflate
|
||||||
print $json;
|
print $json;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
print $q->redirect('statistics.html'); # redirect to HTML file
|
print $q->redirect('statistics.html'); # redirect to HTML file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user