{"id":18678645,"url":"https://github.com/chylex/apache-prometheus-exporter","last_synced_at":"2025-10-08T21:21:00.454Z","repository":{"id":80098822,"uuid":"535098889","full_name":"chylex/Apache-Prometheus-Exporter","owner":"chylex","description":"Prometheus exporter for Apache access logs. Processes multiple log files simultaneously (one file per virtual host).","archived":false,"fork":false,"pushed_at":"2023-10-28T09:47:28.000Z","size":110,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-27T21:30:02.652Z","etag":null,"topics":["exporter","metrics","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chylex.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":"2022-09-10T19:28:56.000Z","updated_at":"2023-01-10T06:39:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"406b3e07-715d-4ac1-a4c6-e63bb301e2a9","html_url":"https://github.com/chylex/Apache-Prometheus-Exporter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chylex%2FApache-Prometheus-Exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chylex%2FApache-Prometheus-Exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chylex%2FApache-Prometheus-Exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chylex%2FApache-Prometheus-Exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chylex","download_url":"https://codeload.github.com/chylex/Apache-Prometheus-Exporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239529402,"owners_count":19654094,"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":["exporter","metrics","prometheus"],"created_at":"2024-11-07T09:39:36.849Z","updated_at":"2025-10-08T21:20:55.420Z","avatar_url":"https://github.com/chylex.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apache Prometheus Exporter\n\nExports Prometheus metrics from Apache access logs.\n\nSee the [docker](./docker) folder for an example setup using Docker Compose.\n\n## 1. Configure Apache Access Log Format\n\nThe following snippet will create a log format named `prometheus` that includes all information the exporter expects. See [Apache documentation](https://httpd.apache.org/docs/2.4/mod/mod_log_config.html#formats) for explanation of the format.\n\n```apache\nLogFormat \"%t %h \\\"%r\\\" %\u003es %O %{ms}T \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" prometheus\n```\n\n## 2. Configure Apache Virtual Hosts\n\nThe following snippet is an example of how you could configure Apache to serve 3 domains from different folders using macros.\n\nEach domain has its own access and error log file. The log files are rotated daily, with a dedicated folder for each day, and a `${APACHE_LOG_DIR}/latest/` folder with hard links to today's log files - this folder will be watched by the exporter.\n\n```apache\n\u003cMacro Logs $domain\u003e\n\tErrorLog \"|/usr/bin/rotatelogs -l -f -D -L ${APACHE_LOG_DIR}/latest/$domain.error.log ${APACHE_LOG_DIR}/%Y-%m-%d/$domain.error.log 86400\"\n\tCustomLog \"|/usr/bin/rotatelogs -l -f -D -L ${APACHE_LOG_DIR}/latest/$domain.access.log ${APACHE_LOG_DIR}/%Y-%m-%d/$domain.access.log 86400\" prometheus\n\u003c/Macro\u003e\n\n\u003cMacro Domain $domain\u003e\n\t\u003cVirtualHost *:80\u003e\n\t\tServerName $domain\n\t\tDocumentRoot /var/www/html/$domain\n\t\tUse Logs $domain\n\t\u003c/VirtualHost\u003e\n\u003c/Macro\u003e\n\nDomain first.example.com\nDomain second.example.com\nDomain third.example.com\n\nUndefMacro Domain\nUndefMacro Logs\n```\n\nIn this example, the `first.example.com` domain will be served from `/var/www/html/first.example.com`, and its logs will be written to:\n- `${APACHE_LOG_DIR}/latest/first.example.com.access.log`\n- `${APACHE_LOG_DIR}/latest/first.example.com.error.log`\n\n## 3. Configure the Exporter\n\nThe exporter requires the following environment variables:\n\n### `HTTP_HOST`\n\nThe host that the HTTP server for metrics will listen on. If omitted, defaults to `127.0.0.1`.\n\n### `ACCESS_LOG_FILE_PATTERN`, `ERROR_LOG_FILE_PATTERN`\n\nThe path to the access/error log files. You may use a single wildcard to match multiple files in a folder, or to match multiple folders in one level of the path. Whatever is matched by the wildcard will become the Prometheus label `file`. If there is no wildcard, the `file` label will be empty.\n\n#### Example 1 (File Name Wildcard)\n\nLog files for all domains are in `/var/log/apache2/latest/` and are named `\u003cdomain\u003e.access.log` and `\u003cdomain\u003e.error.log`. This is the set up from the Apache configuration example above.\n\n**Pattern:** `/var/log/apache2/latest/*.access.log`\n\n- Metrics for `/var/log/apache2/latest/first.example.com.access.log` will be labeled: `first.example.com`\n- Metrics for `/var/log/apache2/latest/first.example.com.error.log` will be labeled: `first.example.com`\n- Metrics for `/var/log/apache2/latest/second.example.com.access.log` will be labeled: `second.example.com`\n\nThe wildcard may appear anywhere in the file name.\n\n#### Example 2 (Folder Wildcard)\n\nEvery domain has its own folder in `/var/log/apache2/latest/` containing log files named `access.log` and `error.log`.\n\n**Pattern:** `/var/log/apache2/latest/*/access.log`\n\n- Metrics for `/var/log/apache2/latest/first.example.com/access.log` will be labeled: `first.example.com`\n- Metrics for `/var/log/apache2/latest/first.example.com/error.log` will be labeled: `first.example.com`\n- Metrics for `/var/log/apache2/latest/second.example.com/access.log` will be labeled: `second.example.com`\n\nThe wildcard must not include any prefix or suffix, so `/*/` is accepted, but `/prefix_*/` or `/*_suffix/` is not.\n\n#### Notes\n\n\u003e The exporter only searches for files when it starts. If you need the exporter to watch a new file or forget a deleted file, you must restart it.\n\n## 4. Launch the Exporter\n\nStart the exporter. The standard output will show which log files have been found, the web server host, and the metrics endpoint URL.\n\nIf no errors are shown, the exporter will begin reading the found log files from the end, and printing each line to the standard output. When a log file is rotated, the exporter will begin reading it from the beginning.\n\nPress `Ctrl-C` to stop the exporter. Signals other than `SIGINT` are ignored.\n\n#### Notes\n\n\u003e The exporter is designed to work and tested with the `rotatelogs` tool in a Linux container. Any other tools or operating systems are unsupported.\n\n\u003e If an error occurs while reading a file or re-opening a rotated file, the exporter will stop watching it and print the error to standard output.\n\n## 5. Collect Prometheus Metrics\n\nCurrently, the exporter exposes only these metrics:\n\n- `apache_requests_total` total number of requests\n- `apache_errors_total` total number of errors\n\nMore detailed metrics will be added in the future.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchylex%2Fapache-prometheus-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchylex%2Fapache-prometheus-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchylex%2Fapache-prometheus-exporter/lists"}