Skip to content

Commit

Permalink
Add optional plugin to report analytics data
Browse files Browse the repository at this point in the history
  • Loading branch information
mherger committed Apr 11, 2024
1 parent 31c0ee7 commit 94e0f6f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changelog8.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h2><a name="v8.5.1" id="v8.5.1"></a>Version 8.5.1</h2>

<li>New Features:</li>
<ul>
<li></li>
<li>Add optional plugin to report data about your LMS installation - see <a href="https://forums.slimdevices.com/forum/user-forums/general-discussion/1697108">forum discussion</a>.</li>
</ul>
<br />

Expand Down
80 changes: 80 additions & 0 deletions Slim/Plugin/Stats/Plugin.pm
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;
16 changes: 16 additions & 0 deletions Slim/Plugin/Stats/install.xml
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>
7 changes: 7 additions & 0 deletions Slim/Plugin/Stats/strings.txt
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!

0 comments on commit 94e0f6f

Please sign in to comment.