{"id":15178840,"url":"https://github.com/pazfelipe/grafana-prometheus","last_synced_at":"2026-02-28T08:08:13.236Z","repository":{"id":247072404,"uuid":"824924651","full_name":"pazfelipe/grafana-prometheus","owner":"pazfelipe","description":"A simple project to show how to implement Grafana, Prometheus, Loki, AlertManager in applications built in NodeJs and Python","archived":false,"fork":false,"pushed_at":"2024-07-07T21:21:43.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T19:24:13.549Z","etag":null,"topics":["alertmanager","docker-compose","express","flask","grafana","loki","nodejs","prometheus","python"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pazfelipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-06T09:55:04.000Z","updated_at":"2024-07-07T21:21:46.000Z","dependencies_parsed_at":"2024-11-12T12:36:33.620Z","dependency_job_id":null,"html_url":"https://github.com/pazfelipe/grafana-prometheus","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"086a5978c98129bea0f525007d71ca989bae253f"},"previous_names":["pazfelipe/grafana-prometheus"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pazfelipe/grafana-prometheus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazfelipe%2Fgrafana-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazfelipe%2Fgrafana-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazfelipe%2Fgrafana-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazfelipe%2Fgrafana-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pazfelipe","download_url":"https://codeload.github.com/pazfelipe/grafana-prometheus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pazfelipe%2Fgrafana-prometheus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29928100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alertmanager","docker-compose","express","flask","grafana","loki","nodejs","prometheus","python"],"created_at":"2024-09-27T15:40:16.086Z","updated_at":"2026-02-28T08:08:13.216Z","avatar_url":"https://github.com/pazfelipe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monitoring a NodeJs application with Prometheus, Loki and Grafana\n\n## Description\n\nThis project demonstrates the integration of a Node.js application with Loki and Promtail for log aggregation and monitoring. The application logs are collected and sent to Loki via Promtail, allowing centralized log management and visualization using Grafana.\n\n## Prerequisites\n\nBefore you begin, ensure you have the following prerequisites:\n\n- Docker and Docker Compose installed\n- Node.js and npm installed\n- Basic understanding of Docker and containerization\n\n## Installation\n\nFollow these steps to set up the project:\n\n1. Clone the repository:\n\n```sh\n   git clone https://github.com/pazfelipe/grafana-prometheus.git\n   cd grafana-prometheus\n   docker-compose up --build -d\n```\n\n## Configuration\n\n1. **Promtail Configuration**:\n   - Ensure you have the correct configuration file (`promtail-config.yml`) in the root directory.\n   - The configuration file should be mounted to the Promtail container in `docker-compose.yml`.\n\n2. **Loki Configuration**:\n   - Ensure you have the correct configuration file (`loki-config.yml`) in the root directory.\n   - The configuration file should be mounted to the Loki container in `docker-compose.yml`.\n\n3. **Grafana Configuration**:\n   - Grafana is configured to use a persistent volume to store its data. Ensure the volume is correctly set up in `docker-compose.yml`.\n   - After starting the containers, access Grafana at `http://localhost:3000` and configure Loki as a data source.\n  \n## How to Use\n\n1. **Starting the Application**:\n   - After setting up and starting the Docker containers, the Node.js application will be running on `http://localhost:3001`.\n\n2. **Accessing Grafana**:\n   - Open your browser and go to `http://localhost:3000`.\n   - Log in with the default credentials (`admin` / `admin`) and configure Loki as a data source to visualize logs.\n\n3. **Node.js Application Routes**:\n   - The application provides several routes to test logging and error handling:\n     - `GET /`: Returns a successful connection message (status 200).\n     - `GET /invalid-request`: Simulates a bad request (status 400).\n     - `GET /not-authorized`: Simulates a not authorized request (status 401).\n     - `GET /not-authenticated`: Simulates a forbidden request (status 403).\n     - `GET /internal-error`: Simulates an internal server error (status 500).\n     - `GET /server-error`: Simulates a service unavailable error (status 503).\n     - `GET /failing`: Simulates an unhandled error by accessing an undefined variable.\n     - `GET /failing-2`: Simulates another unhandled error by attempting to reassign a constant.\n\n## Examples\n\nHere are some examples of how to interact with the Node.js application and visualize the logs in Grafana:\n\n1. **Accessing the Home Route**:\n   - Open your browser and go to `http://localhost:3001/`.\n   - You should see a message indicating a successful connection.\n\n2. **Triggering Different Status Codes**:\n   - Visit the following routes to trigger different HTTP status codes:\n     - `http://localhost:3001/invalid-request` (400 Bad Request)\n     - `http://localhost:3001/not-authorized` (401 Unauthorized)\n     - `http://localhost:3001/not-authenticated` (403 Forbidden)\n     - `http://localhost:3001/internal-error` (500 Internal Server Error)\n     - `http://localhost:3001/server-error` (503 Service Unavailable)\n     - `http://localhost:3001/failing` (Unhandled Error: ReferenceError)\n     - `http://localhost:3001/failing-2` (Unhandled Error: TypeError)\n\n3. **Viewing Logs in Grafana**:\n   - Open Grafana at `http://localhost:3000` and log in with `admin` / `admin`.\n   - Go to the \"Explore\" section, select Loki as the data source, and use queries to filter logs.\n   - Example queries:\n     - `{job=\"nodejs_app\"} | json`\n     - `{job=\"nodejs_app\", error_type=\"ReferenceError\"}`\n\n## Project Structure\n\nThe project directory structure is as follows:\n\n```sh\n.\n├── README.md\n├── docker-compose.yaml\n├── loki-config.yaml\n├── node_app\n│   ├── Dockerfile\n│   ├── index.js\n│   ├── logger.js\n│   ├── logs\n│   │   ├── combined.log\n│   │   ├── error.log\n│   │   └── exceptions.log\n│   ├── package.json\n│   ├── promClient.js\n│   ├── routes.js\n│   └── yarn.lock\n├── prometheus.yaml\n└── promtail-config.yaml\n```\n\n## Technologies Used\n\nThe project leverages the following technologies:\n\n- **Node.js**: A JavaScript runtime built on Chrome's V8 JavaScript engine for building fast and scalable network applications.\n- **Express.js**: A minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.\n- **Docker**: A platform for developing, shipping, and running applications in containers, which enables fast, consistent delivery of your applications.\n- **Docker Compose**: A tool for defining and running multi-container Docker applications. It allows you to define the services, networks, and volumes your application needs.\n- **Prometheus**: An open-source systems monitoring and alerting toolkit designed for reliability and scalability.\n- **Loki**: A log aggregation system designed to store and query logs from applications and infrastructure.\n- **Promtail**: An agent that ships the contents of local logs to a private Loki instance or Grafana Cloud.\n- **Grafana**: An open-source platform for monitoring and observability, providing dashboards and visualizations for your data.\n- **Winston**: A versatile logging library for Node.js applications.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpazfelipe%2Fgrafana-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpazfelipe%2Fgrafana-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpazfelipe%2Fgrafana-prometheus/lists"}