{"id":13582193,"url":"https://github.com/ricoberger/loki_exporter","last_synced_at":"2025-10-04T22:31:24.769Z","repository":{"id":54339526,"uuid":"162022781","full_name":"ricoberger/loki_exporter","owner":"ricoberger","description":"Prometheus exporter to collect metrics and run queries against the Grafana Loki API.","archived":true,"fork":false,"pushed_at":"2020-02-27T17:24:33.000Z","size":54,"stargazers_count":39,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-15T21:51:49.755Z","etag":null,"topics":["alertmanager","docker","go","grafana","loki","prometheus","prometheus-exporter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricoberger.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}},"created_at":"2018-12-16T17:05:24.000Z","updated_at":"2023-08-28T06:57:30.000Z","dependencies_parsed_at":"2022-08-13T12:31:05.033Z","dependency_job_id":null,"html_url":"https://github.com/ricoberger/loki_exporter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricoberger%2Floki_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricoberger%2Floki_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricoberger%2Floki_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricoberger%2Floki_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricoberger","download_url":"https://codeload.github.com/ricoberger/loki_exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235321013,"owners_count":18971230,"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":["alertmanager","docker","go","grafana","loki","prometheus","prometheus-exporter"],"created_at":"2024-08-01T15:02:29.052Z","updated_at":"2025-10-04T22:31:19.503Z","avatar_url":"https://github.com/ricoberger.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# loki_exporter\n\nThe [loki_exporter](https://github.com/ricoberger/loki_exporter) is a [Prometheus](https://prometheus.io) exporter for Loki. [Loki](https://github.com/grafana/loki) is a horizontally-scalable, highly-available, multi-tenant log aggregation system from the creators of [Grafana](https://grafana.com). The loki_exporter runs queries against the Loki API and returns the number of entries for each stream. This exporter is designed to detect critical log events, where the results can be used to create alerts in Prometheus.\n\n## Building and running\n\nTo run the loki_exporter you can use the [prebuild binaries](https://github.com/ricoberger/loki_exporter/releases) or the official Docker image from [Docker Hub](https://hub.docker.com/r/ricoberger/loki_exporter).\n\n### Local Build\n\n```sh\nmake build\n./bin/loki_exporter \u003cflags\u003e\n```\n\nVisiting http://localhost:9524/metrics will return metrics for all queries. The `loki_success` metric indicates if the execution of the queries succeeded.\n\n### Building with Docker\n\n```sh\ndocker build -t loki_exporter .\ndocker run -d -p 9524:9524 --name loki_exporter -v `pwd`:/config loki_exporter --config.file=/config/config.yml\n```\n\n## Usage and configuration\n\nThe loki_exporter is configured via a configuration file and command-line flags.\n\n```\nUsage of ./bin/loki_exporter:\n  -config.file string\n    \tConfiguration file in YAML format. (default \"config.yml\")\n  -version\n    \tShow version information.\n  -web.listen-address string\n    \tAddress to listen on for web interface and telemetry. (default \":9524\")\n  -web.telemetry-path string\n    \tPath under which to expose metrics. (default \"/metrics\")\n```\n\nThe configuration file is written in YAML format, defined by the scheme described below.\n\n```yaml\n# ======================== loki_exporter configuration =========================\n#\n# The loki_exporter is a Prometheus exporter for Loki. Loki is a\n# horizontally-scalable, highly-available, multi-tenant log aggregation system\n# from the creators of Grafana. The loki_exporter runs queries against the Loki\n# API and returns the number of entries for each stream. This exporter is\n# designed to detect critical log events, where the results can be used to\n# create alerts in Prometheus.\n#\n# ------------------------------------ Loki ------------------------------------\n#\nloki:\n  listenAddress: \u003cstring\u003e\n  basicAuth:\n    enabled: \u003cboolean\u003e\n    username: \u003cstring\u003e\n    password: \u003cstring\u003e\n#\n# ---------------------------------- Metrics -----------------------------------\n#\nmetrics:\n  labels: \u003cboolean\u003e\n  labelValues: \u003cboolean\u003e\n  queries: \u003cboolean\u003e\n#\n# ---------------------------------- Queries -----------------------------------\n#\nqueries:\n  - name: \u003cstring\u003e\n    query: \u003cstring\u003e\n    limit: \u003cinteger\u003e\n    start: \u003cstring\u003e\n    end: \u003cstring\u003e\n    direction: \u003cstring\u003e\n```\n\nThe configuration file is divided into three sections. The `loki` section is used for the configuration of the Loki API endpoint. The default value for the `listenAddress` is `http://localhost:3100` and basic authentication is disabled by default.\n\nThe metrics section enables/disables the different type of metrics, which should be exported.\n\nThe `queries` section represents all queries which should be run against the Loki API. The parameters and default values can be found in the following table:\n\n| Parameter | Description | Default Value |\n| --------- | ----------- | ------------- |\n| `name` | A custom name for the query. The name is used for the exported metric: `loki_query_name` | |\n| `query` | Query must be a logQL query. | |\n| `limit` | Maximum number of entries which should be returned by the Loki API. | `-1` |\n| `start` | The start time for the query. Must be a valid golang duration string. The duration is added to the current time. | `-24h` |\n| `end` | The end time for the query. Must be a valid golang duration string. The duration is added to the current time. | `0s` |\n| `direction` | Search direction must be `forward` or `backward`, useful when specifying a limit. | |\n\n## Example\n\nThe example is based on the official example from the [Loki documentation](https://github.com/grafana/loki). Clone the repository, go to the `examples` folder and run the `docker-compose` file. The `docker-compose` file will start a docker image for Loki, Promtail, Grafana, Prometheus and the loki_exporter.\n\n```sh\ngit clone https://github.com/ricoberger/loki_exporter.git\ncd loki_exporter/example\ndocker-compose up\n```\n\nVisiting the loki_exporter output on [http://localhost:9524](http://localhost:9524). The output will look like the one at the end of this section. You can also open the Prometheus dashboard on [http://localhost:9090](http://localhost:9090). There you can find the `loki_` metrics if in one of you log files under `/var/logs` an error occured.\n\n```\n# HELP loki_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which loki_exporter was built.\n# TYPE loki_exporter_build_info gauge\nloki_exporter_build_info{branch=\"master\",goversion=\"go1.11\",revision=\"841cbe36cf84fcf6f0a61d33e16930c63d12792c\",version=\"v0.1.0-1-g841cbe3\"} 1\n# HELP loki_exporter_total_scrapes Current total loki scrapes.\n# TYPE loki_exporter_total_scrapes counter\nloki_exporter_total_scrapes 2\n# HELP loki_label_values_total total number of label values\n# TYPE loki_label_values_total gauge\nloki_label_values_total{label=\"__filename__\"} 26\nloki_label_values_total{label=\"job\"} 1\n# HELP loki_labels_total total number of label\n# TYPE loki_labels_total gauge\nloki_labels_total 2\n# HELP loki_query_varlogs_total number of entries\n# TYPE loki_query_varlogs_total gauge\nloki_query_varlogs_total{filename=\"/var/log/docker.log\",job=\"varlogs\"} 165\nloki_query_varlogs_total{filename=\"/var/log/docker.log.0\",job=\"varlogs\"} 33\nloki_query_varlogs_total{filename=\"/var/log/kmsg.log\",job=\"varlogs\"} 3\nloki_query_varlogs_total{filename=\"/var/log/vpnkit-forwarder.log\",job=\"varlogs\"} 183\nloki_query_varlogs_total{filename=\"/var/log/vsudd.log\",job=\"varlogs\"} 7\nloki_query_varlogs_total{filename=\"/var/log/vsudd.log.0\",job=\"varlogs\"} 6\n# HELP loki_success Was the last scrape of loki successful.\n# TYPE loki_success gauge\nloki_success 1\n```\n\n## Dependencies\n\n- [yaml.v2 - YAML support for the Go language](gopkg.in/yaml.v2)\n- [Prometheus Go client library](github.com/prometheus/client_golang)\n- [Common - Go libraries shared across Prometheus components and libraries](github.com/prometheus/common)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricoberger%2Floki_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricoberger%2Floki_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricoberger%2Floki_exporter/lists"}