-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional plugin to report analytics data
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package Slim::Plugin::Stats::Plugin; | ||
|
||
use strict; | ||
|
||
use Config; | ||
use Digest::SHA1 qw(sha1_base64); | ||
use JSON::XS::VersionOneAndTwo; | ||
|
||
use base qw(Slim::Plugin::Base); | ||
use Slim::Utils::Log; | ||
use Slim::Utils::Prefs; | ||
|
||
use constant REPORT_URL => 'https://stats.lms-community.org/api/instance/%s/'; | ||
use constant REPORT_DELAY => 2.40; | ||
use constant REPORT_INTERVAL => 86400 * 7; | ||
|
||
my $serverPrefs = preferences('server'); | ||
|
||
my $log = Slim::Utils::Log->addLogCategory({ | ||
'category' => 'plugin.stats', | ||
'defaultLevel' => 'WARN', | ||
'description' => __PACKAGE__->getDisplayName(), | ||
}); | ||
|
||
my $id; | ||
|
||
sub initPlugin { | ||
$id ||= sha1_base64(preferences('server')->get('server_uuid')); | ||
|
||
Slim::Utils::Timers::setTimer($id, time() + REPORT_DELAY, \&_reportStats); | ||
} | ||
|
||
sub _reportStats { | ||
Slim::Utils::Timers::killTimers($id, \&_reportStats); | ||
|
||
my $osDetails = Slim::Utils::OSDetect::details(); | ||
my $plugins = [ sort map { /^(?:Slim::Plugin|Plugins)::(.*)::/; $1 } grep { $_ ne __PACKAGE__ }Slim::Utils::PluginManager->enabledPlugins() ]; | ||
my $totals = Slim::Schema->totals(); | ||
|
||
my $data = { | ||
version => $::VERSION, | ||
os => $osDetails->{'osName'}, | ||
platform => $osDetails->{'osArch'}, | ||
perl => $Config{'version'}, | ||
players => scalar (Slim::Player::Client::clients() || ()) || 0, | ||
plugins => $plugins, | ||
skin => $serverPrefs->get('skin'), | ||
tracks => $totals->{track}, | ||
}; | ||
|
||
main::INFOLOG && $log->is_info && $log->info("Reporting system stats"); | ||
# we MUST clone the data, as Data::Dump::dump would convert numbers to strings... | ||
main::DEBUGLOG && $log->is_debug && $log->debug("$id: ", Data::Dump::dump(Storable::dclone($data))); | ||
|
||
Slim::Networking::SimpleAsyncHTTP->new( | ||
sub { | ||
main::INFOLOG && $log->is_info && $log->info("Successfully reported stats"); | ||
_scheduleReport(); | ||
}, | ||
sub { | ||
my ($http, $error) = @_; | ||
$log->error("Failed to report stats: $error"); | ||
_scheduleReport(); | ||
}, | ||
{ | ||
timeout => 5, | ||
}, | ||
)->post( | ||
sprintf(REPORT_URL, $id), | ||
'x-lms-id' => $id, | ||
'Content-Type' => 'application/json', | ||
to_json($data), | ||
); | ||
} | ||
|
||
sub _scheduleReport { | ||
Slim::Utils::Timers::setTimer($id, time() + REPORT_INTERVAL, \&_reportStats); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<extension> | ||
<id>1189afb0-bd15-43dd-b137-09e24d855bf6</id> | ||
<name>PLUGIN_STATS_MODULE_NAME</name> | ||
<module>Slim::Plugin::Stats::Plugin</module> | ||
<version>1.1</version> | ||
<description>PLUGIN_STATS_MODULE_DESC</description> | ||
<creator>Lyrion Community, Michael Herger</creator> | ||
<defaultState>disabled</defaultState> | ||
<type>2</type> | ||
<targetApplication> | ||
<id>Lyrion Music Server</id> | ||
<minVersion>8.4</minVersion> | ||
<maxVersion>*</maxVersion> | ||
</targetApplication> | ||
</extension> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
PLUGIN_STATS_MODULE_NAME | ||
DE Analytikdaten teilen | ||
EN Report Analytics Data | ||
|
||
PLUGIN_STATS_MODULE_DESC | ||
DE Teile Analytikdaten wie Serverversion, Anzahl Geräte, Anzahl Titel, installierte Plugins, Betriebssystem, Perlversion, verwendeter Skin und die verwendete Hardware mit der LMS Community. Dies hilft uns, Prioritäten in der Entwicklung richtig zu setzen. Vielen Dank fürs Vertrauen! | ||
EN Share your server version, number of players, number of tracks, installed plugins, operating system, Perl version, skin used, and the hardware platform with the LMS Community. This will help us prioritize further development. Thanks for enabling this plugin! |