A demo application to send CakePHP docker container logs to Grafana Loki via Fluentd.
Here, I've used CakePHP application but any containerized application logging to stderr/stdout can work.
- Docker v20 or newer
- Grafana Loki instance. Recommended: Grafana Cloud, it's free to play around.
-
Clone project into your local system:
git clone [email protected]:ishanvyas22/cakephp-loki-demo.git cd cakephp-loki-demo
-
Copy fluentd config file:
cp fluentd/conf/fluent.conf.example fluentd/conf/fluent.conf
Once copied, replace
__GRAFANA_URL__
,__GRAFANA_USERNAME__
, and__GRAFANA_PASSWORD__
values in<match>
section with your grafana instance details. -
Start fluentd server:
docker build -t cakephp-loki-fluentd ./fluentd docker run -it -p 24224:24224 -v $(pwd)/fluentd/conf:/fluentd/etc cakephp-loki-fluentd
If above commands run successfully, then fluentd agent is ready to accept logs. Make sure to keep this command running in background so it can gather and send logs to Loki.
-
Finally, start the application using below command:
docker compose up -d --remove-orphans
Now navigate to http://localhost:8765/ to generate logs from your CakePHP app. All the logs will be seen in your Grafana Loki dashboard after 10-15 seconds.