blob: fa868e28dc9207950df8f90d621272a7d33bf75d [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 ALL_CLUSTERS = 'All Clusters';
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 time_format = 'yyyy-mm-dd hh24:mi';
if (timeInterval === TIME_INTERVAL_1) {
interval = 1800;
} else if (timeInterval === TIME_INTERVAL_2) {
interval = 3600;
} else if (timeInterval === TIME_INTERVAL_3) {
interval = 86400;
} else if (timeInterval === TIME_INTERVAL_4) {
interval = 604800;
} else if (timeInterval === TIME_INTERVAL_5) {
interval = 2419200;
}
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/1000), 'second')) AT LOCAL, '" + time_format + "') AS \"Time\", ClusterId \"ClusterId\", " +
"MinInstanceCount \"MinInstanceCount\", MaxInstanceCount \"MaxInstanceCount\", RIFPredicted " +
"\"RIFPredicted\", RIFThreshold \"RIFThreshold\", RIFRequiredInstances \"RIFRequiredInstances\", " +
"MCPredicted \"MCPredicted\", MCThreshold \"MCThreshold\", MCRequiredInstances " +
"\"MCRequiredInstances\", LAPredicted \"LAPredicted\", LAThreshold \"LAThreshold\", " +
"LARequiredInstances \"LARequiredInstances\", RequiredInstanceCount \"RequiredInstanceCount\", " +
"ActiveInstanceCount \"ActiveInstanceCount\", AdditionalInstanceCount \"AdditionalInstanceCount\", " +
"ScalingReason \"ScalingReason\" FROM SCALING_DETAILS 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') ORDER BY TO_CHAR((TIMESTAMP " +
"'1970-01-01 00:00:00' AT TIME ZONE 'UTC' + NUMTODSINTERVAL(CEIL(Time/1000), 'second')) AT LOCAL, '"
+ time_format + "')", clusterId);
print(result);
}
catch (e) {
print(e.toString());
}
finally {
db.close();
}
}());
%>