Custom Dashboard

chevron-rightcustomhashtag

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>:3000
  • Log in with your credentials (admin/admin by default for a fresh installation).


2️⃣ Add Prometheus as a Data Source

  1. Click on the βš™οΈ "Configuration" in the left sidebar.

  2. Select "Data Sources".

  3. Click "Add Data Source".

  4. Choose "Prometheus" from the list.

  5. Set the URL to your Prometheus server:

    http://localhost:9090
  6. Click "Save & Test" (you should see a success message).


3️⃣ Create a New Dashboard

  1. Go to "Dashboards" (πŸ“Š icon) β†’ Click "New Dashboard".

  2. 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

  1. Click "Add new panel".

  2. Enter PromQL:

    (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
  3. Choose Gauge as the visualization.

  4. Set the title to "Memory Usage".

  5. Click "Apply".

πŸ“Œ Add Disk Usage Panel

  1. Click "Add new panel".

  2. Use PromQL:

    100 - ((node_filesystem_avail_bytes{mountpoint="/"} * 100) / node_filesystem_size_bytes{mountpoint="/"})
  3. Select Bar Gauge.

  4. Set the title to "Disk Usage".

  5. Click "Apply".


7️⃣ Configure Alerts

πŸ“Œ Step 1: Add an Alert for High CPU Usage

  1. Select the CPU Usage panel.

  2. Click "Alert" β†’ "Create Alert Rule".

  3. Define the alert:

    • Condition:

      100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
    • For: 5 minutes.

    • Action: Send notifications.

  4. Click "Save".


8️⃣ Save & Share Dashboard

πŸ“Œ Step 1: Save Dashboard

  1. Click "Save dashboard".

  2. Give it a name, e.g., "Server Monitoring".

πŸ“Œ Step 2: Share Dashboard

  1. Click "Share".

  2. Choose:

    • Public link (for viewing)

    • JSON Export (for backup)


9️⃣ Export & Import Dashboard

πŸ“Œ Export Dashboard

  1. Go to "Dashboard settings" β†’ "JSON model".

  2. Click "Copy JSON" β†’ Save it as a file.

πŸ“Œ Import Dashboard

  1. Go to "Dashboards" β†’ Click "Import".

  2. 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