IoT DAS Frameworks - IT Infra Monitoring and Analytics/IOT_Applications/Performance_Dashboard_Application(Reference App)/source/SA-DashBoard/src/java/com/dashboard/linechart/moving/DynamicChart.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Statement st;
        ResultSet rs;
        PropertyUtil propertyUtil = null;
        try {
            propertyUtil = new PropertyUtil();
            String maxTimeStamp = "";
            String host = request.getParameter("HostName");
            String resourceId = request.getParameter("ResourceId");
            String metricslistfromjs = request.getParameter("MetricsList");
            String[] metricslistSplit = metricslistfromjs.split(",");
            String metricslist = "";
            for (int i = 0; i < metricslistSplit.length; i++) {
                metricslist = metricslist + ",\'" + propertyUtil.getreverseMapping_Properties().get(metricslistSplit[i]) + "\'";
                if (maxTimeStamp.equals("")) {
                    String szExecuteQuery = "select max(timestamp1) as timestamp from servicemetrics where metrictype in ('" 
                            + propertyUtil.getreverseMapping_Properties().get(metricslistSplit[i]) + "\'" + ") and host = '" + host 
                            + "' and resourceid = '" + resourceId + "'";
                    maxTimeStamp = getMaxTimestampOfMetrictype(szExecuteQuery, request);
                }
            }
            String metricNames_array = "";
            String metricValue_array = "";
            String timestamp_array = "";

            st = ConnectionDAO.getConnection(request.getServerName()).createStatement();
            /*String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1) at time zone " 
                    + DBUtilHelper.getMetrics_mapping_properties().getProperty("ServerTimeZone_timestamp") + ",'HH24:mi:SS') as timestamp from "
                    + "servicemetrics where metrictype in (" + metricslist.substring(1) + ") and host = '" + host + "' and resourceid='" + resourceId 
                    + "' and timestamp1 = " + maxTimeStamp;*/
            String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1),'HH24:mi:SS') "
                    + "as timestamp from servicemetrics where metrictype in (" + metricslist.substring(1) + ") and host = '" + host + "' and resourceid='" 
                    + resourceId + "' and timestamp1 = " + maxTimeStamp;
            rs = st.executeQuery(szQuery);
            System.out.println(szQuery);
            String jsonResult = "[";
            while (rs.next()) {

                metricNames_array += "\"" + rs.getString("metrictype") + "\",";
                metricValue_array += rs.getString("metricvalue") + ",";
                timestamp_array = "\"" + rs.getString("timestamp") + "\"";
            }
            if (metricNames_array != "") {
                jsonResult = jsonResult + "{\"MetricValue\":[" + metricValue_array.substring(0, (metricValue_array.length() - 1)) + "],\"timestamp\":[" + timestamp_array + "],\"MetricName\":[" + metricNames_array.substring(0, (metricNames_array.length() - 1)) + "]}";
                jsonResult = jsonResult + "]";
            } else {
                jsonResult = "[{}]";
            }
            System.out.println("Json ==  = " + jsonResult);
            PrintWriter pw = response.getWriter();
            response.setContentType("text/html");
            pw.write(jsonResult);
            propertyUtil = null;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
/**
     * ******************************************************************************
     * This method is used to get Json for generating live linechart
     *
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return jsonResult for generating Live LineChart
     * *******************************************************************************
     */
This method is used to get Json for generating live linechart

