Custom Dashboard
custom
Got it! Hereβs a detailed step-by-step guide on creating a custom Grafana dashboard using Prometheus as a data source, covering every aspect like selecting visualization, adding queries, resizing panels, and configuring alerts.
π― Step-by-Step Guide to Creating a Custom Grafana Dashboard
1οΈβ£ Log in to Grafana
Open Grafana in a browser:
http://<your-grafana-server>:3000Log in with your credentials (
admin/adminby default for a fresh installation).
2οΈβ£ Add Prometheus as a Data Source
Click on the βοΈ "Configuration" in the left sidebar.
Select "Data Sources".
Click "Add Data Source".
Choose "Prometheus" from the list.
Set the URL to your Prometheus server:
http://localhost:9090Click "Save & Test" (you should see a success message).
3οΈβ£ Create a New Dashboard
Go to "Dashboards" (π icon) β Click "New Dashboard".
Click "Add a new panel".
4οΈβ£ Add Panels & Queries (Metric Visualizations)
π Step 1: Choose the Data Source
In the Query Editor, make sure Prometheus is selected as the data source.
π Step 2: Add a Query Using the Query Builder or Manual PromQL
Option 1: Use Query Builder
Click on "Builder".
Choose a metric, e.g.,
node_cpu_seconds_total.Set filters (e.g., mode=
"idle", instance="server1", etc.).
Option 2: Use PromQL Directly
Switch to "Code" and enter:
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)This calculates CPU usage over the last 5 minutes.
π Step 3: Select a Visualization Type
Click the "Visualization" tab.
Choose from:
Time Series (for trends over time)
Gauge (for single values like CPU %)
Bar Gauge (for disk space comparison)
Stat (for single numeric values)
Table (for raw data)
For CPU Usage, select Time Series.
5οΈβ£ Customize Panel Settings
π Step 1: Rename the Panel
Click on the Panel Title β Rename it to
"CPU Usage".
π Step 2: Adjust the Panel Size & Position
Drag edges to resize.
Click "Save" when done.
π Step 3: Customize Display Options
Change Legend settings (e.g., show per-instance breakdown).
Adjust Y-axis range (set 0-100% for CPU).
Enable Thresholds (e.g., mark 80% as a warning and 90% as critical).
6οΈβ£ Add More Panels
Repeat the above steps for Memory Usage and Disk Usage:
π Add Memory Usage Panel
Click "Add new panel".
Enter PromQL:
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100Choose Gauge as the visualization.
Set the title to "Memory Usage".
Click "Apply".
π Add Disk Usage Panel
Click "Add new panel".
Use PromQL:
100 - ((node_filesystem_avail_bytes{mountpoint="/"} * 100) / node_filesystem_size_bytes{mountpoint="/"})Select Bar Gauge.
Set the title to "Disk Usage".
Click "Apply".
7οΈβ£ Configure Alerts
π Step 1: Add an Alert for High CPU Usage
Select the CPU Usage panel.
Click "Alert" β "Create Alert Rule".
Define the alert:
Condition:
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80For: 5 minutes.
Action: Send notifications.
Click "Save".
8οΈβ£ Save & Share Dashboard
π Step 1: Save Dashboard
Click "Save dashboard".
Give it a name, e.g.,
"Server Monitoring".
π Step 2: Share Dashboard
Click "Share".
Choose:
Public link (for viewing)
JSON Export (for backup)
9οΈβ£ Export & Import Dashboard
π Export Dashboard
Go to "Dashboard settings" β "JSON model".
Click "Copy JSON" β Save it as a file.
π Import Dashboard
Go to "Dashboards" β Click "Import".
Upload the JSON file.
π― Summary
β Added Prometheus as a data source β Created CPU, memory, and disk usage panels β Configured alerts for high CPU usage β Customized panel size, layout, and visualization β Saved, shared, and exported the dashboard
Would you like me to generate a JSON template for this dashboard? π
Last updated