{"id":13684148,"url":"https://github.com/simplifi/anemometer","last_synced_at":"2025-07-05T02:36:38.899Z","repository":{"id":144345649,"uuid":"267385375","full_name":"simplifi/anemometer","owner":"simplifi","description":"Anemometer is a tool for running SQL queries and pushing results as metrics to Datadog","archived":false,"fork":false,"pushed_at":"2025-02-17T18:53:31.000Z","size":123,"stargazers_count":28,"open_issues_count":2,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-30T20:33:13.023Z","etag":null,"topics":["datadog","go","golang","monitoring","nomad","sql","statsd"],"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/simplifi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-27T17:35:44.000Z","updated_at":"2025-02-17T18:53:26.000Z","dependencies_parsed_at":"2024-06-11T21:25:29.747Z","dependency_job_id":"8a77e27f-7ea7-45d4-be60-065544622469","html_url":"https://github.com/simplifi/anemometer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/simplifi/anemometer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplifi%2Fanemometer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplifi%2Fanemometer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplifi%2Fanemometer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplifi%2Fanemometer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplifi","download_url":"https://codeload.github.com/simplifi/anemometer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplifi%2Fanemometer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263671882,"owners_count":23494057,"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":["datadog","go","golang","monitoring","nomad","sql","statsd"],"created_at":"2024-08-02T14:00:27.278Z","updated_at":"2025-07-05T02:36:38.865Z","avatar_url":"https://github.com/simplifi.png","language":"Go","readme":"# Anemometer\n\n[![Build Status](https://travis-ci.com/simplifi/anemometer.svg?branch=master)](https://travis-ci.com/simplifi/anemometer) [![Go Report Card](https://goreportcard.com/badge/github.com/simplifi/anemometer)](https://goreportcard.com/report/github.com/simplifi/anemometer) [![Release](https://img.shields.io/github/release/simplifi/anemometer.svg)](https://github.com/simplifi/anemometer/releases/latest)\n\n\u003cimg src=\"assets/anemometer.png\" width=\"100\"\u003e\n\nAnemometer is a tool for running SQL queries and pushing results as metrics to Datadog\n\n\n## Why \"Anemometer\"\n\n\u003e An anemometer is a device used for measuring wind speed and direction.\n\nThis project was originally created to help us monitor some tables in Airflow, but was later updated so it could work\ngenerically with any database.\n\n## Supported Databases\n\nWe currently support the following databases:\n- Postgres\n- Vertica\n\n### Adding support for another database\n\nSupport for any of the databases listed [here](https://github.com/golang/go/wiki/SQLDrivers#drivers) can be added fairly easily!\n- Read [How to contribute](#how-to-contribute)\n- Add the driver to [`go.mod`](https://github.com/simplifi/anemometer/blob/master/go.mod), and ensure [`go.sum`](https://github.com/simplifi/anemometer/blob/master/go.sum) gets updated\n- Add import for the new driver to [`monitor.go`](https://github.com/simplifi/anemometer/blob/master/pkg/anemometer/monitor/monitor.go)\n- Update this README to add the new database\n- Submit a Pull Request\n\n# Setup\n\nThe latest version of Anemometer can be found on the [Releases](https://github.com/simplifi/anemometer/releases) tab.\n\n## Example Configuration:\n```yaml\nstatsd:\n  address: 127.0.0.1:8125\n  tags:\n    - environment:production\nmonitors:\n  - name: airflow-dag-disabled\n    database:\n      type: postgres\n      uri: postgresql://username:password@localhost:5432/database?sslmode=disable\n    sleep_duration: 300\n    metric: airflow.dag.disabled\n    sql: \u003e\n      SELECT  dag_id AS dag_id,\n              CASE WHEN is_paused AND NOT is_subdag THEN 1 ELSE 0 END AS metric\n      FROM    dag\n  - name: airflow-task-queued-seconds\n    database:\n      type: postgres\n      uri: postgresql://username:password@localhost:5432/database?sslmode=disable\n    sleep_duration: 300\n    metric: airflow.task.queued_seconds\n    sql: \u003e\n      SELECT dag_id AS dag_id,\n             task_id AS task_id,\n             EXTRACT(EPOCH FROM (current_timestamp - queued_dttm)) AS metric\n      FROM   task_instance\n      WHERE  state = 'queued'\n```\n\n### `statsd`\nThis is where you tell Anemometer where to send StatsD metrics\n- `address` - The address:port on which StatsD is listening (usually `127.0.0.1:8125`)\n- `tags` - Default tags to send with every metric, optional\n\n### `monitors`\nThis is where you tell Anemometer about the monitor(s) configuration\n- `name` - The name of this monitor, mainly used in logging\n- `database.type` - The type of database connection to be used (`postgres` and `vertica` are currently supported)\n- `database.uri` - The URI connection string used to connect to the database (usually follows `protocol://username:password@hostname:port/database`)\n- `sleep_duration` - How long to wait between pushes to StatsD (in seconds)\n- `metric` - The name of the metric to be sent to StatsD\n- `sql` - The SQL query to execute when populating the metric's values/tags (see [SQL Query Structure](#sql-query-structure))\n\n## SQL Query Structure\n\nAnemometer makes the following assumptions about the results of your query:\n- Exactly one column will be named `metric`, and the value is convertable to `float64` (no strings)\n- All other columns will be aggregated into tags and sent to StatsD\n- The tags will take the form of `column_name:value`\n\n### Query Example\n\n#### Single row result\n\nTo monitor the number of records in your user's table you might do something like this:\n```SQL\nSELECT 'production' AS environment,\n       'users' AS table_name,\n       COUNT(0) AS metric\nFROM   users\n```\n\nResulting in the following:\n```\n environment | table_name | metric\n-------------+------------+--------\n production  | users      |     99\n```\n\nAssuming we named our metric `table.records`, this would result in the following data being sent to StatsD:\n`table.records:99|g|#environment:production,table_name:users`\n\n#### Multiple row result\n\nTo monitor the number of queries each user is running in your database you might do something like this:\n```SQL\nSELECT   'production' AS environment,\n         usename AS user_name,\n         COUNT(0) AS metric\nFROM     pg_stat_activity\nWHERE    query != '\u003cIDLE\u003e'\nGROUP BY usename\n```\n\nResulting in the following:\n```\n environment | user_name | metric\n-------------+-----------+--------\n production  | cjonesy   |    160\n production  | postgres  |      6\n```\n\nAssuming we named our metric `database.queries`, this would result in the following data being sent to StatsD:\n`database.queries:160|g|#environment:production,user_name:cjonesy`\n`database.queries:6|g|#environment:production,user_name:postgres`\n\nNotice that one metric is sent for each row in the query.\n\n# Usage\n\n### Basic Usage\n```\nAnemometer (A SQL -\u003e StatsD metrics generator)\n\nUsage:\n  anemometer [command]\n\nAvailable Commands:\n  help        Help about any command\n  start       Start the Anemometer agent\n  version     Print the version number\n\nFlags:\n  -h, --help   help for anemometer\n\nUse \"anemometer [command] --help\" for more information about a command.\n```\n\n### To start the agent:\n```shell script\nanemometer start -c /path/to/your/config.yml\n```\n\n# Development\n\n### Testing locally\nIf you want to test this out locally you can run the following to start Anemometer:\n```shell script\nanemometer start -c /path/to/config.yml\n```\n\nYou can see the metrics that would be sent by watching the statsd port on localhost:\n```shell script\nnc -u -l 8125\n```\n\n### Compiling\n```shell script\nmake build\n```\n\n### Running Tests\nTo run all the standard tests:\n```shell script\nmake test\n```\n\n### Releasing\nThis project is using [goreleaser](https://goreleaser.com). GitHub release creation is automated using Travis CI. New releases are automatically created when new tags are pushed to the repo.\n```shell script\n$ TAG=0.1.0 make tag\n```\n\n## How to contribute\nThis project has some clear Contribution Guidelines and expectations that you can read here ([CONTRIBUTING](CONTRIBUTING.md)).\n\nThe contribution guidelines outline the process that you'll need to follow to get a patch merged.\n\nAnd you don't just have to write code. You can help out by writing documentation, tests, or even by giving feedback about this work.\n\nThank you for contributing!","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplifi%2Fanemometer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplifi%2Fanemometer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplifi%2Fanemometer/lists"}