@param request HttpServletRequest
@param response HttpServletResponse
@return jsonResult for generating Live LineChart
This method is used to get Json for generating live linechart @param request HttpServletRequest @param response HttpServletResponse @return jsonResult for generating Live LineChart
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Statement st;
        ResultSet rs;
        PropertyUtil propertyUtil = null;
        try {
            propertyUtil = new PropertyUtil();
            String maxTimeStamp = "";
            String host = request.getParameter("HostName");
            String resourceId = request.getParameter("ResourceId");
            String metricslistfromjs = request.getParameter("MetricsList");
            String[] metricslistSplit = metricslistfromjs.split(",");
            String metricslist = "";
            for (int i = 0; i < metricslistSplit.length; i++) {
                metricslist = metricslist + ",\'" + propertyUtil.getreverseMapping_Properties().get(metricslistSplit[i]) + "\'";
                if (maxTimeStamp.equals("")) {
                    String szExecuteQuery = "select max(timestamp1) as timestamp from servicemetrics where metrictype in ('" 
                            + propertyUtil.getreverseMapping_Properties().get(metricslistSplit[i]) + "\'" + ") and host = '" + host 
                            + "' and resourceid = '" + resourceId + "'";
                    maxTimeStamp = getMaxTimestampOfMetrictype(szExecuteQuery, request);
                }
            }
            String metricNames_array = "";
            String metricValue_array = "";
            String timestamp_array = "";
            st = ConnectionDAO.getConnection(request.getServerName()).createStatement();
            /*String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1) at time zone " 
                    + DBUtilHelper.getMetrics_mapping_properties().getProperty("ServerTimeZone_timestamp") + ",'HH24:mi:SS') as timestamp from "
                    + "servicemetrics where metrictype in (" + metricslist.substring(1) + ") and host = '" + host + "' and resourceid='" + resourceId 
                    + "' and timestamp1 = " + maxTimeStamp;*/
            String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1),'HH24:mi:SS') "
                    + "as timestamp from servicemetrics where metrictype in (" + metricslist.substring(1) + ") and host = '" + host + "' and resourceid='" 
                    + resourceId + "' and timestamp1 = " + maxTimeStamp;
            rs = st.executeQuery(szQuery);
            System.out.println(szQuery);
            String jsonResult = "[";
            while (rs.next()) {
                metricNames_array += "\"" + rs.getString("metrictype") + "\",";
                metricValue_array += rs.getString("metricvalue") + ",";
                timestamp_array = "\"" + rs.getString("timestamp") + "\"";
            }
            if (metricNames_array != "") {
                jsonResult = jsonResult + "{\"MetricValue\":[" + metricValue_array.substring(0, (metricValue_array.length() - 1)) + "],\"timestamp\":[" + timestamp_array + "],\"MetricName\":[" + metricNames_array.substring(0, (metricNames_array.length() - 1)) + "]}";
                jsonResult = jsonResult + "]";
            } else {
                jsonResult = "[{}]";
            }
            System.out.println("Json ==  = " + jsonResult);
            PrintWriter pw = response.getWriter();
            response.setContentType("text/html");
            pw.write(jsonResult);
            propertyUtil = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { Statement st ; ResultSet rs ; PropertyUtil propertyUtil = null ; try { propertyUtil = new PropertyUtil ( ) ; String maxTimeStamp = "" ; String host = request . getParameter ( "HostName" ) ; String resourceId = request . getParameter ( "ResourceId" ) ; String metricslistfromjs = request . getParameter ( "MetricsList" ) ; String [ ] metricslistSplit = metricslistfromjs . split ( "," ) ; String metricslist = "" ; for ( int i = 0 ; i < metricslistSplit . length ; i ++ ) { metricslist = metricslist + ",\'" + propertyUtil . getreverseMapping_Properties ( ) . get ( metricslistSplit [ i ] ) + "\'" ; if ( maxTimeStamp . equals ( "" ) ) { String szExecuteQuery = "select max(timestamp1) as timestamp from servicemetrics where metrictype in ('" + propertyUtil . getreverseMapping_Properties ( ) . get ( metricslistSplit [ i ] ) + "\'" + ") and host = '" + host + "' and resourceid = '" + resourceId + "'" ; maxTimeStamp = getMaxTimestampOfMetrictype ( szExecuteQuery , request ) ; } } String metricNames_array = "" ; String metricValue_array = "" ; String timestamp_array = "" ; st = ConnectionDAO . getConnection ( request . getServerName ( ) ) . createStatement ( ) ; /*String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1) at time zone " 
                    + DBUtilHelper.getMetrics_mapping_properties().getProperty("ServerTimeZone_timestamp") + ",'HH24:mi:SS') as timestamp from "
                    + "servicemetrics where metrictype in (" + metricslist.substring(1) + ") and host = '" + host + "' and resourceid='" + resourceId 
                    + "' and timestamp1 = " + maxTimeStamp;*/ String szQuery = "select metrictype,round(cast(metricvalue as numeric),2) as metricvalue,to_char(to_timestamp(timestamp1),'HH24:mi:SS') " + "as timestamp from servicemetrics where metrictype in (" + metricslist . substring ( 1 ) + ") and host = '" + host + "' and resourceid='" + resourceId + "' and timestamp1 = " + maxTimeStamp ; rs = st . executeQuery ( szQuery ) ; System . out . println ( szQuery ) ; String jsonResult = "[" ; while ( rs . next ( ) ) { metricNames_array += "\"" + rs . getString ( "metrictype" ) + "\"," ; metricValue_array += rs . getString ( "metricvalue" ) + "," ; timestamp_array = "\"" + rs . getString ( "timestamp" ) + "\"" ; } if ( metricNames_array != "" ) { jsonResult = jsonResult + "{\"MetricValue\":[" + metricValue_array . substring ( 0 , ( metricValue_array . length ( ) - 1 ) ) + "],\"timestamp\":[" + timestamp_array + "],\"MetricName\":[" + metricNames_array . substring ( 0 , ( metricNames_array . length ( ) - 1 ) ) + "]}" ; jsonResult = jsonResult + "]" ; } else { jsonResult = "[{}]" ; } System . out . println ( "Json ==  = " + jsonResult ) ; PrintWriter pw = response . getWriter ( ) ; response . setContentType ( "text/html" ) ; pw . write ( jsonResult ) ; propertyUtil = null ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
This method is used to get Json for generating live linechart
This method is used to get Json for generating live linechart