-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.jag
69 lines (56 loc) · 1.9 KB
/
db.jag
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
<%
var db = new Database("AS_MONITORING_DATASOURCE");
// execute a given SQL
function executeQuery(sql){
return db.query(sql);
}
// get list of nodes reporting stats to the monitoring system
function getAllNodes(){
var nodes = executeQuery("SELECT DISTINCT serverName AS node FROM REQUESTS_SUMMARY_PER_MINUTE;");
return nodes;
}
var action = request.getParameter("action");
// build the where clause of the sql based on start_time, end_time and node values
function buildWhere(){
var startTime = request.getParameter("start_time");
var endTime = request.getParameter("end_time");
var node = request.getParameter("node");
if(startTime == null && endTime == null && node == null){
return "";
}
var where = ""
if(startTime != null){
where = appendCondition(where, "time >= \"" + startTime + "\"");
}
if(endTime != null){
where = appendCondition(where, "time <= \"" + endTime + "\"");
}
if(node != null){
where = appendCondition(where, "serverName = \""+ node + "\"");
}
return where;
}
function appendCondition(where, condition){
if(where == ""){
where = " WHERE ";
}else{
where = where + " AND ";
}
return where + condition;
}
//send the requested data based on the action and the conditions provided
if(action == "node_list"){
print(getAllNodes());
}else if(action == "webapp_list"){
var where = buildWhere();
var sql = "SELECT sum(averageRequestCount) as total_requests\
, max(averageRequestCount) as max_request, min(averageRequestCount) as min_request\
, avg(averageRequestCount) as avg_request, max(averageResponseTime) as max_response\
, min(averageResponseTime) as min_response, avg(averageResponseTime) as avg_response\
, sum(sessionCount) as total_session, avg(sessionCount) as avg_session\
, sum(httpSuccessCount) as total_success, sum(httpErrorCount) as total_error \
FROM REQUESTS_SUMMARY_PER_MINUTE " + where + ";";
var results = executeQuery(sql);
print(results);
}
%>