Skip to content

A demo application to send CakePHP docker container logs to Grafana Loki via Fluentd.

License

Notifications You must be signed in to change notification settings

ishanvyas22/cakephp-loki-demo

Repository files navigation

CakePHP + Grafana Loki demo application

A demo application to send CakePHP docker container logs to Grafana Loki via Fluentd.

Default page screenshot

Here, I've used CakePHP application but any containerized application logging to stderr/stdout can work.

Requirements

  • Docker v20 or newer
  • Grafana Loki instance. Recommended: Grafana Cloud, it's free to play around.

Installation

  1. Clone project into your local system:

    git clone [email protected]:ishanvyas22/cakephp-loki-demo.git
    cd cakephp-loki-demo
  2. 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.

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

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