Open main menu

Extension:Metrics

MediaWiki extensions manual
OOjs UI icon advanced.svg
Special:Metrics
Release status: stable
Implementation Special page
Description Adds a special page to display predefined metrics / statistics
Author(s) Chris Reigrut, Key Bank / Key Equipment Finance
Latest version 0.1 (2008-04-04)
MediaWiki Tested on 1.11.0
License No license specified
Download see Installation
Translate the Metrics extension if it is available at translatewiki.net
Check usage and version matrix.

This extension displays metrics that have been predefined. Basically, we needed the ability to keep track of daily statistics about our wiki, and we wanted as much flexibility as possible.

The special page displays all of the metric names, and allows you to select one (or more) of them, as well as a date range, and then displays the output in a sortable table.

Contents

InstallationEdit

  1. Create a directory called Metrics in your extensions directory
  2. Download the following files into the Metrics directory:
    1. SpecialMetrics.php
    2. SpecialMetrics.i18n.php
  3. Create the table to hold the metrics data:
create table metric (
metric_date DATE NOT NULL,
metric_name VARCHAR(255) NOT NULL,
metric_value DOUBLE NOT NULL,
PRIMARY KEY (metric_date, metric_name),
INDEX (metric_name)
);

Changes to LocalSettings.phpEdit

require_once("$IP/extensions/Metrics/SpecialMetrics.php");

Creating your metricsEdit

The simplest way to create your metrics is to create a SQL file like the following in your extensions/Metrics directory. We call ours metrics.sql.

use wiki;

/*****************************************************************************/
/**                          NIGHTLY METRICS                                **/
/*****************************************************************************/

insert into metric (
select CURRENT_DATE(), 'Pages in Main namespace', count(*)
from page
where page_is_redirect = 0 
and page_namespace=0
);

insert into metric (
select CURRENT_DATE(), 'Talk pages in Main namespace', count(*)
from page
where page_is_redirect = 0 
and page_namespace=1
);

insert into metric (
select CURRENT_DATE(), 'Pages in Main namespace updated in last 30 days', count(*)
from page, revision
where rev_page = page_id
and rev_id = page_latest
and page_is_redirect = 0 
and page_namespace=0
and DATEDIFF(CURRENT_DATE(), rev_timestamp) < 31
);

insert into metric (
select CURRENT_DATE(), 'Links on pages in Main namespace', count(*)
from page, pagelinks
where pl_from = page_id
and page_is_redirect = 0 
and page_namespace=0
);

insert into metric (
select CURRENT_DATE(), 'Pages in User namespace', count(*)
from page
where page_is_redirect = 0
and page_namespace=2
);

insert into metric (
select CURRENT_DATE(), 'Talk pages in User namespace', count(*)
from page
where page_is_redirect = 0
and page_namespace=3
);


insert into metric (
select CURRENT_DATE(), 'Personal pages', count(*)
from page, revision, text
where rev_page = page_id
and rev_id = page_latest
and rev_text_id = old_id
and page_namespace = 2
and page_is_redirect = 0
and not (page_title like '%/%')
and not (page_title = 'Sample')
);

insert into metric (
select CURRENT_DATE(), 'Pages updated today', count(*)
from page, revision
where rev_page = page_id
and rev_id = page_latest
and page_is_redirect = 0 
and DATEDIFF(CURRENT_DATE(), rev_timestamp) = 0
);

/*****************************************************************************/
/**                      NIGHTLY DERIVED METRICS                            **/
/*****************************************************************************/

insert into metric (
select l.metric_date, 'Average number of links per page in Main namespace', l.metric_value / p.metric_value
from metric l, metric p
where l.metric_date = CURRENT_DATE()
and l.metric_date = p.metric_date
and l.metric_name = 'Links on pages in Main namespace'
and p.metric_name = 'Pages in Main namespace'
);

Then you simply need to execute your SQL on a periodic basis. We use crontab to run the file

0 21 * * * mysql -h DBSERVERNAME -P 3306 -u WIKIUSERID -pWIKIPASSWORD < /wiki/extensions/Metrics/metrics.sql

To DoEdit

  • I'd like to add graphing support

Sites using this extensionEdit

Please add your site (and a link if it is public) to the list! Thanks!

  • Key National Finance WiKey (internal intranet)