Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / wiki / mediawiki_api @ 91ad0c21

Historique | Voir | Annoter | Télécharger (2,7 ko)

1 91ad0c21 Erkan
#!/usr/bin/php
2
3
<?php
4
5
#######################################################################
6
#API URL
7
#http://localhost/mediawiki/api.php?action=query&meta=siteinfo&siprop=statistics&format=json
8
9
#JSON OUTPUT
10
#{"query":{"statistics":{"pages":1695,"articles":42,"views":91812,"edits":2958,"images":170,"users":25,"activeusers":6,"admins":1,"jobs":0}}}
11
12
#USAGE
13
#ln -s /usr/share/munin/plugins/mediawiki /etc/munin/plugins/mediawiki_views
14
#######################################################################
15
16
$server = "http://localhost/mediawiki";
17
$wikiname = "Wiki";
18
//$suffix = "views";
19
20
$basename = preg_replace( '/^.+[\\\\\\/]/', '', $_SERVER['PHP_SELF'] );
21
$suffix = explode("_",$basename);
22
$suffix = $suffix[1];
23
24
$param = "";
25
if(sizeof($argv)>1)
26
  $param = $argv[1];
27
28
switch ($param) {
29
case "config":
30
31
print <<<CONFIG
32
graph_title $wikiname $suffix
33
graph_vlabel number
34
graph_category wiki
35
graph_scale no
36
graph_info Reads the total number of $suffix from $wikiname\n
37
CONFIG;
38
39
switch ($suffix) {
40
41
case "views":
42
print <<<VIEWS
43
views.info Total number of page views
44
views.label views
45
views.type COUNTER\n
46
VIEWS;
47
break;
48
49
case "edits":
50
print <<<EDITS
51
edits.info Total number of page edits
52
edits.label edits
53
edits.type COUNTER\n
54
EDITS;
55
break;
56
57
case "articles":
58
print <<<ARTICLES
59
articles.info Total number of 'good' pages (articles)
60
articles.label articles
61
articles.type GAUGE\n
62
ARTICLES;
63
break;
64
65
case "pages":
66
print <<<PAGES
67
pages.info Total number of all pages
68
pages.label pages
69
pages.type GAUGE\n
70
PAGES;
71
break;
72
73
case "users":
74
print <<<USERS
75
users.info Total number of user accounts
76
users.label users
77
users.type GAUGE\n
78
USERS;
79
break;
80
81
case "images":
82
print <<<IMAGES
83
images.info Total number of uploaded images
84
images.label images
85
images.type GAUGE\n
86
IMAGES;
87
break;
88
89
case "admins":
90
print <<<ADMINS
91
admins.info Total number of admins (sysops)
92
admins.label admins
93
admins.type GAUGE\n
94
ADMINS;
95
break;
96
97
default:
98
print <<<ERROR
99
Error: link me as mediawiki_<type>, where type can be one of: views, edits, articles, pages, users, images or admins.\n
100
ERROR;
101
}
102
103
}
104
105
106
$s = file_get_contents($server."/api.php?action=query&meta=siteinfo&siprop=statistics&format=json");
107
$json = json_decode($s);
108
$value = $json->{'query'}->{'statistics'}->{$suffix};
109
110
switch ($suffix) {
111
112
case "views":
113
print "views.value $value\n";
114
break;
115
116
case "edits":
117
print "edits.value $value\n";
118
break;
119
120
case "articles":
121
print "articles.value $value\n";
122
break;
123
124
case "pages":
125
print "pages.value $value\n";
126
break;
127
128
case "users":
129
print "users.value $value\n";
130
break;
131
132
case "images":
133
print "images.value $value\n";
134
break;
135
136
case "admins":
137
print "admins.value $admins\n";
138
139
default:
140
print "link me as mediawiki_<type>, where type can be one of: views, edits, articles, pages, users, images or admins. \n";
141
}
142
143
?>