Skip to main content

Adding Loki Datasource in Grafana

Follow these steps to add a Loki datasource in Grafana. This will enable you to integrate Loki for log visualization alongside your metrics.

note

Our Loki instance is available on https://loki.techbloomeracademy.com, but in your environment, it can be simply the IP address, followed by the port (default: 3000).


1. Login to Grafana

  1. Open your Grafana instance (e.g., http://localhost:3000).
  2. Enter your username and password to log in.

2. Navigate to Add a New Connection

  1. In the left-hand sidebar, click on Home.
  2. Navigate to ConnectionsAdd new connection.

3. Search for Loki

  1. In the search bar, type Loki to find the Loki datasource.
  2. Click on Loki to select it.

Search for Loki and select it


4. Add the Loki Datasource

  1. Click on the Add new datasource button to proceed.

Click Add new datasource


5. Configure the Loki Datasource

  1. In the datasource settings, provide the URL of your Loki server (e.g., http://<loki-server>:<port>).

Enter the Loki server URL


6. Save and Test

  1. Scroll to the bottom of the page and click Save & Test.
  2. Grafana will verify the connection to Loki and confirm if it’s working.

Save and test the datasource


Troubleshooting

Troubleshooting

If you encounter issues while connecting Grafana to Loki, try the following:

  • Verify Loki Server Accessibility: Ensure that the Loki server is running and accessible from the Grafana server.

    • Use telnet or curl to test connectivity:
      telnet <loki-server> 3000
      Or:
      curl http://<loki-server>:3000/metrics
      If these commands fail, check your Loki server configuration or firewall settings.
  • Check Grafana Logs: Review Grafana logs for detailed error messages. Logs can provide insights into issues like incorrect credentials or connection failures.

    sudo journalctl -u grafana-server
  • Authentication Issues: If your Loki setup uses authentication (e.g., API tokens, Basic Auth):

    • Double-check that the credentials are correctly configured in the Grafana Loki datasource settings.
    • Ensure you have assigned appropriate permissions to the API token.
  • Firewall or Network Rules: Verify that no firewall or network restrictions are blocking communication between the Grafana and Loki servers.

  • Check Loki's Status: Confirm that Loki is running correctly and not in a failed state:

    systemctl status loki

    Or review Loki logs for errors:

    journalctl -u loki
  • Grafana and Loki Versions: Ensure that both Grafana and Loki are compatible. Mismatched versions might cause issues. Check the Grafana Loki compatibility matrix for reference.

  • TLS/SSL Configuration: If you're using HTTPS for Loki:

    • Verify that the SSL certificate is correctly configured and trusted by Grafana.
    • If necessary, enable the "Skip TLS Verify" option in the Loki datasource settings for testing purposes.
  • Check Proxy Settings: If Grafana connects to Loki through a proxy, ensure the proxy configuration is correct and not blocking requests.

  • Datasource Configuration: Ensure the datasource URL in Grafana matches the actual Loki endpoint, including the protocol (e.g., http:// or https://).

  • Loki Query Timeout: Increase the timeout settings in the Loki datasource configuration if you encounter timeouts during queries.

If the issue persists, consult the Grafana and Loki documentation or seek help from the Grafana Community Forum.