Skip to content

benjisho/grafana-container

Repository files navigation

Grafana Container

Table of Contents

  1. Introduction
  2. Features
  3. Getting Started
  4. Generate Self-Signed SSL Certificate
  5. Updated Grafana Version
  6. Usage
  7. Monitoring Container Logs
  8. Contributing
  9. License

Introduction

This project provides a containerized version of Grafana, an open-source platform for monitoring and observability. It's designed to be easy to deploy and manage, making it ideal for environments that benefit from containerization. The Grafana Container offers a scalable way to visualize and analyze metrics, logs, and traces from your environment.

Features

  • Easy to deploy Grafana in a containerized environment.
  • Configurable settings for different monitoring needs.
  • Integration with various data sources.

Getting Started

Prerequisites

  • Docker and Docker Compose installed on your system.
  • Basic understanding of containerization and Grafana.

Installation

  1. Clone the repository:
git clone https://github.com/benjisho/grafana-container.git
  1. Navigate to the cloned directory:
cd grafana-container

Generate SSL self-signed certificate into certs/ directory

Note: This section is relevant if you haven't generated a well-known SSL certificate from a certified authority. These will guide you on creating a self-signed certificate, useful for testing or development purposes.

  1. Run the following command to generate a 2048-bit RSA private key, which is used to decrypt traffic:
openssl genrsa -out certs/server.key 2048
  1. Run the following command to generate a certificate, using the private key from the previous step.
openssl req -new -key certs/server.key -out certs/server.csr
  1. Run the following command to self-sign the certificate with the private key, for a period of validity of 365 days:
openssl x509 -req -days 365 -in certs/server.csr -signkey certs/server.key -out certs/server.crt

Updated Grafana Version

The Grafana container now uses version 12.0.1-ubuntu. This version is based on Ubuntu and provides enhanced compatibility and stability. Ensure that your environment is compatible with this version before deployment.

Key Notes:

  • The Ubuntu-based image may have different dependencies compared to the Alpine-based images. Ensure that any custom plugins or configurations are compatible.
  • If you encounter issues, refer to the Grafana Docker documentation for troubleshooting.

Running the Setup

To start the Grafana and Nginx services, use the following command:

docker compose up -d

This will pull the specified Grafana version (12.0.1-ubuntu) and start the services.

Configuration

Copy .env.example to .env and adjust the variables:

cp .env.example .env
  • GRAFANA_ADMIN_USER and GRAFANA_ADMIN_PASSWORD set the initial Grafana credentials.
  • NGINX_SERVER_NAME defines the hostname served by Nginx.
  • SSL_CERT_PATH and SSL_KEY_PATH point to your certificate files.

You can change exposed ports or paths by editing docker-compose.yml.

Persisting Data

Grafana stores its data in /var/lib/grafana. The compose file uses a named volume grafana-storage. To persist data on the host, map a directory instead:

volumes:
  - ./grafana-data:/var/lib/grafana

Troubleshooting

  • Ensure the SSL certificates referenced in .env exist and are readable by Nginx.
  • If Grafana cannot write to the data directory, adjust its permissions:
sudo chown -R 472:472 ./grafana-data

Usage

To use the Grafana Container:

  1. Start the container:
docker compose up -d
  1. Access Grafana by navigating to https://localhost in your web browser.
  2. Default login user is usually admin for both username and password (unless configured otherwise).
  3. Configure data sources and dashboards as per your requirements.

For example, to add a Prometheus data source:

  • Navigate to Configuration > Data Sources in the Grafana UI.
  • Click Add data source, and select Prometheus.
  • Enter the URL of your Prometheus server, and click Save & Test.
  1. Explore and create dashboards to visualize your data. For more detailed usage instructions, refer to the Grafana documentation.

Monitoring Container Logs

This section guides you on how to use docker compose logs -f to follow the log output of the Grafana and Nginx containers in real-time.

Command Explanation

  • docker compose logs -f: This command fetches the logs of the containers.
  • The -f flag means "follow", allowing you to view the log output in real-time.

Steps to Follow Logs

  1. Navigate to where your docker-compose.yml file is located.

  2. Execute the following command to follow the logs for all services:

    docker compose logs -f

    This will display a continuous stream of logs of all containers in the docker-compose.yml.

  3. If you want to follow the logs of a specific container from the docker-compose.yml, specify the service name. For example, to follow only the Grafana logs, use:

    docker compose logs -f grafana

    Similarly, for Nginx logs:

    docker compose logs -f nginx

Tips for Log Outputs

  • Grafana Logs: Look for indications of successful startup, connection to data sources, and any error messages related to querying data.
  • Nginx Logs: These logs will include information about HTTP requests, responses, and any errors related to network connections or SSL/TLS certificates.

Note: Keep in mind that the volume of logs can be high depending on the level of activity. It's advisable to filter or search through the logs for specific keywords related to the issues you're investigating.


Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages