Index: /branches/amp_4_0/src/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/webui/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/webui/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/webui/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/webui/webui/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/webui/webui/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/webui/htdocs/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/webui/webui/htdocs/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/__init__.py	(added)
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/__init__.py	(revision 0)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/__init__.py	(revision 0)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/djproject/urls.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/djproject/urls.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/djproject/urls.py	(working copy)
@@ -15,8 +15,9 @@
 from hive.composer import KibanaProxyView, elastic_proxy, reporting_downloading_handler, reporting_logo_handler, composer_config, composer_status, composer_query, composer_proxy
 from hive.storage import storage_mangement
 from hive.log_location import handle_log_location_app
-from hive.device_metrics import handle_device_metrics_req
-from hive.slb_stats import handle_slb_stats_req
+from hive.controller.device_metrics import handle_device_metrics_req
+from hive.controller.slb_stats import handle_slb_stats_req
+from hive.controller.slb_vpn_stats import handle_ssl_vpn_stats_req
 from hive.llb_stats import handle_llb_stats_req
 from hive.report.generate_report import handle_report_generation
 from hive.controller.backup_controller import handle_backup_req
@@ -69,6 +70,7 @@
     re_path(r'^composer_query$', composer_query),
     re_path(r'^apv/slb/(?P<path>.*)$', handle_slb_stats_req),
     re_path(r'^device_metrics(?:/(?P<path>.*))?$', handle_device_metrics_req),
+    re_path(r'^ssl_vpn_stats(?:/(?P<path>.*))?$', handle_ssl_vpn_stats_req),
     re_path(r'^llb/(?P<path>.*)$', handle_llb_stats_req),
     re_path(r'^report/(?P<path>.*)$', handle_report_generation),
     re_path(r'^log/(?P<app>\w+)$', handle_log_location_app),
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/ssl_vpn_stats.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/ssl_vpn_stats.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/ssl_vpn_stats.py	(working copy)
@@ -0,0 +1,48 @@
+from django.http import JsonResponse
+from cm.lib.libbasic_operation import oper_log
+from hive.custom_exceptions import generic_exception as ge
+from hive.services.ssl_vpn_stat_service import fetch_ssl_vpn_stats
+import json
+
+
+def handle_ssl_vpn_stats_req(request, path=None):
+    try:
+        if request.method in ['GET', 'POST']:
+            return get_ssl_vpn_stats(request)
+        else:
+            return JsonResponse({
+                'error': 405,
+                'message': "Invalid HTTP method"
+            }, status=405, content_type='application/json')
+    except ge.GenericError as e:
+        oper_log('error', 'system', e.message)
+        return ge.handle_exception(e)
+    except Exception as e:
+        oper_log('error', 'system', 'An Unexpected error occurred,  details: {}'.format(e))
+        e.message = 'An Unexpected error occurred,  details: {}'.format(e)
+        return ge.handle_exception(e)
+
+
+def get_ssl_vpn_stats(request):
+    """ Fetch the SSL VPN data """
+    try:
+        req_body = json.loads(request.body)
+        if 'query' in req_body and 'agent_host' not in req_body['query']:
+            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
+                                        "query.")
+            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
+                                       "query.")
+        agent_host = req_body.get("agent_host", None)
+        interval = req_body.get("interval", "1m")
+        vsite_id = req_body.get("vsite_id", None)
+        time_from = req_body.get("from", None)
+        time_to = req_body.get("to", None)
+        stat_name = req_body.get("stat_name", None)
+        json_response = fetch_ssl_vpn_stats(agent_host, vsite_id, interval, stat_name, time_from, time_to)
+
+        return JsonResponse(json_response)
+
+    except Exception as e:
+        return JsonResponse({
+            "error": str(e)
+        }, status=500)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/device_metric_queries.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/device_metric_queries.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/device_metric_queries.py	(working copy)
@@ -1,4 +1,3 @@
-from hive.db.utils import Utils
 
 from hive.db.db_client import DBClient
 from hive.utils import andebug
@@ -11,8 +10,6 @@
         """
         Fetch latest CPU, MEM, NET_MEM, Connections per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
@@ -22,8 +19,8 @@
                 (last(net_mem_usage, time)) AS net_mem,
                 (last(connections, time)) AS connections
             FROM an_device_metrics
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
             GROUP BY agent_host;
         """
 
@@ -35,19 +32,17 @@
         """
         Fetch throughput (received/sent in bps) per agent_host over time buckets
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             WITH bucketed AS (
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     agent_host,
                     first(total_in, time)::double precision AS total_in,
                     first(total_out, time)::double precision AS total_out
                 FROM an_device_metrics
-                WHERE time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
                 GROUP BY ts, agent_host
             )
             SELECT
@@ -77,17 +72,15 @@
         """
         CPU mean over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     agent_host,
                     AVG(cpu_usage) AS cpu
                 FROM an_device_metrics
-                WHERE time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
                   AND agent_host = '{agent_host}'
                 GROUP BY ts, agent_host
                 ORDER BY ts;
@@ -100,18 +93,16 @@
         """
         Memory metrics over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 agent_host,
                 COALESCE(AVG(mem_usage), 0) AS memory_usage,
                 COALESCE(AVG(net_mem_usage), 0) AS network_mem_usage
             FROM an_device_metrics
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND agent_host = '{agent_host}'
             GROUP BY ts, agent_host
             ORDER BY ts;
@@ -124,17 +115,15 @@
         """
         Disk usage percentage over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 agent_host,
                 COALESCE(AVG(used) * 100.0 / NULLIF(AVG(size), 0), 0) AS disk_usage
             FROM an_device_storage
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND agent_host = '{agent_host}'
             GROUP BY ts, agent_host
             ORDER BY ts;
