Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_log/alert_log.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_log/alert_log.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_log/alert_log.controller.js	(working copy)
@@ -246,8 +246,15 @@
                             if (match.tags.server_ip && match.tags.server_port) {
                                 // service_address = match.tags.server_ip + ":" + match.tags.server_port
 
-                                var query = 'select last(ConnCnt) from virtualStats where time > now()-20s and Addr=\'' + match.tags.server_ip + '\' and Port = \'' + match.tags.server_port + '\' and agent_host=\'' + device_ip + '\' group by ServerId, agent_host, Addr, Port, Protocol;'
-                                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                                let payload = {
+                                    "action": "get_alert_stats",
+                                    "query": {
+                                        "serverIP": match.tags.server_ip,
+                                        "serverPort": match.tags.server_port,
+                                        "deviceIp": device_ip
+                                    }
+                                }
+                                dashboardService.composer_query(payload).then(function (res) {
                                     if (res && res.status == 200) {
                                         if (res.data.results[0].series.length == 1) {
                                             series = res.data.results[0].series[0];
@@ -343,4 +350,4 @@
             }
 
         }
-    ])
\ No newline at end of file
+    ])
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/event_alert/event_alert.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/event_alert/event_alert.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/event_alert/event_alert.controller.js	(working copy)
@@ -244,15 +244,13 @@
                         _.each(resp, function (host) {
                             deviceMap[host.ip] = host;
                         })
