← Back to Blog

πŸš€ Loki PoC Implementation in GitHub Codespaces

πŸš€ Loki PoC Implementation in GitHub Codespaces πŸ’‘ What I Want to Achieve Implementing Loki as a log aggregation system within GitHub Codespaces for efficient monitoring of containerized applications.

πŸš€ Loki PoC Implementation in GitHub Codespaces

πŸ’‘ What I Want to Achieve

Implementing Loki as a log aggregation system within GitHub Codespaces for efficient monitoring of containerized applications. Loki, known for its simplicity and ability to retrieve logs without heavy indexing, can be a powerful tool for developers working in cloud-native environments. My goal is to create a functional Loki Proof of Concept (PoC) within GitHub Codespaces that can be used as a quick setup for any future development environments.

πŸ› οΈ Steps to Implement Loki in GitHub Codespaces

1️⃣ Setup GitHub Codespaces

  • Go to your GitHub repository and click on Codespaces from the top menu.

  • Click on New Codespace to launch a new development environment.

2️⃣ Install Loki and Promtail

In your GitHub Codespace terminal, start by installing Loki and its log shipper, Promtail.

Clone the Loki repository to start setting up your log system

git clone https://github.com/grafana/loki.git
cd loki/

Install Loki using Docker (as Codespaces supports Docker)

docker run -d --name loki -p 3100:3100 grafana/loki:2.7.0

3️⃣ Configure Loki

Now, configure Loki to suit your log requirements. Create a loki-config.yaml file and set up your custom configurations like log retention, log scraping, and storage.

auth_enabled: false
server:
http_listen_port: 3100
ingester:
lifecycler:
ring:
kvstore:
store: inmemory
chunk_idle_period: 5m
chunk_retain_period: 30s
max_transfer_retries: 0
schema_config:
configs:
- from: 2021-01-01
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h
storage_config:
boltdb:
directory: /loki/index
filesystem:
directory: /loki/chunks
limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h

4️⃣ Install Promtail

Promtail acts as an agent to ship logs from your Codespace containers to Loki.

Install Promtail using Docker

docker run -d --name promtail --link loki -v /var/log:/var/log -p 9080:9080 grafana/promtail:2.7.0

5️⃣ Verify the Setup

Check if Loki and Promtail are running correctly in your Codespace environment. You can verify by visiting:

http://localhost:3100/metrics

You should see metrics showing logs being ingested.

6️⃣ Connect Grafana for Visualization (Optional)

While Loki alone can collect logs, using Grafana to visualize them can improve your understanding of the system. Set up Grafana in your Codespace and connect it to Loki by adding the Loki instance as a data source.

docker run -d --name=grafana -p 3000:3000 grafana/grafana

You can access Grafana at http://localhost:3000 and add Loki as a data source by configuring it with the same URL http://localhost:3100.

🎯 Result

With Loki and Promtail running within your GitHub Codespace, you can now track logs from your containerized applications effectively.

πŸš€ Next Steps:

  • Optimize the log scraping configurations.

  • Explore alerting mechanisms for critical log messages.

  • Integrate this setup into your CI/CD pipeline for automated monitoring during development.


πŸ”— Connect with me:

πŸ“ Screenshot of the PoC in Action:
Here’s how the setup looks in GitHub Codespaces! (Make sure to pause at key moments during setup to grab screenshots for your blog.)


Imported from rifaterdemsahin.com Β· 2025