@@ -147,8 +136,6 @@
         """
         Network throughput (bits/sec) over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
@@ -170,13 +157,13 @@
                 ) AS received
             FROM (
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     agent_host,
                     first(total_out, time) AS total_out,
                     first(total_in, time)  AS total_in
                 FROM an_device_metrics
-                WHERE time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
                   AND agent_host = '{agent_host}'
                 GROUP BY ts, agent_host
             ) subq
@@ -190,17 +177,15 @@
         """
         SSL connections (sum of total_openssl_conns) over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 agent_host,
                 SUM(total_openssl_conns) AS ssl_connection
             FROM an_device_metrics
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND agent_host = '{agent_host}'
             GROUP BY ts, agent_host
             ORDER BY ts;
@@ -213,17 +198,15 @@
         """
         Average active connections over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 agent_host,
                 AVG(connections) AS connection
             FROM an_device_metrics
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND agent_host = '{agent_host}'
             GROUP BY ts, agent_host
             ORDER BY ts;
@@ -236,17 +219,15 @@
         """
         Average active requests over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     agent_host,
                     AVG(requests) AS connection
                 FROM an_device_metrics
-                WHERE time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
                   AND agent_host = '{agent_host}'
                 GROUP BY ts, agent_host
                 ORDER BY ts;
@@ -259,18 +240,16 @@
         """
         SSL AE and SE core utilization (mean) over time buckets per agent_host
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 agent_host,
                 AVG(ssl_ae_core_utilization) AS ssl_ae_core,
                 AVG(ssl_se_core_utilization) AS ssl_se_core
             FROM an_device_performance
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND agent_host = '{agent_host}'
             GROUP BY ts, agent_host
             ORDER BY ts;
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/slb_stats_queries.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/slb_stats_queries.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/slb_stats_queries.py	(working copy)
@@ -1,7 +1,6 @@
 from hive.db.db_client import DBClient
 from hive.custom_exceptions import generic_exception as ge
 from hive.utils import andebug
-from hive.db.utils import Utils
 
 
 class SLBStats:
@@ -70,19 +69,17 @@
         """
         Fetch network throughput (Sent, Received) from apv_virtual_stats
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
                     SELECT
-                        time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                        time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                         avg(in_byte_per_sec) AS received,
                         avg(out_byte_per_sec) AS sent
                     FROM apv_virtual_stats
                     WHERE agent_host ~ %s
                       AND serverid ~ %s
-                      AND time >= {time_from_sql}
-                      AND time <= {time_to_sql}
+                      AND time >= {time_from}
+                      AND time <= {time_to}
                     GROUP BY ts
                     ORDER BY ts;
                 """
@@ -101,12 +98,9 @@
         Uses MAX - MIN per time bucket to calculate increments, avoids NULLs.
         """
 
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
-
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 COALESCE(
                     MAX(
                         url_hits + hostname_hits + perstnt_cookie_hits + qos_cookie_hits +
@@ -124,8 +118,8 @@
                     ),
                 0) AS hit_diff
             FROM apv_virtual_stats
-            WHERE time >= {time_from_sql}
-              AND time <= {time_to_sql}
+            WHERE time >= {time_from}
+              AND time <= {time_to}
               AND serverid ~ %s
               AND agent_host ~ %s
             GROUP BY ts
@@ -147,8 +141,6 @@
         Fetch Hits Distribution from apv_virtual_stats.
         For each hit type, we compute: MAX(value) - MIN(value) in the given range.
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
@@ -174,8 +166,8 @@
             FROM apv_virtual_stats
             WHERE agent_host ~ %s
               AND serverid ~ %s
-              AND time >= {time_from_sql}
-              AND time <= {time_to_sql};
+              AND time >= {time_from}
+              AND time <= {time_to};
         """
 
         params = [agent_host, virtual_server_id]
@@ -192,18 +184,16 @@
         """
         Fetch connection count (average of ConnCnt over time buckets) from apv_virtual_stats
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     COALESCE(SUM(conn_cnt), 0) AS connections
                 FROM apv_virtual_stats
                 WHERE agent_host ~ %s
                   AND serverid ~ %s
-                  AND time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                  AND time >= {time_from}
+                  AND time <= {time_to}
                 GROUP BY ts
                 ORDER BY ts;
             """
@@ -222,18 +212,16 @@
         """
         Fetch average connections per second (ConnPerSec) over time buckets from apv_virtual_stats
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 avg(conn_per_sec) AS connection
             FROM apv_virtual_stats
             WHERE agent_host ~ %s
               AND serverid ~ %s
-              AND time >= {time_from_sql}
-              AND time <= {time_to_sql}
+              AND time >= {time_from}
+              AND time <= {time_to}
             GROUP BY ts
             ORDER BY ts;
         """
@@ -304,19 +292,16 @@
         Fetch network throughput (Sent, Received) from apv_real_stats
         """
 
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
-
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 COALESCE(avg(rs_in_byte_per_sec), 0) * 8 AS received,
                 COALESCE(avg(rs_out_byte_per_sec), 0) * 8 AS sent
             FROM apv_real_stats
             WHERE agent_host ~ %s
               AND real_server_id ~ %s
