Index: /branches/amp_4_0/scripts/fetch_influx_data.py
===================================================================
--- /branches/amp_4_0/scripts/fetch_influx_data.py	(revision 0)
+++ /branches/amp_4_0/scripts/fetch_influx_data.py	(working copy)
@@ -0,0 +1,72 @@
+from influxdb_client import InfluxDBClient
+
+# === InfluxDB Configuration ===
+INFLUX_URL = "http://localhost:8086"
+INFLUX_TOKEN = "5vTtwB8fWzP9rkaLU8aaNnkM-RJzPl9yHdm1N28NdOtIyVvJTyb9JgyMjnAsHTLBlVtEQ7UMOencnJgHMvFabQ=="
+ORG = "AN"
+BUCKET = "AMP"
+
+
+def run_query(query):
+    client = InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=ORG)
+    query_api = client.query_api()
+    tables = query_api.query(query)
+    results = []
+    for table in tables:
+        for record in table.records:
+            record["time"] = record["_time"]
+            results.append(record.values)
+    return results
+
+
+def fetch_data():
+    # 1. InBytePerSec / OutBytePerSec query (last 30 mins)
+    byte_query = f'''
+from(bucket: "{BUCKET}")
+  |> range(start: -30m)
+  |> filter(fn: (r) =>
+    r._measurement == "apv_virtual_stats" and
+    (r._field == "InBytePerSec" or r._field == "OutBytePerSec"))
+  |> aggregateWindow(every: 5s, fn: last, createEmpty: false)
+  |> pivot(rowKey: ["_time", "ServerId", "agent_host"], columnKey: ["_field"], valueColumn: "_value")
+  |> map(fn: (r) => ({{
+      "_time": r._time,
+      "ServerId": r.ServerId,
+      "agent_host": r.agent_host,
+      "InBytePerSec_bps": float(v: r.InBytePerSec) * 8.0,
+      "OutBytePerSec_bps": float(v: r.OutBytePerSec) * 8.0
+  }}))
+'''
+    # 2. ConnCnt query (last 30 mins)
+    conncnt_query = f'''
+from(bucket: "{BUCKET}")
+  |> range(start: -30m)
+  |> filter(fn: (r) =>
+    r._measurement == "apv_virtual_stats" and
+    (r._field == "ConnCnt"))
+  |> aggregateWindow(every: 5s, fn: last, createEmpty: false)
+  |> pivot(rowKey: ["_time", "ServerId", "agent_host"], columnKey: ["_field"], valueColumn: "_value")
+  |> map(fn: (r) => ({{
+          "_time": r._time,
+          "ServerId": r.ServerId,
+          "agent_host": r.agent_host,
+          "ConnCnt": r.ConnCnt
+      }}))
+    '''
+
+    byte_data = run_query(byte_query)
+    conncnt_data = run_query(conncnt_query)
+    return byte_data, conncnt_data
+
+
+# === Test Run ===
+if __name__ == "__main__":
+    byte_data, conncnt_data = fetch_data()
+
+    print("Byte/sec Data:")
+    for row in byte_data:  # sample
+        print(row)
+
+    print("\nConnCnt Data:")
+    for row in conncnt_data:  # sample
+        print(row)
Index: /branches/amp_4_0/scripts/generate_pdf_report.py
===================================================================
--- /branches/amp_4_0/scripts/generate_pdf_report.py	(revision 0)
+++ /branches/amp_4_0/scripts/generate_pdf_report.py	(working copy)
@@ -0,0 +1,129 @@
+# generate_pdf_report.py
+
+from reportlab.lib.pagesizes import A4
+from reportlab.lib.units import inch
+from reportlab.pdfgen import canvas
+from reportlab.lib import colors
+from datetime import datetime, timezone
+from fetch_influx_data import fetch_data
+
+
+def draw_section(c, y, title, data, page_number):
+    if not data:
+        return y, page_number
+
+    width, height = A4
+    is_conn_cnt = "InBytePerSec_bps" not in data[0]
+
+    def draw_table_header(y_pos):
+        c.setFont("Helvetica-Bold", 10)
+        c.drawString(40, y_pos, "Time")
+        if is_conn_cnt:
+            c.drawString(220, y_pos, "Concurrent Connections")
+        else:
+            c.drawString(220, y_pos, "Inbound (bps)")
+            c.drawString(380, y_pos, "Outbound (bps)")
+        return y_pos - 20 
+
+    # Section title
+    c.setFont("Helvetica-Bold", 12)
+    c.drawString(40, y, title)
+    y -= 20
+
+    # Server Info
+    server_id = data[0].get("ServerId", "N/A")
+    agent_host = data[0].get("agent_host", "N/A")
+
+    c.setFont("Helvetica", 11)
+    c.drawString(40, y, f"Server ID: {server_id}")
+    y -= 16
+    c.drawString(40, y, f"Host: {agent_host}")
+    y -= 24
+
+    # Draw initial table header
+    y = draw_table_header(y)
+
+    # Table content
+    c.setFont("Helvetica", 10)
+    for record in data:
+        if y < 60:
+            # Page footer
+            c.setFont("Helvetica", 9)
+            c.setFillColor(colors.gray)
+            c.drawRightString(width - 40, 30, f"Page {page_number}")
+            c.setFillColor(colors.black)
+
+            c.showPage()
+            page_number += 1
+            y = height - 60
+
+            # Redraw header
+            y = draw_table_header(y)
+            y -= 6
+
+        # Time formatting
+        time_val = record.get("_time")
+        time_str = time_val.astimezone().strftime("%H:%M:%S") if isinstance(time_val, datetime) else str(time_val)
+
+        c.setFont("Helvetica", 10)
+        c.drawString(40, y, time_str)
+        if is_conn_cnt:
+            c.drawString(240, y, str(record.get("ConnCnt", "")))
+        else:
+            c.drawString(240, y, str(record.get("InBytePerSec_bps", "")))
+            c.drawString(400, y, str(record.get("OutBytePerSec_bps", "")))
+        y -= 18
+
+    return y, page_number
+
+
+def generate_pdf(conncnt_data, byte_data, filename="influx_report.pdf"):
+    c = canvas.Canvas(filename, pagesize=A4)
+    width, height = A4
+    page_number = 1  # Start page number
+
+    # Logo and Header
+    c.drawImage("Array-Logo-en-2024.jpg", x=40, y=A4[1] - 80, width=1.5 * inch, height=0.5 * inch)
+
+    c.setFont("Helvetica-Bold", 14)
+    c.setFillColor("#F26C20")
+    c.drawString(220, height - 90, "Service Status Report")
+
+    c.setFont("Helvetica", 10)
+    c.setFillColor(colors.gray)
+    c.drawRightString(width - 40, height - 50,
+                      f"Report Generated on {datetime.now(timezone.utc).strftime('%a, %d %B %Y %H:%M:%S UTC')}")
+
+    c.setFillColor(colors.black)
+    c.setStrokeColor(colors.lightgrey)
+    c.line(40, height - 100, width - 40, height - 100)
+
+    # Service Info
+    c.setFont("Helvetica", 11)
+    y = height - 120
+    c.drawString(40, y, "Service Name: vs1")
+    y -= 15
+    c.drawString(40, y, "Service Type: SLB_vs")
+    y -= 15
+    c.drawString(40, y, "Device Name: vAPV1")
+    y -= 15
+    c.drawString(40, y, "Device IP: 192.168.85.101")
+    y -= 50
+
+    # Sections with page tracking
+    y, page_number = draw_section(c, y, "Connection Count", conncnt_data, page_number)
+    y -= 50
+    y, page_number = draw_section(c, y, "Bandwidth Usage (Bytes/sec)", byte_data, page_number)
+
+    # Final page number
+    c.setFont("Helvetica", 9)
+    c.setFillColor(colors.gray)
+    c.drawRightString(width - 40, 30, f"Page {page_number}")
+
+    c.save()
+    print(f"PDF saved to {filename}")
+
+
+if __name__ == "__main__":
+    conncnt_data, byte_data = fetch_data()
+    generate_pdf(conncnt_data, byte_data, filename="slb_report.pdf")
\ No newline at end of file
