blob: dd98b0809ee5d5bc0f301f26074cfc2ef2632ff9 [file] [log] [blame]
<%
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
include("monitoring-authentication.jag");
(function () {
var log = new Log();
var TIME_INTERVAL_1 = '30 Min';
var TIME_INTERVAL_2 = '1 Hour';
var TIME_INTERVAL_3 = '1 Day';
var TIME_INTERVAL_4 = '1 Week';
var TIME_INTERVAL_5 = '1 Month';
var content = request.getContent();
var contentAsString = null;
if (content != '' && content != null) {
contentAsString = stringify(content);
if (log.isDebugEnabled()) {
log.debug("Value of content: " + contentAsString);
}
}
var db = new Database("WSO2_ANALYTICS_EVENT_STORE_DB");
try {
var result;
var timeInterval = request.getParameter("time");
var interval = 1800;
var x_axis_interval;
var time_format;
if (timeInterval === TIME_INTERVAL_1) {
interval = 1800;
x_axis_interval = 60;
time_format = 'hh24:mi';
} else if (timeInterval === TIME_INTERVAL_2) {
interval = 3600;
x_axis_interval = 120;
time_format = 'hh24:mi';
} else if (timeInterval === TIME_INTERVAL_3) {
interval = 86400;
x_axis_interval = 2880;
time_format = 'yyyy-mm-dd hh24:mi';
} else if (timeInterval === TIME_INTERVAL_4) {
interval = 604800;
x_axis_interval = 20160;
time_format = 'yyyy-mm-dd hh24:mi';
} else if (timeInterval === TIME_INTERVAL_5) {
interval = 2419200;
x_axis_interval = 80640;
time_format = 'yyyy-mm-dd';
}
var clusterId = request.getParameter("clusterId");
result = db.query("SELECT TO_CHAR((TIMESTAMP '1970-01-01 00:00:00' AT TIME ZONE 'UTC' + NUMTODSINTERVAL(CEIL" +
"(Time/(" + x_axis_interval + " * 1000)) * " + x_axis_interval + ", 'second')) AT LOCAL, '" +
time_format + "') \"Time\", AVG(Count) AS \"Count\" FROM AVG_IN_FLIGHT_REQUESTS WHERE ClusterId=? AND" +
" TO_CHAR((TIMESTAMP '1970-01-01 00:00:00' AT TIME ZONE 'UTC' + NUMTODSINTERVAL(Time/1000,'second')) " +
"AT LOCAL, 'yyyy-mm-dd hh24:mi') BETWEEN TO_CHAR(LOCALTIMESTAMP - NUMTODSINTERVAL(" + interval + ", " +
"'second'),'yyyy-mm-dd hh24:mi') AND TO_CHAR(LOCALTIMESTAMP,'yyyy-mm-dd hh24:mi') GROUP BY TO_CHAR(" +
"(TIMESTAMP '1970-01-01 00:00:00' AT TIME ZONE 'UTC' + NUMTODSINTERVAL(CEIL(Time/(" + x_axis_interval
+ " * 1000)) * " + x_axis_interval + ", 'second')) AT LOCAL, '" + time_format + "'), ClusterId ORDER " +
"BY TO_CHAR((TIMESTAMP '1970-01-01 00:00:00' AT TIME ZONE 'UTC' + NUMTODSINTERVAL(CEIL(Time/(" +
x_axis_interval + " * 1000)) * " + x_axis_interval + ", 'second')) AT LOCAL, '" + time_format + "')",
clusterId);
print(result);
}
catch (e) {
print(e.toString());
}
finally {
db.close();
}
}());
%>