1st stuff for federation stats in the admin panel

This commit is contained in:
Tobias Diekershoff 2015-11-17 11:34:47 +01:00
parent a0f3fe6fde
commit a4104d7c17
4 changed files with 120 additions and 9 deletions

View file

@ -121,15 +121,17 @@ function admin_content(&$a) {
/** /**
* Side bar links * Side bar links
*/ */
$aside = Array();
// array( url, name, extra css classes ) // array( url, name, extra css classes )
$aside = Array( // not part of $aside to make the template more adjustable
$asidesubpages = Array(
'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"), 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"), 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"), 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"),
'queue' => Array($a->get_baseurl(true)."/admin/queue/", t('Inspect Queue'), "queue"), 'queue' => Array($a->get_baseurl(true)."/admin/queue/", t('Inspect Queue'), "queue"),
'federation' => Array($a->get_baseurl(true)."/admin/federation/", t('Federation Statistics'), "federation"),
//'update' => Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update") //'update' => Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update")
); );
@ -151,6 +153,7 @@ function admin_content(&$a) {
$t = get_markup_template("admin_aside.tpl"); $t = get_markup_template("admin_aside.tpl");
$a->page['aside'] .= replace_macros( $t, array( $a->page['aside'] .= replace_macros( $t, array(
'$admin' => $aside, '$admin' => $aside,
'$subpages' => $asidesubpages,
'$admtxt' => t('Admin'), '$admtxt' => t('Admin'),
'$plugadmtxt' => t('Plugin Features'), '$plugadmtxt' => t('Plugin Features'),
'$logtxt' => t('Logs'), '$logtxt' => t('Logs'),
@ -192,6 +195,9 @@ function admin_content(&$a) {
case 'queue': case 'queue':
$o = admin_page_queue($a); $o = admin_page_queue($a);
break; break;
case 'federation':
$o = admin_page_federation($a);
break;
default: default:
notice( t("Item not found.") ); notice( t("Item not found.") );
} }
@ -208,6 +214,47 @@ function admin_content(&$a) {
} }
} }
/**
* Admin Federation Stats Page; display some numbers from gserver
* @param App $a
* returning string
*/
function admin_page_federation(&$a) {
// get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
// social and statusnet nodes this node is knowing
//
// We are looking for the following platforms in the DB, "Red" should find
// all variants of that platform ID string as the q() function is stripping
// off one % two of them are needed in the query
$platforms = array('Diaspora', 'Friendica', '%%red%%', 'Hubzilla', 'GNU Social', 'StatusNet');
$counts = array();
foreach ($platforms as $p) {
// get a totaö count for the platform, the name and version of the
// highest version and the protocol tpe
$c = q('select count(*), platform, network, version from gserver where platform like "'.$p.'" and last_contact > last_failure order by version asc;');
// what versions for that platform do we know at all?
// again only the active nodes
$v = q('select count(*), version from gserver where last_contact > last_failure and platform like "'.$p.'" group by version order by version;');
// the 3rd array item is needed for the JavaScript graphs as JS does
// not like some characters in the names of variables...
$counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p));
}
// some helpful text
$intro = t('This page offers you some numbers to the known part of the federated social network your Friendica node is part of. These numbers are not complete but only reflect the part of the network your node is aware of.');
$hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
// load the template, replace the macros and return the page content
$t = get_markup_template("admin_federation.tpl");
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Federation Statistics'),
'$intro' => $intro,
'$hint' => $hint,
'$autoactive' => get_config('system', 'poco_completion'),
'$counts' => $counts,
'$version' => FRIENDICA_VERSION,
'$legendtext' => t('Currently this node is aware of nodes from the following platforms:'),
));
}
/** /**
* Admin Inspect Queue Page * Admin Inspect Queue Page
* @param App $a * @param App $a

View file

@ -276,9 +276,15 @@ a {
#poke-recip-label, #poke-action-label, #prvmail-message-label { #poke-recip-label, #poke-action-label, #prvmail-message-label {
margin: 10px 0 10px; margin: 10px 0 10px;
} }
.version-match {
font-weight: bold;
color: #00a700;
}
ul.federation-stats,
ul.credits { ul.credits {
list-style: none; list-style: none;
} }
ul.federation-stats li,
ul.credits li { ul.credits li {
float: left; float: left;
width: 240px; width: 240px;

View file

@ -10,14 +10,12 @@
}); });
}); });
</script> </script>
<h4><a href="{{$admurl}}">{{$admtxt}}</a></h4> <h4><a href="{{$admurl}}">{{$admtxt}}</a></h4>
<ul class='admin linklist'> <ul class='admin linklist'>
<li class='admin link button {{$admin.site.2}}'><a href='{{$admin.site.0}}'>{{$admin.site.1}}</a></li> {{foreach $subpages as $page}}
<li class='admin link button {{$admin.users.2}}'><a href='{{$admin.users.0}}'>{{$admin.users.1}}</a><span id='pending-update' title='{{$h_pending}}'></span></li> <li class='admin link button {{$page.2}}'><a href='{{$page.0}}'>{{$page.1}}</a></li>
<li class='admin link button {{$admin.plugins.2}}'><a href='{{$admin.plugins.0}}'>{{$admin.plugins.1}}</a></li> {{/foreach}}
<li class='admin link button {{$admin.themes.2}}'><a href='{{$admin.themes.0}}'>{{$admin.themes.1}}</a></li>
<li class='admin link button {{$admin.dbsync.2}}'><a href='{{$admin.dbsync.0}}'>{{$admin.dbsync.1}}</a></li>
<li class='admin link button {{$admin.queue.2}}'><a href='{{$admin.queue.0}}'>{{$admin.queue.1}}</a></li>
</ul> </ul>
{{if $admin.update}} {{if $admin.update}}

View file

@ -0,0 +1,60 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<canvas id="FederationChart" style="width: 400px; height: 400px; float: right; margin: 20px;"></canvas>
<div id="adminpage">
<h1>{{$title}} - {{$page}}</h1>
<p>{{$intro}}</p>
{{if not $autoactive}}
<p class="error-message">{{$hint}}</p>
{{/if}}
<p>{{$legendtext}}
<ul>
{{foreach $counts as $c}}
<li>{{$c[0]['platform']}} ({{$c[0]['count(*)']}})</li>
{{/foreach}}
</ul>
</p>
</div>
<script>
var FedData = [
{{foreach $counts as $c}}
{ value: {{$c[0]['count(*)']}}, label: "{{$c[0]['platform']}}", color: "#90EE90", highlight: "#EE90A1", },
{{/foreach}}
];
var ctx = document.getElementById("FederationChart").getContext("2d");
var myDoughnutChart = new Chart(ctx).Doughnut(FedData,
{
animateRotate : false,
});
document.getElementById('FederationLegend').innerHTML = myDoughnutChart.generateLegend();
</script>
<table style="width: 100%">
{{foreach $counts as $c}}
<tr>
<th>{{$c[0]['platform']}}</th>
<th><strong>{{$c[0]['count(*)']}}</strong></td>
<td>{{$c[0]['network']}}</td>
</tr>
<tr>
<td colspan="3" style="border-bottom: 1px solid #000;">
<canvas id="{{$c[2]}}Chart" style="width: 240px; height: 240px; float: left;
margin: 20px;"></canvas>
<script>
var {{$c[2]}}data = [
{{foreach $c[1] as $v}}
{ value: {{$v['count(*)']}}, label: '{{$v['version']}}', color: "#90EE90", highlight: "#EE90A1",},
{{/foreach}}
];
var ctx = document.getElementById("{{$c[2]}}Chart").getContext("2d");
var my{{$c[2]}}DoughnutChart = new Chart(ctx).Doughnut({{$c[2]}}data,
{animateRotate : false,});
</script>
<ul class="federation-stats">
{{foreach $c[1] as $v}}
<li>{{if ($c[0]['platform']==='Friendica' and $version===$v['version']) }}<span class="version-match">{{$v['version']}}</span>{{else}}{{$v['version']}}{{/if}} ({{$v['count(*)']}})</li>
{{/foreach}}
</ul>
</td>
</tr>
{{/foreach}}
</table>