{"id":13562750,"url":"https://github.com/chop-dbhi/prometheus-sql","last_synced_at":"2025-04-09T17:23:50.587Z","repository":{"id":36541387,"uuid":"40847215","full_name":"chop-dbhi/prometheus-sql","owner":"chop-dbhi","description":"Service that exposes Prometheus metrics for a SQL result set.","archived":false,"fork":false,"pushed_at":"2023-03-06T23:56:51.000Z","size":1876,"stargazers_count":205,"open_issues_count":15,"forks_count":55,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-02T10:48:31.537Z","etag":null,"topics":["metrics","prometheus","sql"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chop-dbhi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2015-08-16T23:18:45.000Z","updated_at":"2025-02-27T07:03:09.000Z","dependencies_parsed_at":"2024-06-20T17:21:45.936Z","dependency_job_id":"4471bd8f-7c8d-4acc-862f-686414af9cfc","html_url":"https://github.com/chop-dbhi/prometheus-sql","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fprometheus-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fprometheus-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fprometheus-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fprometheus-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chop-dbhi","download_url":"https://codeload.github.com/chop-dbhi/prometheus-sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075464,"owners_count":21043590,"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":["metrics","prometheus","sql"],"created_at":"2024-08-01T13:01:11.907Z","updated_at":"2025-04-09T17:23:50.569Z","avatar_url":"https://github.com/chop-dbhi.png","language":"Go","readme":"# Prometheus SQL\n\n*Docker tag `latest` is based on the same commit as the latest released version.*\n\n[![GitHub release](https://img.shields.io/github/release/chop-dbhi/prometheus-sql.svg)](https://github.com/chop-dbhi/prometheus-sql)\n[![Github Releases](https://img.shields.io/github/downloads/chop-dbhi/prometheus-sql/latest/total.svg)](https://github.com/chop-dbhi/prometheus-sql/releases)\n[![Docker Pulls](https://img.shields.io/docker/pulls/dbhi/prometheus-sql.svg)](https://hub.docker.com/r/dbhi/prometheus-sql/)\n[![GoDoc](https://godoc.org/github.com/chop-dbhi/prometheus-sql?status.svg)](https://godoc.org/github.com/chop-dbhi/prometheus-sql)\n\nService that generates basic metrics for SQL result sets and exposing them as Prometheus metrics.\n\nThis service relies on the [SQL Agent](https://github.com/chop-dbhi/sql-agent) service to execute and return the SQL result sets.\n\n[Changelog](https://github.com/chop-dbhi/prometheus-sql/blob/master/CHANGELOG.md)\n\n## Behavior\n\n- Static configuration files are used to define the queries to monitor.\n- Each query has a designated worker for execution.\n- An interval is used to define how often to execute the query.\n- Failed queries are automatically retried using a [backoff](https://en.wikipedia.org/wiki/Exponential_backoff) mechanism.\n- Faceted metrics are supported.\n- A single metric's different facets can be filled in from different data sources.\n\n## Format\n\n- Metric names are exposed in the format `query_result_\u003cmetric name\u003e`.\n- With faceted metrics, the name of the data column is determined by the `data-field` key in config, and all other columns (and column values) are exposed as labels.\n- If the result set consists of a single row and column, the metric value is obvious and `data-field` is not needed.\n- Label names under the same metric should be consistent.\n- Each different query (query entry in config) for the same metric should lead to different label values.\n\n## Usage\n\n```shell\nUsage of prometheus-sql:\n  -config string\n        Configuration file to define common data sources etc.\n  -host string\n        Host of the service. (0.0.0.0)\n  -lax\n        Tolerate invalid files in queryDir\n  -port int\n        Port of the service. (default 8080)\n  -queries string\n        Path to file containing queries. (default \"queries.yml\")\n  -queryDir string\n        Path to directory containing queries.\n  -service string\n        Query of SQL agent service.\n```\n\n### Queries file\n\nA queries file is required for the application to know which data source to query and which queries that shall be monitored.\n\nIn the repository there is an [example file](examples/example-queries.yml) that you can have a look at.\n\n### Config file\n\nThe config file is optional and can defined some default values for queries and data sources which can be referenced by queries. The benefit of referencing a data source will be reduction of duplication of database connection information. See example config file [here](examples/working_example/config.yml) and [queries file](examples/working_example/queries.yml) which utilizes the config information.\n\n### Run via console\n\nCreate a `queries.yml` file in the current directory and run the following:\n\n```shell\nprometheus-sql\n```\n\nor for an alternate path, use the -queries or the -queryDir option:\n\n```shell\nprometheus-sql -queries ${PWD}/queries.yml\n```\n\n### Run using Docker\n\nRun the SQL agent service.\n\n```bash\ndocker run -d --name sqlagent dbhi/sql-agent\n```\n\nRun this service. Mount the `queries.yml` file and link the SQL Agent service.\n\n```shell\ndocker run -d \\\n  --name prometheus-sql \\\n  -p 8080:8080 \\\n  -v ${PWD}/queries.yml:/queries.yml \\\n  --link sqlagent:sqlagent \\\n  dbhi/prometheus-sql\n```\n\nIf you want to separate database connection information etc you can do that by specifying data sources in separate file which you then can mount:\n\n```shell\ndocker run -d \\\n  --name prometheus-sql \\\n  -p 8080:8080 \\\n  -v ${PWD}/queries.yml:/queries.yml \\\n  -v ${PWD}/prometheus-sql.yml:/prometheus-sql.yml \\\n  --link sqlagent:sqlagent \\\n  dbhi/prometheus-sql \\\n  -service http://sqlagent:5000 \\\n  -config prometheus-sql.yml\n```\n\nTo view a plain text version of the metrics, open up the browser to the \u003chttp://localhost:8080/metrics\u003e (or \u003chttp://192.168.59.103:8080/metrics\u003e for boot2docker users).\n\n### Run using a Docker Compose file\n\nAlternately, use the `docker-compose.yml` file included in this repository. The `volumes` section be added for mounting the `queries.yml` file.\n\n## Contributing\n\nRead instructions [how to contribute](CONTRIBUTING.md) before you start.\n\n## FAQ\n\n**How do you I provide additional options to the database connection?**\n\nAdditional options are set in the `config.yml` file, specifically as additional key-value pairs in the [connection map](https://github.com/chop-dbhi/prometheus-sql/blob/master/examples/example-queries.yml#L14-L19). These are passed to the [SQL Agent service](https://github.com/chop-dbhi/sql-agent#connection-options) which construct a DSN string to establish the connection on the backend (alternately you can set the `dsn` key as the full string).\n\nAs an example, a common _gotcha_ when using Postgres in a development environment is to ignore SSL not being enabled on the server. This can be done by adding the `sslmode: disable` option in the connection map.\n\n```yaml\n    # ...\n    connection:\n        host: example.org\n        port: 5432\n        user: postgres\n        password: s3cre7\n        database: products\n        sslmode: disable\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchop-dbhi%2Fprometheus-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchop-dbhi%2Fprometheus-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchop-dbhi%2Fprometheus-sql/lists"}