-              AND time >= {time_from_sql}
-              AND time <= {time_to_sql}
+              AND time >= {time_from}
+              AND time <= {time_to}
             GROUP BY ts
             ORDER BY ts;
         """
@@ -334,18 +319,15 @@
         Fetch Outstanding Requests (sum of rsCntOfReq) from apv_real_stats
         """
 
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
-
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 sum(rs_cnt_of_req) AS request
             FROM apv_real_stats
             WHERE agent_host ~ %s
               AND real_server_id ~ %s
-              AND time >= {time_from_sql}
-              AND time <= {time_to_sql}
+              AND time >= {time_from}
+              AND time <= {time_to}
             GROUP BY ts
             ORDER BY ts;
         """
@@ -363,18 +345,15 @@
         Fetch Requests Number (Hits per interval) from apv_real_stats
         """
 
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
-
         query = f"""
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     COALESCE(MAX(rs_total_hits) - MIN(rs_total_hits), 0) AS hits
                 FROM apv_real_stats
                 WHERE agent_host ~ %s
                   AND real_server_id ~ %s
-                  AND time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                  AND time >= {time_from}
+                  AND time <= {time_to}
                 GROUP BY ts
                 ORDER BY ts;
             """
@@ -391,18 +370,16 @@
         """
         Fetch connection count (average of rs_conn_cnt over time buckets) from apv_real_stats
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
                 SELECT
-                    time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                     COALESCE(MAX(rs_conn_cnt)::INT, 0) AS connections_per_sec
                 FROM apv_real_stats
                 WHERE agent_host ~ %s
                   AND real_server_id ~ %s
-                  AND time >= {time_from_sql}
-                  AND time <= {time_to_sql}
+                  AND time >= {time_from}
+                  AND time <= {time_to}
                 GROUP BY ts
                 ORDER BY ts;
             """
@@ -421,18 +398,16 @@
         """
         Fetch average connections per second (rs_conn_per_sec) from apv_real_stats
         """
