My favorites | Sign in
Project Home
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php

/*! @ingroup WsFramework Framework for the Web Services */
//@{

/*! @brief Broadcast structWSF querying statistics

@details This script is used to create XML statistic files of a structWSF instance. It can be useful to monitor
the usage of the instance. Such statistics can be used to plan future scalability deployment
plans, or simply to make sure that everything is working normally. Additionally, it can be used
in conjonction with software systems such as Ganglia to monitor WS response errors in a global
system monitoring infrastructure.

Additionally, you can use this script to participate to the Global structWSF Statistical Service.
To be part of the global structWSF statistics, you only have to subscribe your structWSF network
at this address:

http://openstructs.org/structwsf/stats/subscribe

You only have to put the URL where this script can be queried, and your stats will be automatically
aggregated with stats of other structWSF networks.

If you want to use that script for any reason, you have to set the value of the
$enableStatisticsBroadcast variable to TRUE.

Note: eventually this script will be created as a Statistics & Monitoring web service endpoint.
That way, structWSF system administrators will be able to manage it like any other web services,
and leverage the structWSF permissions.

\n\n

@author Frederick Giasson, Structured Dynamics LLC.
\n\n\n
*/


/*
Set this variable to TRUE is you want to make your statistics available publicly.
If this variable is set to TRUE, it means that anybody will be able to get statistics
of your structWSF instance by query the script at this address:

http://[your-web-site]/ws/statisticsBroker.php

If you don't want to, you can simply remove this file from your web server.
*/
$enableStatisticsBroadcast = FALSE;


if($enableStatisticsBroadcast)
{
include_once("framework/WebService.php");
include_once("framework/db.php");

$data_ini = parse_ini_file(WebService::$data_ini . "data.ini", TRUE);

$db = new DB_Virtuoso($data_ini["triplestore"]["username"], $data_ini["triplestore"]["password"],
$data_ini["triplestore"]["dsn"], $data_ini["triplestore"]["host"]);


$sparql = " select count(?record) as ?nb_records
from <".$data_ini["datasets"]["wsf_graph"]."datasets/>
where
{
?dataset a <http://rdfs.org/ns/void#Dataset>.
graph ?dataset
{
?record a ?type.
}
}";


$resultset = @$db->query($db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $sparql), array(), FALSE));

$nbRecords = "0";
if(!odbc_error())
{
$nbRecords = odbc_result($resultset, 1);
}

$sparql = " select count(?dataset) as ?nb_datasets
from <".$data_ini["datasets"]["wsf_graph"]."datasets/>
where
{
?dataset a <http://rdfs.org/ns/void#Dataset>.
}";


$resultset = @$db->query($db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $sparql), array(), FALSE));

$nbDatasets = "0";
if(!odbc_error())
{
$nbDatasets = odbc_result($resultset, 1);
}

$sparql = " select count(?o) as ?nb_triples
from <".$data_ini["datasets"]["wsf_graph"]."datasets/>
where
{
?dataset a <http://rdfs.org/ns/void#Dataset>.
graph ?dataset
{
?record ?p ?o.
}
}";


$resultset = @$db->query($db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $sparql), array(), FALSE));

$nbTriples = "0";
if(!odbc_error())
{
$nbTriples = odbc_result($resultset, 1);
}



$statisticsXML = "<statistics>\n";

$statisticsXML .= " <datasets nb=\"$nbDatasets\" nbTriples=\"$nbTriples\" nbRecords=\"$nbRecords\" />\n";



$statisticsXML .= " <webservices>\n";

$resultset = @$db->query("select distinct requested_web_service from ".$data_ini["triplestore"]["log_table"]);

$webservices = array();

if(!odbc_error())
{
while(odbc_fetch_row($resultset))
{
array_push($webservices, odbc_result($resultset, 1));
}
}

foreach($webservices as $ws)
{
$resultset = @$db->query("select count(*) from ".$data_ini["triplestore"]["log_table"]." where requested_web_service = '$ws'");

$nbQueries = "0";
if(!odbc_error())
{
$nbQueries = odbc_result($resultset, 1);
}


$resultset = @$db->query("select avg(request_processing_time) as average from ".$data_ini["triplestore"]["log_table"]." where
requested_web_service = '$ws'");

$averageTime = "0";
if(!odbc_error())
{
$averageTime = odbc_result($resultset, 1);
}

$statisticsXML .= " <".str_replace("/", "_", $ws)." nbQueries=\"$nbQueries\" averageTimePerQuery=\"$averageTime\">\n";

$statisticsXML .= " <httpMessages>\n";

$resultset = @$db->query("select distinct request_http_response_status, count(request_http_response_status) as nb
from ".$data_ini["triplestore"]["log_table"]." where requested_web_service = '$ws'
group by request_http_response_status");

if(!odbc_error())
{
while(odbc_fetch_row($resultset))
{
$statisticsXML .= " <msg type=\"".odbc_result($resultset, 1)."\" count=\"".odbc_result($resultset, 2).
"\" />\n";
}
}

$statisticsXML .= " </httpMessages>\n";


$statisticsXML .= " <requestedMimes>\n";

$resultset = @$db->query("select distinct requested_mime, count(requested_mime) as nb from ".$data_ini["triplestore"]["log_table"]." ".
"where requested_web_service = '$ws' group by requested_mime");

if(!odbc_error())
{
while(odbc_fetch_row($resultset))
{
$statisticsXML .= " <mime type=\"".odbc_result($resultset, 1)."\" count=\"".odbc_result($resultset, 2).
"\" />\n";
}
}

$statisticsXML .= " </requestedMimes>\n";


$statisticsXML .= " </".str_replace("/", "_", $ws).">\n";
}

$statisticsXML .= " </webservices>\n";



$statisticsXML .= "</statistics>\n";

header("Content-Type: text/xml; charset=utf-8");

echo $statisticsXML;
}


//@}
?>

Change log

r43 by f...@fgiasson.com on Apr 19, 2010   Diff
Creation of a new "triplestore->log_table"
setting to be able to log usage of
multiple structWSF instances on the same
server.
Go to: 
Project members, sign in to write a code review

Older revisions

r36 by f...@fgiasson.com on Apr 8, 2010   Diff
This script is used to create XML
statistic files of a structWSF
instance. It can be useful to monitor
the usage of the instance. Such
statistics can be used to plan future
...
All revisions of this file

File info

Size: 7310 bytes, 211 lines
Powered by Google Project Hosting