Extension:Metrics
|
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 |
| Last version | 0.1 (4/4/2008) |
| MediaWiki | Tested on 1.11.0 |
| License | No license specified |
| Download | see Installation |
|
Check usage (experimental) |
|
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 |
[edit] Installation
- Create a directory called Metrics in your extensions directory
- Download the following files into the Metrics directory:
- 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) );
[edit] Changes to LocalSettings.php
require_once("$IP/extensions/Metrics/SpecialMetrics.php");
[edit] Creating your metrics
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
[edit] To Do
- I'd like to add graphing support
[edit] Sites using this extension
Please add your site (and a link if it is public) to the list! Thanks!
- Key National Finance WiKey (internal intranet)