-        time_from_sql = Utils.convert_time(time_from, "now() - interval '15 minutes'")
-        time_to_sql = Utils.convert_time(time_to, "now()")
 
         query = f"""
             SELECT
-                time_bucket_gapfill('{interval}', time, {time_from_sql}, {time_to_sql}) AS ts,
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
                 COALESCE(AVG(rs_conn_per_sec), 0) AS connections
             FROM apv_real_stats
             WHERE agent_host ~ %s
               AND real_server_id ~ %s
-              AND time >= {time_from_sql}
-              AND time <= {time_to_sql}
+              AND time >= {time_from}
+              AND time <= {time_to}
             GROUP BY ts
             ORDER BY ts;
         """
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/ssl_vpn_stat_queries.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/ssl_vpn_stat_queries.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/ssl_vpn_stat_queries.py	(working copy)
@@ -0,0 +1,291 @@
+from hive.db.db_client import DBClient
+from hive.utils import andebug
+
+
+class SSLVpnStatQueries:
+
+    @staticmethod
+    def get_active_sessions(agent_host):
+        """
+        Get the latest active_sessions in the last 20 seconds for each (id, agent_host, ip)
+        """
+
+        if agent_host:
+            query = f"""
+                SELECT DISTINCT ON (id, agent_host, ip)
+                   CAST(active_sessions AS BIGINT)
+                FROM ag_virtual_site_stats
+                WHERE agent_host = '{agent_host}'
+                  AND time > now() - interval '20 seconds'
+                ORDER BY id, agent_host, ip, time DESC;
+            """
+        else:
+            query = f"""
+                SELECT DISTINCT ON (id, agent_host, ip)
+                    CAST(active_sessions AS BIGINT)
+                FROM ag_virtual_site_stats
+                WHERE time > now() - interval '20 seconds'
+                ORDER BY id, agent_host, ip, time DESC;
+            """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_login_stats(agent_host, vsite_id, interval="1m", time_from="now() - interval '15 minutes'",
+                        time_to="now()"):
+        """
+        Get login stats (Success, Failure, Error, Locked, Rejected) over time buckets
+        """
+
+        query = f"""
+            SELECT
+                time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
+                agent_host,
+                id,
+                CAST(COALESCE(MAX(success_login) - MIN(success_login), 0) AS BIGINT) AS success,
+                CAST(COALESCE(MAX(failure_login) - MIN(failure_login), 0) AS BIGINT) AS failure,
+                CAST(COALESCE(MAX(error_login) - MIN(error_login), 0) AS BIGINT) AS error,
+                CAST(COALESCE(MAX(locked_login) - MIN(locked_login), 0) AS BIGINT) AS locked,
+                CAST(COALESCE(MAX(rejected_login) - MIN(rejected_login), 0) AS BIGINT) AS rejected
+            FROM ag_virtual_site_stats
+            WHERE time >= {time_from}
+              AND time <= {time_to}
+              AND agent_host = '{agent_host}'
+              AND id = '{vsite_id}'
+            GROUP BY ts, agent_host, id
+            ORDER BY ts;
+        """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_net_throughput_stats(agent_host, vsite_id,
+                                 interval="20s",
+                                 time_from="now() - interval '15 minutes'",
+                                 time_to="now()"):
+        """
+        Get bandwidth stats (Sent/Received bits per second) over time buckets
+        """
+        query = f"""
+                SELECT
+                    time_bucket_gapfill('{interval}', time, {time_from}, {time_to}) AS ts,
+                    agent_host,
+                    id,
+                    ROUND(COALESCE(
+                        (MAX("client_bytes_out") - MIN("client_bytes_out")) * 8 
+                        / GREATEST(EXTRACT(EPOCH FROM (MAX(time) - MIN(time))), 1)
+                        )::numeric, 2
+                    ) AS nw_sent_bps,
+                    ROUND(COALESCE(
+                        (MAX("client_bytes_in") - MIN("client_bytes_in")) * 8
+                        / GREATEST(EXTRACT(EPOCH FROM (MAX(time) - MIN(time))), 1)
+                        )::numeric, 2
+                    ) AS nw_recv_bps
+                FROM ag_virtual_site_stats
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
+                  AND agent_host = '{agent_host}'
+                  AND id = '{vsite_id}'
+                GROUP BY ts, agent_host, id
+                ORDER BY ts;
+            """
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_l3_tunnel_stats(agent_host, vsite_id, time_from="now() - interval '15 minutes'", time_to="now()"):
+        """
+        Get VPN tunnel stats (Open, Est, Rejected, Terminated) as deltas
+        """
+
+        query = f"""
+            SELECT
+                agent_host,
+                id,
+                CAST((MAX(tunnels_open) - MIN(tunnels_open)) AS BIGINT)        AS open,
+                CAST((MAX(tunnels_est) - MIN(tunnels_est)) AS BIGINT)          AS est,
+                CAST((MAX(tunnels_rejected) - MIN(tunnels_rejected)) AS BIGINT) AS rejected,
+                CAST((MAX(tunnels_terminated) - MIN(tunnels_terminated)) AS BIGINT) AS terminated
+            FROM ag_vpn_stats
+            WHERE time >= {time_from}
+              AND time <= {time_to}
+              AND agent_host = '{agent_host}'
+              AND id = '{vsite_id}'
+            GROUP BY agent_host, id
+            ORDER BY agent_host, id;
+        """
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_l3_vpn_throughput(agent_host, vsite_id, interval="20s",
+                           time_from="now() - interval '15 minutes'", time_to="now()"):
+        """
+        Get VPN throughput (sent_bps, recv_bps) over time buckets
+        """
+
+        query = f"""
+            SELECT
+                time_bucket('{interval}', time) AS ts,
+                agent_host,
+                id,
+                ROUND((
+                    (MAX(bytes_out) - MIN(bytes_out)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS vpn_sent_bps,
+                ROUND((
+                    (MAX(bytes_in) - MIN(bytes_in)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS vpn_recv_bps
+            FROM ag_vpn_stats
+            WHERE time >= {time_from}
+              AND time <= {time_to}
+              AND agent_host = '{agent_host}'
+              AND id = '{vsite_id}'
+            GROUP BY ts, agent_host, id
+            ORDER BY ts;
+        """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_l3_client_app_throughput(agent_host, vsite_id, interval="20s",
+                                  time_from="now() - interval '15 minutes'", time_to="now()"):
+        """
+        Get VPN Client Application throughput (sent_bps, recv_bps) over time buckets
+        """
+
+        query = f"""
+            SELECT
+                time_bucket('{interval}', time) AS ts,
+                agent_host,
+                id,
+                ROUND((
+                    (MAX(client_app_bytes_out) - MIN(client_app_bytes_out)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS client_app_sent_bps,
+                ROUND((
+                    (MAX(client_app_bytes_in) - MIN(client_app_bytes_in)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS client_app_recv_bps
+            FROM ag_vpn_stats
+            WHERE time >= {time_from}
+              AND time <= {time_to}
+              AND agent_host = '{agent_host}'
+              AND id = '{vsite_id}'
+            GROUP BY ts, agent_host, id
+            ORDER BY ts;
+        """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_l7_request_status(agent_host, vsite_id, interval="20s",
+                           time_from="now() - interval '15 minutes'",
+                           time_to="now()"):
+        """
+        Get L7 Request Status throughput (Sent bps, Received bps) over time buckets
+        """
+
+        query = f"""
+               SELECT
+                   time_bucket('{interval}', time) AS ts,
+                   agent_host,
+                   id,
+                   ROUND((
+                       (MAX(client_bytes_out) - MIN(client_bytes_out)) * 8 /
+                       GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                       )
+                   ::numeric, 2) AS sent_bps,
+                   ROUND((
+                       (MAX(client_bytes_in) - MIN(client_bytes_in)) * 8 /
+                       GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                       )
+                   ::numeric, 2) AS recv_bps
+               FROM ag_web_stats
+               WHERE time >= {time_from}
+                 AND time <= {time_to}
+                 AND agent_host = '{agent_host}'
+                 AND id = '{vsite_id}'
+               GROUP BY ts, agent_host, id
+               ORDER BY ts;
+           """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    @staticmethod
+    def get_l7_client_throughput(agent_host, vsite_id, interval="20s",
+                                 time_from="now() - interval '15 minutes'",
+                                 time_to="now()"):
+        """
+        Get L7 Client Throughput (Sent bps, Received bps) over time buckets
+        """
+
+        query = f"""
+                SELECT
+                    time_bucket('{interval}', time) AS ts,
+                    agent_host,
+                    id,
+                    ROUND((
+                        (MAX(client_bytes_out) - MIN(client_bytes_out)) * 8 /
+                        GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )::numeric, 2) AS client_sent_bps,
+                    ROUND((
+                        (MAX(client_bytes_in) - MIN(client_bytes_in)) * 8 /
+                        GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                        )
+                    ::numeric, 2) AS client_recv_bps
+                FROM ag_web_stats
+                WHERE time >= {time_from}
+                  AND time <= {time_to}
+                  AND agent_host = '{agent_host}'
+                  AND id = '{vsite_id}'
+                GROUP BY ts, agent_host, id
+                ORDER BY ts;
+            """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
+
+    def get_l7_server_throughput(agent_host, vsite_id, interval="20s",
+                                 time_from="now() - interval '15 minutes'",
+                                 time_to="now()"):
+        """
+        Get L7 Server Throughput (Sent bps, Received bps) over time buckets
+        """
+
+        query = f"""
+            SELECT
+                time_bucket('{interval}', time) AS ts,
+                agent_host,
+                id,
+                ROUND((
+                    (MAX(server_bytes_out) - MIN(server_bytes_out)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS server_sent_bps,
+                ROUND((
+                    (MAX(server_bytes_in) - MIN(server_bytes_in)) * 8 /
+                    GREATEST(1, EXTRACT(EPOCH FROM MAX(time) - MIN(time)))
+                    )
+                ::numeric, 2) AS server_recv_bps
+            FROM ag_web_stats
+            WHERE time >= {time_from}
+              AND time <= {time_to}
+              AND agent_host = '{agent_host}'
+              AND id = '{vsite_id}'
+            GROUP BY ts, agent_host, id
+            ORDER BY ts;
+        """
+
+        req = {"query": query}
+        return DBClient.execute_query(req)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/utils.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/utils.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/db/utils.py	(nonexistent)
@@ -1,30 +0,0 @@
-import dateutil
-from hive.custom_exceptions import generic_exception as ge
-
-class Utils:
-    @staticmethod
-    def convert_time(value, default):
-        if not value:
-            return default
-        if isinstance(value, str):
-            if value.startswith("now"):
-                # handle relative formats like "now-15m", "now-1h"
-                if "-" in value:
-                    value = value.split("-")[1]
-                    num = int(''.join([c for c in value if c.isdigit()]))
-                    unit = ''.join([c for c in value if c.isalpha()])
-                    if unit == "m":
-                        return f"now() - interval '{num} minutes'"
-                    elif unit == "h":
-                        return f"now() - interval '{num} hours'"
-                    elif unit == "d":
-                        return f"now() - interval '{num} days'"
-                return "now()"
-            else:
-                # Assume ISO8601 timestamp
-                try:
-                    dt = dateutil.parser.isoparse(value)
-                    return f"'{dt.strftime('%Y-%m-%d %H:%M:%S')}'"
-                except Exception:
-                    raise ge.GenericError(400, f"Invalid time format: {value}")
-        return default
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/device_metrics.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/device_metrics.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/device_metrics.py	(working copy)
@@ -0,0 +1,48 @@
+from django.http import JsonResponse
+from hive.services.device_metrics_service import fetch_device_metrics
+from cm.lib.libbasic_operation import oper_log
+from hive.custom_exceptions import generic_exception as ge
+import json
+from hive.utils import andebug
+
+
+def handle_device_metrics_req(request, path=None):
+    try:
+        if request.method in ['GET', 'POST']:
+            return get_device_metrics(request)
+        else:
+            return JsonResponse({
+                'error': 405,
+                'message': "Invalid HTTP method"
+            }, status=405, content_type='application/json')
+    except ge.GenericError as e:
+        oper_log('error', 'system', e.message)
+        return ge.handle_exception(e)
+    except Exception as e:
+        oper_log('error', 'system', 'An Unexpected error occurred,  details: {}'.format(e))
+        e.message = 'An Unexpected error occurred,  details: {}'.format(e)
+        return ge.handle_exception(e)
+
+
+def get_device_metrics(request):
+    """ Fetch the device metrics data """
+    try:
+        req_body = json.loads(request.body)
+        if 'query' in req_body and 'agent_host' not in req_body['query']:
+            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
+                                        "query.")
+            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
+                                       "query.")
+        agent_host = req_body.get("agent_host", None)
+        interval = req_body.get("interval", "1m")
+        time_from = req_body.get("from", None)
+        time_to = req_body.get("to", None)
+        metric_name = req_body.get("metric_name", None)
+        json_response = fetch_device_metrics(agent_host, interval, metric_name, time_from, time_to)
+
+        return JsonResponse(json_response)
+
+    except Exception as e:
+        return JsonResponse({
+            "error": str(e)
+        }, status=500)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/device_metrics.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/device_metrics.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/device_metrics.py	(nonexistent)
@@ -1,110 +0,0 @@
-from django.http import JsonResponse
-
-from cm.lib.libbasic_operation import oper_log
-from hive.custom_exceptions import generic_exception as ge
-from hive.db.slb_stats_queries import SLBStats
-from hive.db.device_metric_queries import DeviceMetrics
-import json
-from hive.utils import andebug
-
-
-def handle_device_metrics_req(request, path=None):
-    try:
-        if request.method in ['GET', 'POST']:
-            return get_device_metrics(request)
-        else:
-            return JsonResponse({
-                'error': 405,
-                'message': "Invalid HTTP method"
-            }, content_type='application/json')
-    except ge.GenericError as e:
-        oper_log('error', 'system', e.message)
-        return ge.handle_exception(e)
-    except Exception as e:
-        oper_log('error', 'system', 'An Unexpected error occurred,  details: {}'.format(e))
-        e.message = 'An Unexpected error occurred,  details: {}'.format(e)
-        return ge.handle_exception(e)
-
-
-def get_device_metrics(request):
-    """ Fetch the device metrics data """
-    try:
-        req_body = json.loads(request.body)
-        if 'query' in req_body and 'agent_host' not in req_body['query']:
-            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
-                                        "query.")
-            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
-                                       "query.")
-        agent_host = req_body.get("agent_host", None)
-        interval = req_body.get("interval", "1m")
-        time_from = req_body.get("from", None)
-        time_to = req_body.get("to", None)
-        metric_name = req_body.get("metric_name", None)
-        json_response = {}
-
-        if metric_name and metric_name == 'cpu_usage':
-            metrics = DeviceMetrics.get_cpu_usage_metrics(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name and metric_name == 'memory_usage':
-            metrics = DeviceMetrics.get_mem_usage_metrics(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name and metric_name == 'disk_usage':
-            metrics = DeviceMetrics.get_disk_usage_metrics(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name and metric_name == 'network_throughput':
-            metrics = DeviceMetrics.get_network_throughput(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name == "ssl_connections":
-            metrics = DeviceMetrics.get_ssl_connections(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name == "connections":
-            metrics = DeviceMetrics.get_connections(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name == "requests":
-            metrics = DeviceMetrics.get_requests(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        elif metric_name == "ssl_core_utilization":
-            metrics = DeviceMetrics.get_ssl_core_utilization(agent_host, interval, time_from, time_to)
-            json_response = {
-                "status": 1,
-                "data": metrics
-            }
-        else:
-            device_stats = DeviceMetrics.get_device_stats(time_from, time_to)['data']
-            net_throughput = DeviceMetrics.get_throughput_data(interval, time_from, time_to)['data']
-            json_response = {
-                "status": 1,
-                "data": {
-                    "device_stats": device_stats,
-                    "net_throughput": net_throughput
-                }
-            }
-
-        return JsonResponse(json_response)
-
-    except Exception as e:
-        return JsonResponse({
-            "status": 0,
-            "error": str(e)
-        }, status=500)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/device_metrics_service.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/device_metrics_service.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/device_metrics_service.py	(working copy)
@@ -0,0 +1,42 @@
+from hive.db.device_metric_queries import DeviceMetrics
+from hive.db.utils import Utils
+from hive.services.utils import construct_json_response, convert_time
+
+
+def fetch_device_metrics(agent_host, interval, metric_name, time_from, time_to):
+    time_from = convert_time(time_from, "now() - interval '15 minutes'")
+    time_to = convert_time(time_to, "now()")
+
+    json_response = {}
+    if metric_name and metric_name == 'cpu_usage':
+        metrics = DeviceMetrics.get_cpu_usage_metrics(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name and metric_name == 'memory_usage':
+        metrics = DeviceMetrics.get_mem_usage_metrics(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name and metric_name == 'disk_usage':
+        metrics = DeviceMetrics.get_disk_usage_metrics(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name and metric_name == 'network_throughput':
+        metrics = DeviceMetrics.get_network_throughput(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name == "ssl_connections":
+        metrics = DeviceMetrics.get_ssl_connections(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name == "connections":
+        metrics = DeviceMetrics.get_connections(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name == "requests":
+        metrics = DeviceMetrics.get_requests(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    elif metric_name == "ssl_core_utilization":
+        metrics = DeviceMetrics.get_ssl_core_utilization(agent_host, interval, time_from, time_to)
+        json_response = construct_json_response(json_response, metrics)
+    else:
+        device_stats = DeviceMetrics.get_device_stats(time_from, time_to)['data']
+        net_throughput = DeviceMetrics.get_throughput_data(interval, time_from, time_to)['data']
+        json_response = construct_json_response(json_response, {
+            "device_stats": device_stats,
+            "net_throughput": net_throughput
+        })
+    return json_response
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/slb_stats_service.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/slb_stats_service.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/slb_stats_service.py	(working copy)
@@ -0,0 +1,41 @@
+from hive.db.slb_stats_queries import SLBStats
+from hive.db.utils import Utils
+from hive.services.utils import convert_time
+
+
+def fetch_virtual_stats(agent_host, interval, req, server_id, time_from, time_to):
+    time_from = convert_time(time_from, "now() - interval '15 minutes'")
+    time_to = convert_time(time_to, "now()")
+
+    if "stat_name" in req and req["stat_name"] == "network_throughput":
+        response = SLBStats.get_network_throughput(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req and req["stat_name"] == "total_hits":
+        response = SLBStats.get_total_hits(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req and req["stat_name"] == "hits_distribution":
+        response = SLBStats.get_hits_distribution(agent_host, server_id, time_from, time_to)
+    elif req.get("stat_name") == "connection_count":
+        response = SLBStats.get_connection_count(agent_host, server_id, interval, time_from, time_to)
+    elif req.get("stat_name") == "connections_per_sec":
+        response = SLBStats.get_connections_per_sec(agent_host, server_id, interval, time_from, time_to)
+    else:
+        response = SLBStats.get_virtual_service_stats(agent_host)
+    return response
+
+
+def fetch_real_stats(agent_host, interval, req_body, server_id, time_from, time_to):
+    time_from = convert_time(time_from, "now() - interval '15 minutes'")
+    time_to = convert_time(time_to, "now()")
+
+    if "stat_name" in req_body and req_body["stat_name"] == "network_throughput":
+        response = SLBStats.get_real_network_throughput(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req_body and req_body["stat_name"] == "outstanding_requests":
+        response = SLBStats.get_outstanding_requests(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req_body and req_body["stat_name"] == "hits":
+        response = SLBStats.get_real_stats_total_hits(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req_body and req_body["stat_name"] == "connection_count":
+        response = SLBStats.get_real_connection_count(agent_host, server_id, interval, time_from, time_to)
+    elif "stat_name" in req_body and req_body["stat_name"] == "connections_per_sec":
+        response = SLBStats.get_real_connections_per_sec(agent_host, server_id, interval, time_from, time_to)
+    else:
+        response = SLBStats.get_real_service_stats(agent_host)
+    return response
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/ssl_vpn_stat_Service.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/ssl_vpn_stat_Service.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/ssl_vpn_stat_Service.py	(working copy)
@@ -0,0 +1,30 @@
+from hive.db.ssl_vpn_stat_queries import SSLVpnStatQueries
+from hive.services.utils import construct_json_response, convert_time
+
+
+def fetch_ssl_vpn_stats(agent_host, vsite_id, interval, stat_name, time_from, time_to):
+    time_from = convert_time(time_from, "now() - interval '15 minutes'")
+    time_to = convert_time(time_to, "now()")
+
+    json_response = {}
+    if stat_name == 'login_status':
+        stats = SSLVpnStatQueries.get_login_stats(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'net_thoughput':
+        stats = SSLVpnStatQueries.get_net_throughput_stats(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'l3_tunnel_status':
+        stats = SSLVpnStatQueries.get_l3_tunnel_stats(agent_host, vsite_id, time_from, time_to)
+    elif stat_name == 'l3_vpn_throughput':
+        stats = SSLVpnStatQueries.get_l3_vpn_throughput(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'l3_client_app_throughput':
+        stats = SSLVpnStatQueries.get_l3_client_app_throughput(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'l7_request_status':
+        stats = SSLVpnStatQueries.get_l7_request_status(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'l7_client_throughput':
+        stats = SSLVpnStatQueries.get_l7_client_throughput(agent_host, vsite_id, interval, time_from, time_to)
+    elif stat_name == 'l7_server_throughput':
+        stats = SSLVpnStatQueries.get_l7_server_throughput(agent_host, vsite_id, interval, time_from, time_to)
+    else:
+        stats = SSLVpnStatQueries.get_active_sessions(agent_host)
+    json_response = construct_json_response(json_response, stats)
+    return json_response
+
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/utils.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/utils.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/services/utils.py	(working copy)
@@ -1,5 +1,6 @@
 import json
 import os
+import dateutil
 
 from django.http import HttpResponse
 
@@ -30,3 +31,37 @@
             "message": "while fetching observability services status",
             "details": "{}".format(message)
         }), content_type="application/json", status=500)
+
+
+def construct_json_response(json_response, metrics):
+    json_response = {
+        "data": metrics["data"]
+    }
+    return json_response
+
+
+def convert_time(value, default):
+    if not value:
+        return default
+    if isinstance(value, str):
+        if value.startswith("now"):
+            # handle relative formats like "now-15m", "now-1h"
+            if "-" in value:
+                value = value.split("-")[1]
+                num = int(''.join([c for c in value if c.isdigit()]))
+                unit = ''.join([c for c in value if c.isalpha()])
+                if unit == "m":
+                    return f"now() - interval '{num} minutes'"
+                elif unit == "h":
+                    return f"now() - interval '{num} hours'"
+                elif unit == "d":
+                    return f"now() - interval '{num} days'"
+            return "now()"
+        else:
+            # Assume ISO8601 timestamp
+            try:
+                dt = dateutil.parser.isoparse(value)
+                return f"'{dt.strftime('%Y-%m-%d %H:%M:%S')}'"
+            except Exception:
+                raise ge.GenericError(400, f"Invalid time format: {value}")
+    return default
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/slb_stats.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/slb_stats.py	(nonexistent)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/controller/slb_stats.py	(working copy)
@@ -0,0 +1,86 @@
+from django.http import JsonResponse
+from hive.services.slb_stats_service import fetch_virtual_stats, fetch_real_stats
+from cm.lib.libbasic_operation import oper_log
+from hive.custom_exceptions import generic_exception as ge
+from hive.utils import andebug
+import json
+
+
+def handle_slb_stats_req(request, path=None):
+    try:
+        if path == 'virtual_stats' and request.method in ['GET', 'POST']:
+            return get_virtual_service_stats(request)
+        elif path == 'real_stats' and request.method in ['GET', 'POST']:
+            return get_real_service_stats(request)
+        else:
+            return JsonResponse({
+                'error': 405,
+                'message': "Invalid HTTP method"
+            }, status=405, content_type='application/json')
+    except ge.GenericError as e:
+        oper_log('error', 'system', e.message)
+        return ge.handle_exception(e)
+    except Exception as e:
+        oper_log('error', 'system', 'An Unexpected error occurred,  details: {}'.format(e))
+        e.message = 'An Unexpected error occurred,  details: {}'.format(e)
+        return ge.handle_exception(e)
+
+
+def get_virtual_service_stats(request):
+    """ Fetch data for SLB Virtual stats data """
+    try:
+        req = {}
+        req = json.loads(request.body)
+        if 'query' in req and 'agent_host' not in req['query']:
+            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
+                                        "query.")
+            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
+                                       "query.")
+
+        agent_host = req.get("agent_host")
+        server_id = req.get("server_id", None)
+        interval = req.get("interval", "20s")
+        time_from = req.get("from")
+        time_to = req.get("to")
+        if not agent_host:
+            raise ge.GenericError(400, "agent_host field is required for Network Throughput stats")
+
+        response = fetch_virtual_stats(agent_host, interval, req, server_id, time_from, time_to)
+
+        return JsonResponse({
+            "data": response["data"]
+        })
+    except Exception as e:
+        return JsonResponse({
+            "error": str(e)
+        }, status=500)
+
+
+def get_real_service_stats(request):
+    """
+    Fetch data for SLB Real stats data
+    """
+    try:
+        req_body = json.loads(request.body)
+
+        if 'query' in req_body and 'agent_host' not in req_body['query']:
+            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
+                                        "query.")
+            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
+                                       "query.")
+        agent_host = req_body.get("agent_host", None)
+        server_id = req_body.get("server_id", None)
+        interval = req_body.get("interval", "1m")
+        time_from = req_body.get("from", None)
+        time_to = req_body.get("to", None)
+
+        response = fetch_real_stats(agent_host, interval, req_body, server_id, time_from, time_to)
+
+        return JsonResponse({
+            "data": response["data"]
+        })
+
+    except Exception as e:
+        return JsonResponse({
+            "error": str(e)
+        }, status=500)
Index: /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/slb_stats.py
===================================================================
--- /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/slb_stats.py	(revision 2707)
+++ /branches/amp_4_0/src/webui/webui/htdocs/new/src/hive/slb_stats.py	(nonexistent)
@@ -1,113 +0,0 @@
-from django.http import JsonResponse
-
-from cm.lib.libbasic_operation import oper_log
-from hive.custom_exceptions import generic_exception as ge
-from hive.db.slb_stats_queries import SLBStats
-from hive.utils import andebug
-import json
-
-
-def handle_slb_stats_req(request, path=None):
-    try:
-        if path == 'virtual_stats' and request.method in ['GET', 'POST']:
-            return get_virtual_service_stats(request)
-        elif path == 'real_stats' and request.method in ['GET', 'POST']:
-            return get_real_service_stats(request)
-        else:
-            return JsonResponse({
-                'error': 405,
-                'message': "Invalid HTTP method"
-            }, content_type='application/json')
-    except ge.GenericError as e:
-        oper_log('error', 'system', e.message)
-        return ge.handle_exception(e)
-    except Exception as e:
-        oper_log('error', 'system', 'An Unexpected error occurred,  details: {}'.format(e))
-        e.message = 'An Unexpected error occurred,  details: {}'.format(e)
-        return ge.handle_exception(e)
-
-
-def get_virtual_service_stats(request):
-    """ Fetch data for SLB Virtual stats data """
-    try :
-        req = {}
-        req = json.loads(request.body)
-        if 'query' in req and 'agent_host' not in req['query']:
-            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
-                                        "query.")
-            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
-                                   "query.")
-
-        agent_host = req.get("agent_host")
-        server_id = req.get("server_id", None)
-        interval = req.get("interval", "20s")
-        time_from = req.get("from")
-        time_to = req.get("to")
-        if not agent_host:
-            raise ge.GenericError(400, "agent_host field is required for Network Throughput stats")
-
-        if "stat_name" in req and req["stat_name"] == "network_throughput":
-            response = SLBStats.get_network_throughput(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req and req["stat_name"] == "total_hits":
-            response = SLBStats.get_total_hits(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req and req["stat_name"] == "hits_distribution":
-            response = SLBStats.get_hits_distribution(agent_host, server_id, time_from, time_to)
-        elif req.get("stat_name") == "connection_count":
-            response = SLBStats.get_connection_count(agent_host, server_id, interval, time_from, time_to)
-        elif req.get("stat_name") == "connections_per_sec":
-            response = SLBStats.get_connections_per_sec(agent_host, server_id, interval, time_from, time_to)
-        else:
-            response = SLBStats.get_virtual_service_stats(agent_host)
-
-        return JsonResponse({
-            "status": 1,
-            "data": response
-        })
-    except Exception as e:
-        return JsonResponse({
-            "status": 0,
-            "error": str(e)
-        }, status=500)
-
-
-def get_real_service_stats(request):
-    """
-    Fetch data for SLB Real stats data
-    """
-    try:
-        req_body = json.loads(request.body)
-
-        if 'query' in req_body and 'agent_host' not in req_body['query']:
-            oper_log('error', 'system', "Query must contain only agent_host details. Please specify agent_host in the "
-                                        "query.")
-            raise ge.GenericError(400, "Query must contain only agent_host details. Please specify agent_host in the "
-                                       "query.")
-        agent_host = req_body.get("agent_host", None)
-        server_id = req_body.get("server_id", None)
-        interval = req_body.get("interval", "1m")
-        time_from = req_body.get("from", None)
-        time_to = req_body.get("to", None)
-
-        if "stat_name" in req_body and req_body["stat_name"] == "network_throughput":
-            response = SLBStats.get_real_network_throughput(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req_body and req_body["stat_name"] == "outstanding_requests":
-            response = SLBStats.get_outstanding_requests(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req_body and req_body["stat_name"] == "hits":
-            response = SLBStats.get_real_stats_total_hits(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req_body and req_body["stat_name"] == "connection_count":
-            response = SLBStats.get_real_connection_count(agent_host, server_id, interval, time_from, time_to)
-        elif "stat_name" in req_body and req_body["stat_name"] == "connections_per_sec":
-            response = SLBStats.get_real_connections_per_sec(agent_host, server_id, interval, time_from, time_to)
-        else:
-            response = SLBStats.get_real_service_stats(agent_host)
-
-        return JsonResponse({
-            "status": 1,
-            "data": response
-        })
-
-    except Exception as e:
-        return JsonResponse({
-            "status": 0,
-            "error": str(e)
-        }, status=500)
