-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dashboard.py
More file actions
74 lines (69 loc) · 2.35 KB
/
create_dashboard.py
File metadata and controls
74 lines (69 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Create Flytrap dashboard in Grafana via API
"""
import requests
# Grafana API details
GRAFANA_URL = "http://localhost:3000"
AUTH = ("admin", "admin")
# Dashboard JSON
dashboard = {
"dashboard": {
"title": "Flytrap Object Detection",
"tags": ["flytrap", "object-detection"],
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "Detection Count Over Time",
"type": "graph",
"targets": [
{
"query": 'from(bucket: "detections") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "frame") |> filter(fn: (r) => r._field == "detection_count")',
"refId": "A",
}
],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
},
{
"id": 2,
"title": "Processing Time (ms)",
"type": "graph",
"targets": [
{
"query": 'from(bucket: "detections") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "frame") |> filter(fn: (r) => r._field == "processing_time_ms")',
"refId": "A",
}
],
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
},
{
"id": 3,
"title": "Object Classes Detected",
"type": "table",
"targets": [
{
"query": 'from(bucket: "detections") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "detection") |> group(columns: ["class"]) |> count()',
"refId": "A",
}
],
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
},
],
"time": {"from": "now-1h", "to": "now"},
"refresh": "5s",
}
}
# Create dashboard
response = requests.post(
f"{GRAFANA_URL}/api/dashboards/db",
auth=AUTH,
json=dashboard,
headers={"Content-Type": "application/json"},
)
if response.status_code == 200:
print("✅ Dashboard created successfully!")
print("Open: http://localhost:3000")
else:
print(f"❌ Failed to create dashboard: {response.status_code}")
print(response.text)