{"id":22830754,"url":"https://github.com/imega/alerta","last_synced_at":"2025-03-31T01:41:23.182Z","repository":{"id":267658437,"uuid":"901940897","full_name":"iMega/alerta","owner":"iMega","description":"A simple and effective setup for monitoring custom metrics using Prometheus and Grafana.","archived":false,"fork":false,"pushed_at":"2024-12-11T16:26:37.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T01:41:22.504Z","etag":null,"topics":["grafana","monitoring","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iMega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-12-11T15:47:59.000Z","updated_at":"2024-12-11T16:39:28.000Z","dependencies_parsed_at":"2024-12-11T17:31:32.802Z","dependency_job_id":"6776b628-7721-4ebd-9012-091079aa0da3","html_url":"https://github.com/iMega/alerta","commit_stats":null,"previous_names":["imega/alerta"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Falerta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Falerta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Falerta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Falerta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iMega","download_url":"https://codeload.github.com/iMega/alerta/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246403892,"owners_count":20771526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["grafana","monitoring","prometheus"],"created_at":"2024-12-12T20:14:18.902Z","updated_at":"2025-03-31T01:41:23.128Z","avatar_url":"https://github.com/iMega.png","language":"Shell","readme":"# Monitoring with Prometheus and Grafana\n\nThis project is designed to create and monitor custom metrics using **Prometheus** and **Grafana**. It includes tools to generate fake data for testing and provides an easy-to-use setup for local development.\n\n## Features\n\n1. **Prometheus and Grafana Integration**: Pre-configured setup for Prometheus and Grafana.\n2. **Fake Data Generator**: A Bash script (`faker.sh`) for creating mock metrics data.\n3. **Makefile Commands**: Simplified commands for generating data, running the environment, and stopping services.\n\n## Requirements\n\n-   Docker\n-   Make\n\n## Installation\n\n1. Clone the repository\n\n2. Ensure Docker and Make are installed on your system.\n\n## Usage\n\n### 1. Prepare the Fake Data Generator\n\nBefore generating fake data, edit the `faker.sh` script if needed. The script includes a function `save_metrics_to_file`, which creates a sequence of metrics and writes them to a file.\n\n#### Function Documentation:\n\n```\n# save_metrics_to_file\n#\n# creates a sequence of metrics with specified parameters, incrementing\n# the counter by a random value within a defined range. The metrics\n# are written to a file, one line per metric.\n#\n# Usage:\n# ------\n# save_metrics_to_file \u003cmetric_name\u003e \u003clabels\u003e \u003climit\u003e \u003cstart_time\u003e \u003ccurrent_time\u003e \u003cfilename\u003e\n#\n# metric_name   The name of the metric in Prometheus format\n#               (e.g., http_requests_total).\n# labels        Labels in Prometheus format (e.g., method=\"GET\",status=\"200\").\n# limit         The maximum random increment for the counter at each step.\n# start_time    The starting Unix timestamp (e.g., $(date +%s)).\n# current_time  The ending Unix timestamp (e.g., $(date +%s)).\n#\n# Example:\n# --------\n# current_time=$(date +%s)\n# start_time=$((current_time - 604800)) # 7 days in sec\n# save_metrics_to_file \"http_requests_total\" 'method=\"GET\",status=\"200\"' 50 $start_time $current_time output.txt\n#\n# The function will write the following lines to output.txt:\n#\n# http_requests_total{method=\"GET\",status=\"200\"} 35 1696099200\n# http_requests_total{method=\"GET\",status=\"200\"} 70 1696099260\n# http_requests_total{method=\"GET\",status=\"200\"} 105 1696099320\n```\n\nEnsure that `faker.sh` is executable:\n\n```bash\nchmod +x faker.sh\n```\n\n### 2. Generate Fake Data\n\nTo generate fake data using the `faker.sh` script, run:\n\n```bash\nmake gen\n```\n\nThis will create mock metrics data in a format compatible with Prometheus.\n\n### 3. Start Prometheus and Grafana\n\nRun the following command to start Prometheus and Grafana in Docker containers:\n\n```bash\nmake dev\n```\n\n-   Grafana URL: [http://127.0.0.1:3000](http://127.0.0.1:3000)\n-   Prometheus URL: [http://127.0.0.1:9090](http://127.0.0.1:9090)\n\n### 4. Stop Services\n\nTo stop and remove the running Docker containers, execute:\n\n```bash\nmake stop\n```\n\n## Files and Directories\n\n### `faker.sh`\n\n-   A Bash script for generating fake metrics data. Customize it as needed to create specific metrics for testing.\n\n### `Makefile`\n\n-   `make gen`: Runs the `faker.sh` script to generate fake data.\n-   `make dev`: Starts Prometheus and Grafana containers.\n-   `make stop`: Stops and removes running containers.\n\n## Metrics Monitoring\n\nOnce the environment is running, you can:\n\n1. Access **Grafana** at [http://127.0.0.1:3000](http://127.0.0.1:3000):\n    - Default credentials:\n        - Username: `admin`\n        - Password: `admin`\n    - Configure Prometheus as the data source in Grafana.\n2. Use **Prometheus** at [http://127.0.0.1:9090](http://127.0.0.1:9090) to query metrics directly.\n\n## Dashboard Provisioning in Grafana\n\nTo simplify the setup of Grafana dashboards, you can use **dashboard provisioning** to automatically load preconfigured dashboards when Grafana starts.\n\n### Steps for Dashboard Provisioning\n\n1. **Save a Dashboard JSON File**.\n   Export your dashboard from Grafana as a JSON file and save it in the `grafana/dashboards/` directory.\n\n    ```\n    dashboards/\n    └── example-dashboard.json\n    ```\n\n2. **Create a Provisioning Configuration File**.\n   Create a YAML file in the `provisioning/dashboards` directory to define the provisioning settings:\n\n    ```yaml\n    apiVersion: 1\n\n    providers:\n        - name: \"default\"\n          folder: \"\"\n          type: file\n          disableDeletion: false\n          updateIntervalSeconds: 10\n          options:\n              path: /etc/grafana/dashboards\n    ```\n\n3. **Restart Grafana**.\n   Restart the Grafana container to apply the provisioning settings:\n\n    ```bash\n    make stop dev\n    ```\n\nThe preloaded dashboards will now appear in Grafana under the specified folder (or the root folder if not specified).\n\n## Alerting Provisioning in Grafana\n\nGrafana allows provisioning of alert rules to automate alert setup. These rules can be loaded at startup using a YAML configuration file.\n\n### Steps for Alerting Provisioning\n\n1. **Define Alerting Rules**.\n   Create a YAML file in the `provisioning/alerting/` directory to define alert rules. Example:\n\n    ```yaml\n    apiVersion: 1\n\n    groups:\n        - name: PaymentAlerts\n            interval: 1m\n            rules:\n                - alert: HighErrorRate\n                expr: (sum(rate(payments_failed_total[5m])) / sum(rate(payments_initiated_total[5m]))) \u003e 0.1\n                for: 2m\n                labels:\n                    severity: critical\n                annotations:\n                    summary: \"High payment error rate detected\"\n                    description: \"The error rate for payments has exceeded 10% over the last 5 minutes.\"\n\n                - alert: LowPaymentInitiationRate\n                expr: rate(payments_initiated_total[5m]) \u003c 10\n                for: 5m\n                labels:\n                    severity: warning\n                annotations:\n                    summary: \"Low payment initiation rate\"\n                    description: \"The rate of payment initiations is below 10 per minute.\"\n    ```\n\n2. **Restart Grafana**.\n   Restart the Grafana container to apply the alerting settings:\n\n    ```bash\n    make stop dev\n    ```\n\n3. **Access Preconfigured Alerts**.\n   The preloaded alert rules will now appear in Grafana under the Alerting section.\n\n## Troubleshooting\n\n-   Ensure Docker is running and accessible.\n-   If ports are in use, modify the `docker-compose.yml` file to use different ports.\n-   Verify that `faker.sh` is executable:\n    ```bash\n    chmod +x faker.sh\n    ```\n\n## License\n\nThis project is licensed under the Apache-2.0 license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimega%2Falerta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimega%2Falerta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimega%2Falerta/lists"}