-                        var query = '';
-                        if (modalViewModel.product == 'virtualService') {
-                            query = 'select count(URLHits) from virtualStats where time > now()-20s group by ServerId, agent_host;'
-                        } else if (modalViewModel.product == 'realService') {
-                            query = 'select count(rsTotalHits) from realStats where time > now()-20s group by realServerId, agent_host;'
-                        } else if (modalViewModel.product == 'sslvpnService') {
-                            query = 'select count(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host;'
+                        let payload = {
+                            "action": "get_event_alert_stats",
+                            "query": {
+                                "serviceType": modalViewModel.product,
+                            }
                         }
-                        dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                        dashboardService.composer_query(payload).then(function (res) {
                             modalViewModel.loadingInstance = false;
                             if (res && res.status == 200) {
                                 var instanceList = []
@@ -478,4 +476,4 @@
     //             return true;
     //         });
     //     }
-    // });
\ No newline at end of file
+    // });
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/threshold_alert/threshold_alert.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/threshold_alert/threshold_alert.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/alerting/alert_rule/threshold_alert/threshold_alert.controller.js	(working copy)
@@ -456,15 +456,13 @@
                         _.each(resp, function (host) {
                             deviceMap[host.ip] = host;
                         })
-                        var query = '';
-                        if (alertDetailModel.product == 'virtualService') {
-                            query = 'select count(URLHits) from virtualStats where time > now()-20s group by ServerId, agent_host, Addr, Port, Protocol;'
-                        } else if (alertDetailModel.product == 'realService') {
-                            query = 'select count(rsTotalHits) from realStats where time > now()-20s group by realServerId, agent_host;'
-                        } else if (alertDetailModel.product == 'sslvpnService') {
-                            query = 'select count(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host;'
+                        let payload = {
+                            "action": "get_threshold_stats",
+                            "query": {
+                                "serviceType": alertDetailModel.product,
+                            }
                         }
-                        dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                        dashboardService.composer_query(payload).then(function (res) {
                             alertDetailModel.loadingInstance = false;
                             if (res && res.status == 200) {
                                 var instanceList = []
@@ -762,4 +760,4 @@
                 $state.go('index.monitoring.alerting.rule.threshold');
             }
         }
-    ])
\ No newline at end of file
+    ])
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/event/query_event/query_event.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/event/query_event/query_event.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/event/query_event/query_event.controller.js	(working copy)
@@ -127,15 +127,13 @@
                         _.each(resp, function (host) {
                             deviceMap[host.ip] = host;
                         })
-                        var query = '';
-                        if (queryViewModel.queryBuilder.product == 'virtualService') {
-                            query = 'select count(URLHits) from virtualStats where time > now()-20s group by ServerId, agent_host;'
-                        } else if (queryViewModel.queryBuilder.product == 'realService') {
-                            query = 'select count(rsTotalHits) from realStats where time > now()-20s group by realServerId, agent_host;'
-                        } else if (queryViewModel.queryBuilder.product == 'sslvpnService') {
-                            query = 'select count(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host;'
+                        let payload = {
+                            "action": "get_event_alert_stats",
+                            "query": {
+                                "serviceType": modalViewModel.product,
+                            }
                         }
-                        dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                        dashboardService.composer_query(payload).then(function (res) {
                             queryViewModel.loadingInstance = false;
                             if (res && res.status == 200) {
                                 var instanceList = []
@@ -201,11 +199,31 @@
                     'endTime': queryViewModel.endTime
                 });
 
-                var timeCondition = "WHERE time > ";
-                var startstamp = new Date(queryViewModel.startTime.replace(/-/g, "/")).getTime();
-                timeCondition += startstamp * 1e6 + " AND time < ";
-                var endstamp = new Date(queryViewModel.endTime.replace(/-/g, "/")).getTime();
-                timeCondition += endstamp * 1e6;
+                let startstamp = new Date(queryViewModel.startTime.replace(/-/g, "/")).getTime();
+                let endstamp = new Date(queryViewModel.endTime.replace(/-/g, "/")).getTime();
+                let payload = {
+                    "action": "get_event_detection_stat_quantity",
+                    "query": {
+                        "start_time": startstamp * 1e6,
+                        "end_time": endstamp * 1e6,
+                    }
+                }
+                if (queryViewModel.queryBuilder.product !== "all") {
+                    payload['query']['product'] = queryViewModel.queryBuilder.product;
+                    if (queryViewModel.queryBuilder.instance.length !== 0) {
+                        let instance = JSON.parse(queryViewModel.queryBuilder.instance);
+                        payload['query']['agent_host'] = instance.agent_host
+                        if (queryViewModel.queryBuilder.product !== 'device') {
+                            payload['query']['server_id'] = instance.name
+                        }
+                    }
+                    if (queryViewModel.queryBuilder.event_type.length !== 0) {
+                        payload['query']['event_type'] = queryViewModel.queryBuilder.event_type
+                    }
+                    if (queryViewModel.queryBuilder.event_name.length !== 0) {
+                        payload['query']['event_name'] = queryViewModel.queryBuilder.event_name
+                    }
+                }
 
                 var otherCondition = "";
                 if (queryViewModel.queryBuilder.product != "all") {
@@ -261,8 +279,7 @@
                     queryViewModel.eventWidget.series = newSeries;
                 });
 
-                var query = 'SELECT sum(quantity) FROM event_detection ' + timeCondition + otherCondition + ' GROUP BY event_name, product;'
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                dashboardService.composer_query(payload).then(function (res) {
                     queryViewModel.loading = false;
                     if (res && res.status == 200) {
                         var eventList = []
@@ -409,27 +426,29 @@
             queryViewModel.product = modalData.queryBuilder.product;
             queryViewModel.event_verbose_name = modalData.queryBuilder.event_verbose_name;
 
-            var timeCondition = "WHERE time > ";
-            var startstamp = new Date(modalData.startTime.replace(/-/g, "/")).getTime();
-            timeCondition += startstamp * 1e6 + " AND time < ";
-            var endstamp = new Date(modalData.endTime.replace(/-/g, "/")).getTime();
-            timeCondition += endstamp * 1e6;
-
-            var otherCondition = "";
-            if (modalData.queryBuilder.product != "all") {
-                otherCondition += " AND product = '" + modalData.queryBuilder.product + "'"
-                if (modalData.queryBuilder.instance.length != 0) {
-                    var instance = JSON.parse(modalData.queryBuilder.instance)
-                    otherCondition += " AND agent_host = '" + instance.agent_host + "'"
-                    if (modalData.queryBuilder.product != 'device') {
-                        otherCondition += " AND server_id = '" + instance.name + "'"
+            let startstamp = new Date(modalData.startTime.replace(/-/g, "/")).getTime();
+            let endstamp = new Date(modalData.endTime.replace(/-/g, "/")).getTime();
+            let payload = {
+                "action": "get_event_detection_stats",
+                "query": {
+                    "start_time": startstamp * 1e6,
+                    "end_time": endstamp * 1e6,
+                }
+            }
+            if (modalData.queryBuilder.product !== "all") {
+                payload['query']['product'] = modalData.queryBuilder.product;
+                if (modalData.queryBuilder.instance.length !== 0) {
+                    let instance = JSON.parse(modalData.queryBuilder.instance);
+                    payload['query']['agent_host'] = instance.agent_host
+                    if (modalData.queryBuilder.product !== 'device') {
+                        payload['query']['server_id'] = instance.name
                     }
                 }
-                if (modalData.queryBuilder.event_type.length != 0) {
-                    otherCondition += " AND event_type = '" + modalData.queryBuilder.event_type + "'"
+                if (modalData.queryBuilder.event_type.length !== 0) {
+                    payload['query']['event_type'] = modalData.queryBuilder.event_type
                 }
-                if (modalData.queryBuilder.event_name.length != 0) {
-                    otherCondition += " AND event_name = '" + modalData.queryBuilder.event_name + "'"
+                if (modalData.queryBuilder.event_name.length !== 0) {
+                    payload['query']['event_name'] = modalData.queryBuilder.event_name
                 }
             }
 
@@ -445,12 +464,11 @@
                     }
                 })
                 if (agentHost !== '') agentHost += '/';
-                let query = 'SELECT time, agent_host, server_id, quantity FROM event_detection ' + timeCondition + otherCondition + ' GROUP BY event_name, product order by time desc;'
                 if ($scope.isDeviceAdmin) {
-                    query = 'SELECT time, agent_host, server_id, quantity FROM event_detection ' + timeCondition + otherCondition + ' and agent_host =~ '+ agentHost +' GROUP BY event_name, product order by time desc;'
+                    payload['query']['agent_host'] = agentHost;
                 }
                 if (($scope.isDeviceAdmin && agentHost !== '') || !$scope.isDeviceAdmin) {
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                    dashboardService.composer_query(payload).then(function (res) {
                     queryViewModel.loading = false;
                     if (res && res.status == 200) {
                         var eventList = []
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/monitoring.service.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/monitoring.service.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/monitoring.service.js	(working copy)
@@ -51,8 +51,14 @@
 
             function getVirtualService(device_ip) {
                 var deferred = $q.defer();
-                var query = "select count(URLHits) from virtualStats where time > now()-20s and agent_host='" + device_ip + "' group by ServerId;"
-                dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                let payload = {
+                    "action": "get_threshold_stats",
+                    "query": {
+                        "serviceType": "virtualService",
+                        "device_ip": device_ip
+                    }
+                }
+                dashboardService.composer_query(payload).then(function (res) {
                     var serverList = []
                     if (res && res.status === 200) {
                         _.each(res.data.results[0].series, function (series) {
@@ -70,8 +76,14 @@
 
             function getRealService(device_ip) {
                 var deferred = $q.defer();
-                var query = "select count(rsTotalHits) from realStats where time > now()-20s and agent_host='" + device_ip + "' group by realServerId;"
-                dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                let payload = {
+                    "action": "get_threshold_stats",
+                    "query": {
+                        "serviceType": "realService",
+                        "device_ip": device_ip
+                    }
+                }
+                dashboardService.composer_query(payload).then(function (res) {
                     var serverList = []
                     if (res && res.status === 200) {
                         _.each(res.data.results[0].series, function (series) {
@@ -89,8 +101,14 @@
 
             function getVirtualSite(device_ip) {
                 var deferred = $q.defer();
-                var query = "select count(ActiveSessions) from virtualSiteStats where time > now()-20s and agent_host='" + device_ip + "' group by Id;"
-                dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                let payload = {
+                    "action": "get_threshold_stats",
+                    "query": {
+                        "serviceType": "sslvpnService",
+                        "device_ip": device_ip
+                    }
+                }
+                dashboardService.composer_query(payload).then(function (res) {
                     var serverList = []
                     if (res && res.status === 200) {
                         _.each(res.data.results[0].series, function (series) {
@@ -106,4 +124,4 @@
                 return deferred.promise;
             }
         }
-    ]);
\ No newline at end of file
+    ]);
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/real_service.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/real_service.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/real_service.controller.js	(working copy)
@@ -185,12 +185,16 @@
                         })
                     })
                     if (agentHost !== '') agentHost += '/';
-                    let query = 'select last(rsCntOfReq), last(rsConnPerSec), last(rsInBytePerSec)*8, last(rsOutBytePerSec)*8 from realStats where time > now()-20s group by realServerId, agent_host, Addr, Port, Protocol, Status;'
+                    let payload = {
+                        "action": "get_real_service_stats",
+                    }
                     if (isDeviceAdmin) {
-                        query = 'select last(rsCntOfReq), last(rsConnPerSec), last(rsInBytePerSec)*8, last(rsOutBytePerSec)*8 from realStats where agent_host  =~ ' + agentHost + ' and time > now()-20s group by realServerId, agent_host, Addr, Port, Protocol, Status;'
+                        payload['query'] = {
+                            "agent_host": agentHost
+                        }
                     }
                     if ((isDeviceAdmin && agentHost !== '') || !isDeviceAdmin) {
-                        dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                        dashboardService.composer_query(payload).then(function (res) {
                             serviceViewModel.loading = false;
                             if (res && res.status === 200) {
                                 if (res.data.results.length > 0) {
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/virtual_service.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/virtual_service.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/slb/virtual_service.controller.js	(working copy)
@@ -187,12 +187,16 @@
                         });
                     });
                     if (agentHost !== '') agentHost += '/';
-                    let query = 'select max(totalHits)-min(totalHits), last(ConnCnt), last(InBytePerSec)*8, last(OutBytePerSec)*8 from virtualStats where time > now()-20s group by ServerId, agent_host, Addr, Port, Protocol, HealthStatus;'
+                    let payload = {
+                        "action": "get_virtual_service_stats",
+                    }
                     if (isDeviceAdmin) {
-                        query = 'select max(totalHits)-min(totalHits), last(ConnCnt), last(InBytePerSec)*8, last(OutBytePerSec)*8 from virtualStats where agent_host  =~ ' + agentHost + ' and time > now()-20s group by ServerId, agent_host, Addr, Port, Protocol, HealthStatus;'
+                        payload['query'] = {
+                            "agent_host": agentHost
+                        }
                     }
                     if ((isDeviceAdmin && agentHost !== '') || !isDeviceAdmin) {
-                        dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                        dashboardService.composer_query(payload).then(function (res) {
                             serviceViewModel.loading = false;
                             if (res && res.status === 200) {
                                 if (res.data.results.length > 0) {
@@ -584,8 +588,14 @@
                 // modalInstance.result.then(function (result) {
                 // });
             }
-            var query = 'select last(ConnCnt) from virtualStats where time > now()-20s and ServerId=\'' + $scope.current_service_name + '\' and agent_host=\'' + $stateParams.device_ip + '\' group by ServerId, agent_host, Addr, Port, Protocol;'
-            dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+            let payload = {
+                "action": "get_virtual_service_connection_stats",
+                "query": {
+                    "serviceName": $scope.current_service_name,
+                    "deviceIp": $stateParams.device_ip
+                }
+            }
+            dashboardService.composer_query(payload).then(function (res) {
                 if (res && res.status == 200) {
                     if (res.data.results[0].series.length == 1) {
                         series = res.data.results[0].series[0];
Index: /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/sslvpn/sslvpn.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/sslvpn/sslvpn.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/extensions/monitoring/webui/resource/sslvpn/sslvpn.controller.js	(working copy)
@@ -153,12 +153,16 @@
                         })
                     });
                     if (agentHost !== '') agentHost += '/';
-                    let query = 'select last(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host, IP;'
+                    let payload = {
+                        "action": "get_ssl_vpn_stats",
+                    }
                     if (isDeviceAdmin) {
-                        query = 'select last(ActiveSessions) from virtualSiteStats where agent_host  =~ ' + agentHost + ' and time > now()-20s group by Id, agent_host, IP;'
+                        payload['query'] = {
+                            "agent_host": agentHost
+                        }
                     }
                     if ((isDeviceAdmin && agentHost !== '') || !isDeviceAdmin) {
-                        dashboardService.influxdb_proxy({"q": query}).then(function (res) {
+                        dashboardService.composer_qurty(payload).then(function (res) {
                             serviceViewModel.loading = false;
                             if (res && res.status === 200) {
                                 if (res.data.results.length > 0) {
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/dashboard.service.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/dashboard.service.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/dashboard.service.js	(working copy)
@@ -5,21 +5,17 @@
         function ($q, apiService) {
             return {
                 get_composer_data: get_composer_data,
-                influxdb_proxy: influxdb_proxy,
                 get_adc_ssl_cert: get_adc_ssl_cert,
                 get_vpn_ssl_cert: get_vpn_ssl_cert,
                 getAllVirtualService: getAllVirtualService,
                 getAllVirtualSite: getAllVirtualSite,
                 checkLicenseExpire: checkLicenseExpire,
+                composer_query: composer_query
             };
             function get_composer_data(url, data) {
                 return apiService.post2(url, data);
             }
 
-            function influxdb_proxy(params) {
-                return apiService.post2('/composer/datasource/proxy/1/query?db=composer&epoch=ms', params, { headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' } });
-            }
-
             function get_adc_ssl_cert() {
                 return apiService.get('/cm/get_adc_ssl_cert');
             }
@@ -30,15 +26,19 @@
 
             function getAllVirtualService(device_name) {
                 return apiService.proxy_get_dev(device_name, "/rest/loadbalancing/slb/vs/VirtualService");
-            };
+            }
 
             function getAllVirtualSite(device_name) {
                 var post_data = { 'cmd': 'show virtual site name' }
                 return apiService.proxy_post_dev(device_name, "/rest/global/cli_extend", JSON.stringify(post_data));
-            };
+            }
 
             function checkLicenseExpire() {
                 return apiService.get('/cm/get_license_expire');
             }
+
+            function composer_query(payload) {
+                return apiService.post2('/composer_query', JSON.stringify(payload), { headers: { 'Content-Type': 'application/json' } });
+            }
         }
     ]);
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/overview/overview.controller.js
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/overview/overview.controller.js	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/client/app/modules/dashboard/overview/overview.controller.js	(working copy)
@@ -129,15 +129,15 @@
             }
             let getDeviceMonitoringData = function () {
                 overviewModel.deviceLoading = true;
-                let query = 'select TOP(last, 5) as cpu, agent_host from (select last(cpu_usage) from snmp_system group by agent_host) where time > now()-20s;' +
-                    'select TOP(last, 5) as net_mem, agent_host from (select last(net_mem_usage) from snmp_system group by agent_host) where time > now()-20s;' +
-                    'select TOP(total, 5), received, sent, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(total_in), 1s)*8 as received, non_negative_derivative(first(total_out), 1s)*8 as sent FROM snmp_system WHERE time > now()-30s group by time(10s), agent_host) group by agent_host)'
+                let payload = {
+                    "action": "get_device_monitoring_data",
+                }
                 if($scope.isDeviceAdmin) {
-                    query = 'select TOP(last, 5) as cpu, agent_host from (select last(cpu_usage) from snmp_system group by agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(last, 5) as net_mem, agent_host from (select last(net_mem_usage) from snmp_system group by agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(total, 5), received, sent, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(total_in), 1s)*8 as received, non_negative_derivative(first(total_out), 1s)*8 as sent FROM snmp_system WHERE agent_host =~ '+ overviewModel.agentHost +' and time > now()-30s group by time(10s), agent_host) group by agent_host)'
+                    payload['query'] = {
+                        "agent_host": overviewModel.agentHost
+                    }
                 }
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                dashboardService.composer_query(payload).then(function (res) {
                     overviewModel.deviceLoading = false;
                     if (res && res.status === 200) {
                         var cpuUsageList = []
@@ -196,15 +196,15 @@
             }
             let getVirtualMonitoringData = function () {
                 overviewModel.vsLoading = true;
-                let query = 'select TOP(hits, 5), ServerId, agent_host from (SELECT max(totalHits)-min(totalHits) as hits FROM virtualStats group by agent_host, ServerId) WHERE time > now()-20s;' +
-                    'select TOP(last, 5), ServerId, agent_host from (select last(ConnCnt) from virtualStats group by ServerId, agent_host) where time > now()-20s;' +
-                    'select TOP(total, 5), received, sent, ServerId, agent_host from (select last(InBytePerSec)+last(OutBytePerSec) as total, last(InBytePerSec)*8 as received, last(OutBytePerSec)*8 as sent from virtualStats group by ServerId, agent_host) where time > now()-20s;'
+                let payload = {
+                    "action": "get_virtual_service_monitoring_data",
+                }
                 if($scope.isDeviceAdmin) {
-                    query = 'select TOP(hits, 5), ServerId, agent_host from (SELECT max(totalHits)-min(totalHits) as hits FROM virtualStats group by agent_host, ServerId) WHERE agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(last, 5), ServerId, agent_host from (select last(ConnCnt) from virtualStats group by ServerId, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(total, 5), received, sent, ServerId, agent_host from (select last(InBytePerSec)+last(OutBytePerSec) as total, last(InBytePerSec)*8 as received, last(OutBytePerSec)*8 as sent from virtualStats group by ServerId, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;'
+                    payload['query'] = {
+                        "agent_host": overviewModel.agentHost
+                    }
                 }
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                dashboardService.composer_query(payload).then(function (res) {
                     overviewModel.vsLoading = false;
                     if (res && res.status === 200) {
                         var hitsList = []
@@ -254,15 +254,15 @@
             }
             let getRealMonitoringData = function () {
                 overviewModel.rsLoading = true;
-                let query = 'select TOP(last, 5), realServerId, agent_host from (select last(rsCntOfReq) from realStats group by realServerId, agent_host) where time > now()-20s;' +
-                    'select TOP(last, 5), realServerId, agent_host from (select last(rsConnPerSec) from realStats group by realServerId, agent_host) where time > now()-20s;' +
-                    'select TOP(total, 5), received, sent, realServerId, agent_host from (select last(rsInBytePerSec)+last(rsOutBytePerSec) as total, last(rsInBytePerSec)*8 as received, last(rsOutBytePerSec)*8 as sent from realStats group by realServerId, agent_host) where time > now()-20s;'
-                if ($scope.isDeviceAdmin) {
-                    query = 'select TOP(last, 5), realServerId, agent_host from (select last(rsCntOfReq) from realStats group by realServerId, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(last, 5), realServerId, agent_host from (select last(rsConnPerSec) from realStats group by realServerId, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(total, 5), received, sent, realServerId, agent_host from (select last(rsInBytePerSec)+last(rsOutBytePerSec) as total, last(rsInBytePerSec)*8 as received, last(rsOutBytePerSec)*8 as sent from realStats group by realServerId, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;'
+                let payload = {
+                    "action": "get_real_service_monitoring_data",
+                }
+                if($scope.isDeviceAdmin) {
+                    payload['query'] = {
+                        "agent_host": overviewModel.agentHost
+                    }
                 }
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                dashboardService.composer_query(payload).then(function (res) {
                     overviewModel.rsLoading = false;
                     if (res && res.status === 200) {
                         var rsCntOfReqList = []
@@ -312,15 +312,15 @@
             }
             let getSSLVPNMonitoringData = function () {
                 overviewModel.sslvpnLoading = true;
-                let query = 'select TOP(last, 5), Id, agent_host from (select last(ActiveSessions) from virtualSiteStats group by Id, agent_host) where time > now()-20s;' +
-                    'select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ClientBytesIn), 1s)*8 as received, non_negative_derivative(first(ClientBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);' +
-                    'select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ServerBytesIn), 1s)*8 as received, non_negative_derivative(first(ServerBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);'
-                if ($scope.isDeviceAdmin) {
-                    query = 'select TOP(last, 5), Id, agent_host from (select last(ActiveSessions) from virtualSiteStats group by Id, agent_host) where agent_host =~ '+ overviewModel.agentHost +' and time > now()-20s;' +
-                        'select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ClientBytesIn), 1s)*8 as received, non_negative_derivative(first(ClientBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE agent_host =~ '+ overviewModel.agentHost +' and time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);' +
-                        'select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ServerBytesIn), 1s)*8 as received, non_negative_derivative(first(ServerBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE agent_host =~ '+ overviewModel.agentHost +' and time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);'
+                let payload = {
+                    "action": "get_ssl_vpn_monitoring_data",
                 }
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
+                if($scope.isDeviceAdmin) {
+                    payload['query'] = {
+                        "agent_host": overviewModel.agentHost
+                    }
+                }
+                dashboardService.composer_query(payload).then(function (res) {
                     overviewModel.sslvpnLoading = false;
                     if (res && res.status === 200) {
                         var sessionList = []
@@ -549,13 +549,17 @@
                     })
                 }
 
-                var eventNum = 0;
-                var timeCondition = "WHERE time > ";
-                timeCondition += start * 1e6 + " AND time < ";
-                timeCondition += now * 1e6;
-                var query = 'SELECT sum(quantity) FROM event_detection ' + timeCondition
-                dashboardService.influxdb_proxy({ "q": query }).then(function (res) {
-                    if (res && res.status == 200) {
+                let eventNum = 0;
+                let payload = {
+                    "action": "get_quantity_from_event_deduction",
+                    "query": {
+                        "start_time": start * 1e6,
+                        "end_time": now * 1e6,
+                    }
+                }
+                dashboardService.composer_query(payload).then(function (res) {
+                    eventNum = 0;
+                    if (res && res.status === 200) {
                         if (res.data.results) {
                             if (res.data.results[0].series) {
                                 _.each(res.data.results[0].series, function (series) {
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/djproject/urls.py
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/djproject/urls.py	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/djproject/urls.py	(working copy)
@@ -9,7 +9,7 @@
 from hive.utils import hive_webpipe_handler, hive_webpipe_write_handler
 from hive.node import reload_app_node
 from hive.session import current_app
-from hive.composer import KibanaProxyView, elastic_proxy, composer_proxy, reporting_downloading_handler, reporting_logo_handler, composer_config, composer_status
+from hive.composer import KibanaProxyView, elastic_proxy, reporting_downloading_handler, reporting_logo_handler, composer_config, composer_status, composer_query
 from hive.storage import storage_mangement
 from hive.log_location import handle_log_location_app
 
@@ -54,9 +54,9 @@
 
 urlpatterns += patterns(
     '',
-    url(r'^composer/(?P<path>.*)', composer_proxy),
     url(r'^composer_config/(?P<app>\w+)', composer_config),
     url(r'^composer_status/(?P<app>\w+)', composer_status),
+    url(r'^composer_query$', composer_query),
     url(r'^log/(?P<app>\w+)$', handle_log_location_app),
     url(r'^real_service$', real_service),
     url(r'^rs_block$', rs_block),
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/composer.py
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/composer.py	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/composer.py	(working copy)
@@ -1,30 +1,24 @@
+import codecs
+import fcntl
 import hashlib
 import httplib
-import time
 import json
 import os
-import fcntl
-from lib.response import FileResponse
-from django.http import HttpResponse
-from djproject.an_settings import extension_path, CMDATA
-from elasticsearch import Elasticsearch
-from elasticsearch.exceptions import ElasticsearchException
-from hive.utils import andebug, upload_receive
+import subprocess
+import time
+
 import lib.toml as toml
 import lib.yaml as yaml
-import codecs
-import subprocess
-import os
-import ConfigParser
+from cm.lib.libbasic_operation import oper_log
+from django.http import HttpResponse
 from django.views.decorators.csrf import csrf_exempt
 from django.views.decorators.gzip import gzip_page
-from cm.lib.libbasic_operation import oper_log
-# import re
-# import requests
-# try:
-#     from urlparse import urlparse
-# except BaseException:
-#     from urllib.parse import urlparse
+from djproject.an_settings import extension_path, CMDATA
+from elasticsearch import Elasticsearch
+from hive.custom_exceptions import generic_exception as ge
+from hive.utils import andebug, upload_receive
+from lib.response import FileResponse
+from hive.services import composer_query_service
 from revproxy.views import ProxyView
 
 ELASTIC_SEARCH_CONFIG_FILE = '/etc/elasticsearch/elasticsearch.yml'
@@ -145,38 +139,39 @@
     return HttpResponse(json.dumps(res), content_type='application/json')
 
 
-@csrf_exempt
-@gzip_page
-def composer_proxy(request, path):
-    url = "/v1/" + path
-    timestamp = str(int(time.time()))
-    m = hashlib.md5()
-    m.update(CMDATA['COMPOSER_KEY'] + str(timestamp) + url + CMDATA['COMPOSER_SECRET'])
-
-    query_string = request.environ['QUERY_STRING']
-    if query_string == '':
-        query_string += "time=" + timestamp + "&sign=" + m.hexdigest()
-    else:
-        query_string += "&time=" + timestamp + "&sign=" + m.hexdigest()
+def composer_query(request):
+    http_client = None
 
-    # for k, v in request.environ.items():
-    #     print(k, v)
+    try:
+        req = json.loads(request.body)
+        req_dict = eval('composer_query_service.' + req['action'] + '(req)')
+        req_payload = req_dict["body"]
+        timestamp = str(int(time.time()))
+        m = hashlib.md5()
+        m.update(CMDATA['COMPOSER_KEY'] + str(timestamp) + req_dict["url"] + CMDATA['COMPOSER_SECRET'])
+
+        query_string = req_dict["path"]
+        if query_string == '':
+            query_string += "time=" + timestamp + "&sign=" + m.hexdigest()
+        else:
+            query_string += "&time=" + timestamp + "&sign=" + m.hexdigest()
 
-    httpClient = None
+        http_client = httplib.HTTPConnection(CMDATA['COMPOSER_IP'], str(CMDATA['COMPOSER_PORT']), True, timeout=300)
+        http_client.request(req_dict['method'], req_dict["url"] + "?" + query_string, req_payload, req_dict['config'])
 
-    if 'CONTENT_TYPE' in request.environ:
-        config = {"Content-Type": request.environ['CONTENT_TYPE']}
-    else:
-        config = {}
-    try:
-        httpClient = httplib.HTTPConnection(CMDATA['COMPOSER_IP'], str(CMDATA['COMPOSER_PORT']), True, timeout=300)
-        httpClient.request(request.method, url + "?" + query_string, request.body, config)
-        response = httpClient.getresponse()
+        response = http_client.getresponse()
         response_data = {
             'status': response.status,
             'reason': response.reason,
             'body': response.read(),
         }
+    except ge.ANInternalException as exp:
+        return HttpResponse(json.dumps({
+            'parm_name': exp.parm_name,
+            'error': exp.error_code,
+            'message': exp.description,
+            'data': None
+        }), content_type='application/json', status=exp.error_code)
     except Exception as e:
         return HttpResponse(json.dumps({
             'error': 500,
@@ -193,8 +188,8 @@
                 'data': response_data['body']
             }), content_type='application/json')
     finally:
-        if httpClient:
-            httpClient.close()
+        if http_client:
+            http_client.close()
 
 
 def reporting_downloading_handler(request, app, filename):
@@ -567,4 +562,3 @@
         return elastic_status(request)
     elif app == 'kibana':
         return kibana_status(request)
-
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/custom_exceptions/generic_exception.py
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/custom_exceptions/generic_exception.py	(revision 2369)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/custom_exceptions/generic_exception.py	(working copy)
@@ -32,4 +32,11 @@
         }
         status_code = 500
 
-    return HttpResponse(json.dumps(response_data), status=status_code, content_type='application/json')
\ No newline at end of file
+    return HttpResponse(json.dumps(response_data), status=status_code, content_type='application/json')
+
+
+class ANInternalException(Exception):
+    def __init__(self, parm_name, error_code, description):
+        self.parm_name = parm_name
+        self.error_code = error_code
+        self.description = description
Index: /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/services/composer_query_service.py
===================================================================
--- /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/services/composer_query_service.py	(revision 0)
+++ /branches/amp_bug_fixes_base_3_6_0/src/webui/webui/htdocs/new/src/hive/services/composer_query_service.py	(working copy)
@@ -0,0 +1,354 @@
+from cm.lib.libbasic_operation import oper_log
+from hive.custom_exceptions import generic_exception as ge
+
+
+def format_query_string(query):
+    return query.strip().replace(' ', "%20").replace('<', "%3C").replace('>', "%3E").replace(',', "%2C").replace(
+        ';', "%3B").replace('+', "%2B").replace('/', "%2F").replace('|', "%7C").replace('=', "%3D")
+
+
+def get_quantity_from_event_deduction(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": "",
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    if 'query' in request:
+        if 'start_time' in request['query'] and 'end_time' in request['query']:
+            query_string = format_query_string(
+                'SELECT SUM(quantity) FROM event_detection WHERE time > {} AND time < {}'.format(
+                    request['query']['start_time'], request['query']['end_time']))
+            req_dict["body"] = 'q=' + query_string
+        else:
+            oper_log('error', 'system', "Required fields (start_time, end_time) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (start_time, end_time) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - start_time, end_time) are missing.")
+        raise ge.ANInternalException(parm_name="query", error_code=400,
+                                     description="Required fields (query - start_time, end_time) are missing.")
+    return req_dict
+
+
+def get_device_monitoring_data(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'SELECT TOP(last, 5) as cpu, agent_host from (select last(cpu_usage) from snmp_system group by agent_host) where time > now()-20s;select TOP(last, 5) as net_mem, agent_host from (select last(net_mem_usage) from snmp_system group by agent_host) where time > now()-20s;select TOP(total, 5), received, sent, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(total_in), 1s)*8 as received, non_negative_derivative(first(total_out), 1s)*8 as sent FROM snmp_system WHERE time > now()-30s group by time(10s), agent_host) group by agent_host)'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = "SELECT TOP(last, 5) as cpu, agent_host from (select last(cpu_usage) from snmp_system group by agent_host) where agent_host =~ {} and time > now()-20s; select TOP(last, 5) as net_mem, agent_host from (select last(net_mem_usage) from snmp_system group by agent_host) where agent_host =~ {} and time > now()-20s; select TOP(total, 5), received, sent, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(total_in), 1s)*8 as received, non_negative_derivative(first(total_out), 1s)*8 as sent FROM snmp_system WHERE agent_host =~ {} and time > now()-30s group by time(10s), agent_host) group by agent_host)".format(
+                request['query']['agent_host'], request['query']['agent_host'], request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_virtual_service_monitoring_data(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select TOP(hits, 5), ServerId, agent_host from (SELECT max(totalHits)-min(totalHits) as hits FROM virtualStats group by agent_host, ServerId) WHERE time > now()-20s;select TOP(last, 5), ServerId, agent_host from (select last(ConnCnt) from virtualStats group by ServerId, agent_host) where time > now()-20s;select TOP(total, 5), received, sent, ServerId, agent_host from (select last(InBytePerSec)+last(OutBytePerSec) as total, last(InBytePerSec)*8 as received, last(OutBytePerSec)*8 as sent from virtualStats group by ServerId, agent_host) where time > now()-20s;'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = "select TOP(hits, 5), ServerId, agent_host from (SELECT max(totalHits)-min(totalHits) as hits FROM virtualStats group by agent_host, ServerId) WHERE agent_host =~ {} and time > now()-20s;select TOP(last, 5), ServerId, agent_host from (select last(ConnCnt) from virtualStats group by ServerId, agent_host) where agent_host =~ {} and time > now()-20s;select TOP(total, 5), received, sent, ServerId, agent_host from (select last(InBytePerSec)+last(OutBytePerSec) as total, last(InBytePerSec)*8 as received, last(OutBytePerSec)*8 as sent from virtualStats group by ServerId, agent_host) where agent_host =~ {} and time > now()-20s;".format(
+                request['query']['agent_host'], request['query']['agent_host'], request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_real_service_monitoring_data(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select TOP(last, 5), realServerId, agent_host from (select last(rsCntOfReq) from realStats group by realServerId, agent_host) where time > now()-20s;select TOP(last, 5), realServerId, agent_host from (select last(rsConnPerSec) from realStats group by realServerId, agent_host) where time > now()-20s;select TOP(total, 5), received, sent, realServerId, agent_host from (select last(rsInBytePerSec)+last(rsOutBytePerSec) as total, last(rsInBytePerSec)*8 as received, last(rsOutBytePerSec)*8 as sent from realStats group by realServerId, agent_host) where time > now()-20s;'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = 'select TOP(last, 5), realServerId, agent_host from (select last(rsCntOfReq) from realStats group by realServerId, agent_host) where agent_host =~ {} and time > now()-20s;select TOP(last, 5), realServerId, agent_host from (select last(rsConnPerSec) from realStats group by realServerId, agent_host) where agent_host =~ {} and time > now()-20s;select TOP(total, 5), received, sent, realServerId, agent_host from (select last(rsInBytePerSec)+last(rsOutBytePerSec) as total, last(rsInBytePerSec)*8 as received, last(rsOutBytePerSec)*8 as sent from realStats group by realServerId, agent_host) where agent_host =~ {} and time > now()-20s;'.format(
+                request['query']['agent_host'], request['query']['agent_host'], request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_ssl_vpn_monitoring_data(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select TOP(last, 5), Id, agent_host from (select last(ActiveSessions) from virtualSiteStats group by Id, agent_host) where time > now()-20s;select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ClientBytesIn), 1s)*8 as received, non_negative_derivative(first(ClientBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ServerBytesIn), 1s)*8 as received, non_negative_derivative(first(ServerBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = 'select TOP(last, 5), Id, agent_host from (select last(ActiveSessions) from virtualSiteStats group by Id, agent_host) where agent_host =~ {} and time > now()-20s;select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ClientBytesIn), 1s)*8 as received, non_negative_derivative(first(ClientBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE agent_host =~ {} and time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);select TOP(total, 5), received, sent, Id, agent_host from (select last(received)+last(sent) as total, last(received) as received, last(sent) as sent from (SELECT non_negative_derivative(first(ServerBytesIn), 1s)*8 as received, non_negative_derivative(first(ServerBytesOut), 1s)*8 as sent FROM virtualSiteStats WHERE agent_host =~ {} and time > now()-30s group by time(10s), Id, agent_host) group by Id, agent_host);'.format(
+                request['query']['agent_host'], request['query']['agent_host'], request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_virtual_service_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select max(totalHits)-min(totalHits), last(ConnCnt), last(InBytePerSec)*8, last(OutBytePerSec)*8 from virtualStats where time > now()-20s group by ServerId, agent_host, Addr, Port, Protocol, HealthStatus;'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = 'select max(totalHits)-min(totalHits), last(ConnCnt), last(InBytePerSec)*8, last(OutBytePerSec)*8 from virtualStats where agent_host  =~ {} and time > now()-20s group by ServerId, agent_host, Addr, Port, Protocol, HealthStatus;'.format(
+                request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_real_service_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select last(rsCntOfReq), last(rsConnPerSec), last(rsInBytePerSec)*8, last(rsOutBytePerSec)*8 from realStats where time > now()-20s group by realServerId, agent_host, Addr, Port, Protocol, Status;'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = 'select last(rsCntOfReq), last(rsConnPerSec), last(rsInBytePerSec)*8, last(rsOutBytePerSec)*8 from realStats where agent_host  =~ {} and time > now()-20s group by realServerId, agent_host, Addr, Port, Protocol, Status;'.format(
+                request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_ssl_vpn_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = 'select last(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host, IP;'
+    if 'query' in request:
+        if 'agent_host' in request['query']:
+            query_string = 'select last(ActiveSessions) from virtualSiteStats where agent_host  =~ {} and time > now()-20s group by Id, agent_host, IP;'.format(
+                request['query']['agent_host'])
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_virtual_service_connection_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'serviceName' in request['query'] and 'deviceIp' in request['query']:
+            query_string = "select last(ConnCnt) from virtualStats where time > now()-20s and ServerId='{}' and agent_host='{}' group by ServerId, agent_host, Addr, Port, Protocol;".format(
+                request["query"]["serviceName"], request["query"]["deviceIp"])
+        else:
+            oper_log('error', 'system', "Required fields (serviceName, deviceIp) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (serviceName, deviceIp) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - serviceName, deviceIp) are missing.")
+        raise ge.ANInternalException(parm_name="query", error_code=400,
+                                     description="Required fields (query - serviceName, deviceIp) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_threshold_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'serviceType' in request['query']:
+            if request['query']['serviceType'] == 'virtualService':
+                query_string = 'select count(URLHits) from virtualStats where time > now()-20s'
+                if 'device_ip' in request['query']:
+                    query_string += " and agent_host='{}'".format(request['query']['device_ip'])
+                query_string += ' group by ServerId, agent_host, Addr, Port, Protocol;'
+            elif request['query']['serviceType'] == 'realService':
+                query_string = 'select count(rsTotalHits) from realStats where time > now()-20s'
+                if 'device_ip' in request['query']:
+                    query_string += " and agent_host='{}'".format(request['query']['device_ip'])
+                query_string += ' group by realServerId, agent_host;'
+            elif request['query']['serviceType'] == 'sslvpnService':
+                query_string = 'select count(ActiveSessions) from virtualSiteStats where time > now()-20s'
+                if 'device_ip' in request['query']:
+                    query_string += " and agent_host='{}'".format(request['query']['device_ip'])
+                query_string += ' group by Id, agent_host;'
+        else:
+            oper_log('error', 'system', "Required fields (serviceType) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (serviceType) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query- serviceType) are missing.")
+        raise ge.ANInternalException(parm_name="query", error_code=400,
+                                     description="Required fields (query - serviceType) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_alert_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'serverIP' in request['query'] and 'serverPort' in request['query'] and 'deviceIp' in request['query']:
+            query_string = "select last(ConnCnt) from virtualStats where time > now()-20s and Addr='{}' and Port = '{}' and agent_host='{}' group by ServerId, agent_host, Addr, Port, Protocol;".format(
+                request['query']['serverIP'], request['query']['serverPort'], request['query']['deviceIp']
+            )
+        else:
+            oper_log('error', 'system', "Required fields (serverIP, serverPort, deviceIp) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (serverIP, serverPort, deviceIp) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - serverIP, serverPort, deviceIp) are missing.")
+        raise ge.ANInternalException(parm_name="request_payload", error_code=400,
+                                     description="Required fields (query - serverIP, serverPort, deviceIp) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_event_alert_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'serviceType' in request['query']:
+            if request['query']['serviceType'] == 'virtualService':
+                query_string = 'select count(URLHits) from virtualStats where time > now()-20s group by ServerId, agent_host;'
+            elif request['query']['serviceType'] == 'realService':
+                query_string = 'select count(rsTotalHits) from realStats where time > now()-20s group by realServerId, agent_host;'
+            elif request['query']['serviceType'] == 'sslvpnService':
+                query_string = 'select count(ActiveSessions) from virtualSiteStats where time > now()-20s group by Id, agent_host;'
+        else:
+            oper_log('error', 'system', "Required fields (serviceType) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (serviceType) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - serviceType) are missing.")
+        raise ge.ANInternalException(parm_name="request_payload", error_code=400,
+                                     description="Required fields (query - serviceType) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_event_detection_stats(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'start_time' in request['query'] and 'end_time' in request['query']:
+            query_string = 'SELECT time, agent_host, server_id, quantity FROM event_detection where time > {} and time < {}'.format(
+                request['query']['start_time'], request['query']['end_time'])
+            if 'product' in request['query']:
+                query_string += " AND product='{}'".format(request['query']['product'])
+            if 'agent_host' in request['query']:
+                query_string += " AND agent_host =~ {}".format(request['query']['agent_host'])
+            if 'server_id' in request['query']:
+                query_string += " AND server_id = '{}'".format(request['query']['server_id'])
+            if 'event_type' in request['query']:
+                query_string += " AND event_type = '{}'".format(request['query']['event_type'])
+            if 'event_name' in request['query']:
+                query_string += " AND event_name = '{}'".format(request['query']['event_name'])
+            query_string += ' GROUP BY event_name, product order by time desc;'
+        else:
+            oper_log('error', 'system', "Required fields (start_time, end_time) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (start_time, end_time) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - start_time, end_time) are missing.")
+        raise ge.ANInternalException(parm_name="query", error_code=400,
+                                     description="Required fields (query - start_time, end_time) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
+
+
+def get_event_detection_stat_quantity(request):
+    req_dict = {
+        "url": "/v1/datasource/proxy/1/query",
+        "path": "db=composer&epoch=ms",
+        "method": "POST",
+        "body": {},
+        "config": {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
+    }
+    query_string = ''
+    if 'query' in request:
+        if 'start_time' in request['query'] and 'end_time' in request['query']:
+            query_string = 'SELECT sum(quantity) FROM event_detection where time > {} and time < {}'.format(
+                request['query']['start_time'], request['query']['end_time'])
+            if 'product' in request['query']:
+                query_string += " AND product='{}'".format(request['query']['product'])
+            if 'agent_host' in request['query']:
+                query_string += " AND agent_host =~ {}".format(request['query']['agent_host'])
+            if 'server_id' in request['query']:
+                query_string += " AND server_id = '{}'".format(request['query']['server_id'])
+            if 'event_type' in request['query']:
+                query_string += " AND event_type = '{}'".format(request['query']['event_type'])
+            if 'event_name' in request['query']:
+                query_string += " AND event_name = '{}'".format(request['query']['event_name'])
+            query_string += ' GROUP BY event_name, product;'
+        else:
+            oper_log('error', 'system', "Required fields (start_time, end_time) are missing.")
+            raise ge.ANInternalException(parm_name="query_payload", error_code=400,
+                                         description="Required fields (start_time, end_time) are missing.")
+    else:
+        oper_log('error', 'system', "Required fields (query - start_time, end_time) are missing.")
+        raise ge.ANInternalException(parm_name="query", error_code=400,
+                                     description="Required fields (query - start_time, end_time) are missing.")
+    query_string = format_query_string(query_string)
+    req_dict["body"] = 'q=' + query_string
+    return req_dict
