{"id":36798185,"url":"https://github.com/yolossn/query2metric","last_synced_at":"2026-01-12T13:31:50.608Z","repository":{"id":57544117,"uuid":"280242636","full_name":"yolossn/query2metric","owner":"yolossn","description":"A tool to run queries in defined frequency and expose the count as prometheus metrics. Supports MongoDB and SQL","archived":false,"fork":false,"pushed_at":"2020-10-21T10:54:00.000Z","size":465,"stargazers_count":20,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T14:15:06.854Z","etag":null,"topics":["exporter","golang","metrics","prometheus","queries"],"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/yolossn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://www.buymeacoffee.com/yolossn"}},"created_at":"2020-07-16T19:39:24.000Z","updated_at":"2023-08-30T02:19:43.000Z","dependencies_parsed_at":"2022-08-27T18:52:27.516Z","dependency_job_id":null,"html_url":"https://github.com/yolossn/query2metric","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yolossn/query2metric","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolossn%2Fquery2metric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolossn%2Fquery2metric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolossn%2Fquery2metric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolossn%2Fquery2metric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yolossn","download_url":"https://codeload.github.com/yolossn/query2metric/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolossn%2Fquery2metric/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28339157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["exporter","golang","metrics","prometheus","queries"],"created_at":"2026-01-12T13:31:49.630Z","updated_at":"2026-01-12T13:31:50.185Z","avatar_url":"https://github.com/yolossn.png","language":"Go","funding_links":["https://www.buymeacoffee.com/yolossn"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003equery2metric\u003c/h1\u003e\n\u003cp align=\"center\"\u003eA tool to run db queries in defined frequency and expose the count as prometheus metrics.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/yolossn/query2metric/blob/master/images/gopher.png\" height=\"200px\"/\u003e\n\u003c/p\u003e\n\n## Why ?\n\nProduct metrics play an important role in understanding product adoption and historic metrics helps answer many questions about a product (for eg: which day of the week do I get the most signups). One common thing is that most of these metrics are extracted by querying the databases. The tool takes queries and time frequency as configuration and runs the queries in the specified intervals and exposes the output as prometheus metrics.\n\n## Example\n\nCreate a config.yaml file.\n\n\u003e config.yaml\n\n```yml\nconnections:\n  - name: mongodb1\n    type: MONGO\n    connectionStringFromEnv: MONGO_CONN\n    metrics:\n      - name: active_user_count\n        helpString: users in the product\n        database: test\n        collection: test\n        query: '{\"is_active\":true}'\n        time: 10\n      - name: total_user_count\n        helpString: users in the product\n        database: test\n        collection: test\n        query: \"\"\n        time: 120\n  - name: postgres1\n    type: SQL\n    connectionStringFromEnv: POSTGRES_CONN\n    metrics:\n      - name: template_count\n        helpString: products in the db\n        query: select * from templates\n        time: 2\n      - name: active_template_count\n        helpString: products in the db\n        query: error\n        time: 4\n```\n\nAlong with the metrics defined, the success and failure count of queries are also exposed as prometheus metrics.\n\n`query2metric_success_count` - No of successful queries coverted to metrics.\n\n`query2metric_error_count` - No of errors when converting query to metric.\n\nNote: Errors can occur due to invalid queries or connection issues to the db, one can use the logs to debug the issues.\n\n## How to use ?\n\nAt present the tool supports mongo and sql queries. Just create a config.yaml file and run the code.\n\n### Mongo\n\nset `type` as `MONGO` and metrics as given in example with `query`,`time` (in seconds) etc.\n\n```yml\nconnections:\n- name: mongodb1\n    type: MONGO\n    connectionStringFromEnv: MONGO_CONN\n    metrics:\n      - name: active_user_count\n        helpString: users in the product\n        database: test\n        collection: test\n        query: '{\"is_active\":true}'\n        time: 10\n```\n\n### SQL\n\nset `type` as `SQL` and metrics as give in example.\n\n```yml\nconnections:\n  - name: postgres1\n    type: SQL\n    connectionStringFromEnv: POSTGRES_CONN\n    metrics:\n      - name: template_count\n        helpString: products in the db\n        query: select * from templates\n        time: 2\n```\n\n## Run example using docker\n\nYou can run the example along with prometheus and grafana using docker.\n\ndocker-compose.yaml\n\n\u003e docker-compose up\n\nmetrics output: [localhost:8090/metrics](http://localhost:8090/metrics).\n\nprometheus dashboard: [localhost:9090/graph](http://localhost:9090/graph).\n\ngrafana dashboard: [localhost:3000/d/qqTN2unMk/example?orgId=1](http://localhost:3000/d/qqTN2unMk/example?orgId=1).\n\nExample Output:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"720\" height=\"354\" src=\"https://github.com/yolossn/query2metric/blob/master/images/grafana.png\"\u003e\n\u003c/p\u003e\n\n## Credits\n\n- Logo credit [gopherize.me](gopherize.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolossn%2Fquery2metric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyolossn%2Fquery2metric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolossn%2Fquery2metric/lists"}