Day 62: Building Dashboard on Grafana
Configuring Grafana with Loki Data Source
Add Data Source on Grafana
In our previous blog- Installing Grafana, Loki, and Prometheus we walked you through the installation process of Grafana, Loki, and Prometheus. In this article, we'll dive deeper into the Grafana setup by showing you how to add the Loki data source and create an insightful dashboard.
Step 1: Access Data Sources
After successfully installing Grafana, the first step is to add Loki as a data source. To do this, access the Grafana web interface.
Step 2: Choose Loki Data Source
In the Grafana interface, navigate to the "Configuration" menu on the left-hand side and click on "Data Sources." Then, click on the "Add data source" button.
Step 3: Configure Loki Data Source
In the "HTTP" category, you'll need to enter the URL for your Loki instance. Typically, this URL is localhost:3100, assuming Loki is running on the same machine as Grafana.
Scroll down and click on the "Save & Test" button. A confirmation message will pop up, indicating that the data source has been successfully connected to Loki.
A message will pop up "Data source successfully connected."
Add new Dashboard
Step 1: Access Dashboards
Go to the Grafana home page and click on "Dashboards."
Step 2: Start a New Dashboard
To create a new dashboard, click on the "New Dashboard" button.
Step 3: Select Data Source
When you add a visualization to your dashboard, make sure to select the Loki data source you created earlier.
Step 4: Customize Your Dashboard
You'll be presented with a blank dashboard canvas. Ensure that the intended data source is selected.
Step 5: Choose Data Source or Label Filters
Depending on your preference, you can choose to visualize data from a specific log file or apply label filters like "job" and "varlogs." These label filters are typically defined in the Promtail configuration file, which you set up during the installation of Grafana, Loki, and Prometheus.
You can refer to the Promtail configuration file that was created while installing Promtail- Installing Grafana, Loki, and Prometheus
Refer Promtail configuration file
Step 6: Execute Queries
Click on "Run Queries," and your selected data will be displayed on the panel.
On the panel the data will reflect
Step 7: Review Logs
If you want to review the actual log entries, click on "Switch to table."
Step 8: Customize Log Title
To enhance clarity, you can rename the title of the logs. For example, you can name it "System Logs" and click "Apply."
We have successfully added the System Logs
Step 9: Add Additional Data
You can follow similar steps to create a separate panel for Grafana Logs, selecting the appropriate label filters such as "job" and "varlogs" to display the desired data.
You can incorporate more data by selecting operations like aggregations (e.g., Sum), changing visualizations, and applying different data sources.
Run Queries
Select Grafana Logs and Apply
We have successfully created Grafana Logs.
Step 10: Dashboard Completion
Once you've added and configured all the desired data as mentioned in the below screenshots, your dashboard is ready to provide valuable insights.
Add new operations -> Aggregations -> Sum
Change Visualisation
Select desired data - in this case we selected "Line Chart with gradient colour scheme" and Apply
Congratulations! Your Dashboard Is Ready
Conclusion:
With Grafana configured to pull data from Loki and your dashboard set up, you're well-equipped to monitor and analyze your log data effectively. Grafana's flexibility and Loki's log aggregation capabilities make for a powerful combination, enabling you to gain actionable insights from your logs and keep your systems running smoothly. Happy dashboarding! ๐๐๐