{"id":21470141,"url":"https://github.com/sensu-plugins/sensu-extensions-influxdb2","last_synced_at":"2025-10-14T12:49:06.714Z","repository":{"id":52421470,"uuid":"91836796","full_name":"sensu-plugins/sensu-extensions-influxdb2","owner":"sensu-plugins","description":null,"archived":false,"fork":false,"pushed_at":"2021-04-29T19:17:46.000Z","size":77,"stargazers_count":7,"open_issues_count":9,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-09-02T21:37:21.713Z","etag":null,"topics":["influxdb","sensu","sensu-extensions","sensu-handler","sensu-plugins"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sensu-plugins.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-05-19T19:00:09.000Z","updated_at":"2023-04-18T12:47:53.000Z","dependencies_parsed_at":"2022-09-06T08:11:06.497Z","dependency_job_id":null,"html_url":"https://github.com/sensu-plugins/sensu-extensions-influxdb2","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sensu-plugins/sensu-extensions-influxdb2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-extensions-influxdb2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-extensions-influxdb2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-extensions-influxdb2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-extensions-influxdb2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sensu-plugins","download_url":"https://codeload.github.com/sensu-plugins/sensu-extensions-influxdb2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-extensions-influxdb2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018577,"owners_count":26086579,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["influxdb","sensu","sensu-extensions","sensu-handler","sensu-plugins"],"created_at":"2024-11-23T09:23:59.272Z","updated_at":"2025-10-14T12:49:06.695Z","avatar_url":"https://github.com/sensu-plugins.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"__NOTE:__ running `sensu-install -e sensu-extensions-influxdb` will __NOT__ install this extension, as a project with the same name already exists on Rubygems.org. Before reporting any issues here, make sure you are using this version of the extension. (_hint:_ check the version number on the logs) In order to install this extension, run `sensu-install -e sensu-extensions-influxdb2`.\n\n# Requirements\n\nThis extension uses InfluxDB [Line Protocol](https://influxdb.com/docs/v0.9/write_protocols/line.html) over HTTP to send metrics.\n\nSince Sensu already uses [eventmachine](https://github.com/eventmachine/eventmachine), you just have to ensure that em-http-request gem is present inside Sensu's embedded Ruby :\n* `em-http-request` ruby gem\n\nBy default, this extension uses in memory metrics caching : it makes InfluxDB writes batched.\nThis cache is flushed every __500 items__ or __6 seconds__ (this values can be changed in conf).\n\n## Caveat\n* SSL/TLS connection to InfluxDB is still broken in Sensu `0.20.6`. We're waiting for a Ruby / EM upgrade in Sensu project :\n    * https://github.com/sensu/sensu/issues/1084\n\n# Usage\nThe configuration options are pretty straight forward.\n\nMetrics are inserted into the database using the check's key name as _measurement_ name. So if you're using the `sensu-plugins-load-checks` community plugin :\n```\nmy-host-01.load_avg.one 0.02 1444824197\nmy-host-01.load_avg.five 0.04 1444824197\nmy-host-01.load_avg.fifteen 0.09 1444824197\n```\nIn this example, you'll have 3 differents _measurements_ in your database :\n```\n\u003e show measurements\nname: measurements\n------------------\nname\nmy-host-01.load_avg.fifteen\nmy-host-01.load_avg.five\nmy-host-01.load_avg.one\n```\n\n```\n\u003e select * from \"my-host-01.load_avg.one\";\nname: my-host-01.load_avg.one\n------------------\ntime                  host        value  duration\n2015-10-14T13:53:22Z  my-host-01  0.34   0.399\n2015-10-14T13:53:32Z  my-host-01  0.29   0.419\n2015-10-14T13:53:42Z  my-host-01  0.39   0.392\n2015-10-14T13:53:52Z  my-host-01  0.41   0.398\n[...]\n```\n\nAdditionally a `duration` value will be present based on the time it took the check to run (this is gleaned from the sensu event data).\n\nThe name of the _measurement_ is based on the value of `strip_metric` and/or a template, as described below.\nThe name of the key ```host``` is grabbed from sensu event client name.\n\n## Extension not a handler\nNote that the first push of this was a handler that could be called via `pipe`. This is now an actual extension that's more performant since it's actually in the sensu-server runtime. Additionally it's now using batch submission to InfluxDB by writing all the points for a given series at once.\n\nTo [load the extension](https://sensuapp.org/docs/latest/reference/extensions.html), you will need to install the gem into the sensu ruby, and then add the following config file\n```json\n{\n  \"extensions\": {\n    \"influxdb\": {\n      \"gem\": \"sensu-extensions-influxdb2\"\n    },\n    \"history\": {\n      \"gem\": \"sensu-extensions-history\"\n    }\n  }\n}\n```\n\n**NOTE**: Even though this gem is called `sensu-extensions-influxdb`, the way sensu loads the extension is by parsing the name of the gem, and loading the library. This is why we have to specify `sensu-extensions-history`, even though that gem doesn't exist.\n\nCreate a set to wrap this extension into a callable handler. In this example, we created a ```metrics``` handler wrapping a debug output and this Influx extension :\n\n_/etc/sensu/conf.d/handlers/metrics.json_ :\n```json\n{\n  \"handlers\": {\n    \"metrics\": {\n      \"type\": \"set\",\n      \"handlers\": [\n        \"debug\",\n        \"influxdb\"\n      ]\n    }\n  }\n}\n```\n\n_Note :_ Since Sensu 0.17.1 you can also use extension name directly :\n```\nCheck definitions can now specify a Sensu check extension to run,\n\"extension\", instead of a command.\n```\n\n## Handler config\n\n`/etc/sensu/conf.d/influxdb.json`\n```json\n{\n  \"influxdb\": {\n    \"database\": \"stats\",\n    \"host\": \"localhost\",\n    \"port\": \"8086\",\n    \"username\": \"stats\",\n    \"password\": \"stats\",\n    \"use_ssl\": false,\n    \"strip_metric\": \"host\",\n    \"tags\": {\n      \"region\": \"my-dc-01\",\n      \"stage\": \"prod\"\n    },\n    \"templates\": [\n      {\"^sensu\\\\.checks\\\\..*\": \"source.measurement.field*\"},\n      {\".*\\\\.cgroup\\\\..*\": \"host.path.component\"}\n    ]\n  }\n}\n```\n\n### Config attributes\n\n* `host`, `port`, `username`, `password` and `database` are pretty straight forward. If `use_ssl` is set to true, the connection to the influxdb server will be made using https instead of http.\n\n* `use_basic_auth` if your InfluxDB is behind a proxy that requires authentication you can set this to `true`, in that case you also have to define `basic_user` and `basic_pass`.\n\n* `filters` allow's you to \"find and replace\" words/patterns in the key, it's a Hash where the key is a regex pattern and the value is a string that should replace it. (these are passed directly to the gsub method). Filters are applyed before any other transformations like templates.\n\n* `templates` like with the InfluxDB Graphite plugin, you can specify patterns and formats, if the metric name matches the pattern, the template will be applied. Templates can be defined per check, in the check configuration, or globaly in the handler's configuration. Parts of the metric name will be converted into tags, reducing the measurement name in InfluxDB whilst keeping all the information as tags or fields.\nYou can specifty multiple templates, if your metric matches more than one the first one will be used.\nFor example, if you have a metric named:\n```\n  ip-10-0-1-32.host_stats.load_avg 3\n```\nYou can set a template like:\n```json\n  \"templates\": {\n    \".*\\\\.host_stats\\\\..*\": \"host.type\"\n  }\n```\nAnd as a result the following will be sent to InfluxDB:\n```\n  load_avg,host=ip-10-0-1-32,type=host_stats value=3\n```\nYou can also use three special keywords in your templates, `void`, `measurement` and `field` and these can be used with a `*` at the end.\nExample, considereing the following metrics:\n```\n  ip-10-0-1-32.host_stats.load_avg.one 3\n  ip-10-0-1-32.host_stats.load_avg.five 9\n  ip-10-0-1-32.host_stats.load_avg.fifteen 13\n```\nYou could create a template like this:\n```json\n  \"templates\": {\n    \".*\\\\.host_stats\\\\..*\": \"host.measurement.field*\"\n  }\n```\nAnd you would get:\n```\n  host_stats,host=ip-10-0-1-32 load_avg.one=3\n  host_stats,host=ip-10-0-1-32 load_avg.five=9\n  host_stats,host=ip-10-0-1-32 load_avg.fifteen=13\n```\nOr, a template like this:\n```json\n  \"templates\": {\n    \".*\\\\.host_stats\\\\..*\": \"host.measurement.field.aggregation\"\n  }\n```\nWould get you:\n```\n  host_stats,host=ip-10-0-1-32,aggregation=one load_avg=3\n  host_stats,host=ip-10-0-1-32,aggregation=five load_avg=9\n  host_stats,host=ip-10-0-1-32,aggregation=fifteen load_avg=13\n```\nthe `void` keyword will make the handler ignore that part of the metric name.\n\n* `tags` hash is also pretty straight forward. Just list here in a flat-hash design as many influxdb tags you wish to be added in your measures. This can also be set both in the handler configuration or as part of the check configuration.\n\n* `strip_metric` however might not be. This is used to \"clean up\" the data sent to influxdb. Normally everything sent to handlers is akin to the `graphite`/`stats` style:\n```\n  something.host.metrictype.foo.bar\n```\nor\n```\n  host.stats.something.foo.bar\n```\n\nReally the pattern is irrelevant. People have different tastes. Adding much of that data to the column name in InfluxDB is rather silly so `strip_metric` provides you with a chance to add a value that strips off everything up to (and including that value). This allows you to continue sending to graphite or statsd or whatever and still use this handler.\n\nUsing the examples above, if you set the `strip_metric` to `host`, then the measurement in InfluxDB would be called `metrictype.foo.bar` or `stats.something.foo.bar`. If you set the value to `foo` then the measurement would simply be called `foo`\n\nNote that :\n* `strip_metric` isn't required.\n* `strip_metric` can be set either in the handler configuration or as part of the check configuration, check configuration takes precedence.\n* you can cleanup an arbitrary string from your keyname or use `host` as special value to cleanup the sensu event client name from your key.\n\n#### Other attributes\n\n* `time_precision` : global checks time precision (default is `'s'`)\n* `buffer_max_size` : buffer size limit before flush - This is the amount of points in the InfluxDB batch - (default is `500`)\n* `buffer_max_age` : buffer maximum age - Flush will be forced after this amount of time - (default is `6` seconds)\n* `Proxy mode` : If the extension is configured to be in proxy mode, it will skip the transformation step and assume that the data is valid [line protocol](https://docs.influxdata.com/influxdb/latest/write_protocols/line_protocol_reference). It will not take into account any tags defined in the sensu-configuration.\n* `enhanced_history`: by default this extension writes checks history as separated measurements on InfluxDB. Setting this attribute to true will write all check history in the same metric (sensu.checks), tagging check name and subscriptions (if any), allowing the user to write InfluxDB queries filtering by check name and subscriptions.\n\n## Check options\n\nIn the check config, an optional `influxdb` section can be added, containing a `database` option and `tags`.\nYou can also set `proxy_mode` in this section on the checks to override the default configuration set on the handler. This way checks that use the InfluxDB line protocol can coexsist with checks that use the Graphite format and use the same handler.\nAs mentioned above you can also specify `strip_metric`, `templates` and `filters`,  in the check configuration.\nIf specified, this overrides the default `database` and `strip_metric` options in the handler config and adds (or overrides) influxdb tags and templates.\n\nThis allows events to be written to different influxdb databases and modify key indexes on a check-by-check basis.\n\nYou can also specify the time precision of your check script in the check config with the `time_precision` attribute.\n\n### Example check config\n\n`/etc/sensu/conf.d/checks/metrics-load.json`\n```json\n{\n  \"checks\": {\n    \"metrics-load\": {\n      \"type\": \"metric\",\n      \"command\": \"metrics-load.rb\",\n      \"standalone\": true,\n      \"handlers\": [\n        \"metrics\"\n      ],\n      \"interval\": 60,\n      \"time_precision\": \"s\",\n      \"influxdb\": {\n        \"database\": \"custom-db\",\n        \"tags\": {\n           \"stage\": \"prod\",\n           \"region\": \"eu-west-1\"\n        },\n        \"templates\": {\n          \"^load_avg\\\\..*\": \"measurement.field\"\n        }\n      }\n    }\n  }\n}\n```\n\n_Result_ :\n```\nload_avg,stage:prod,region:eu-west-1,host:iprint-test-sa-01.photobox.com one=1.04,duration=0.402  1444816792147\nload_avg,stage:prod,region:eu-west-1,host:iprint-test-sa-01.photobox.com five=0.86,duration=0.398 1444816792147\nload_avg,stage:prod,region:eu-west-1,host:iprint-test-sa-01.photobox.com fifteen=0.84,duration=0.375 1444816792147\n\n * will be sent to -\u003e http://my-influx09.company.com:8086/db/custom-db/series?time_precision=s\u0026u=sensu\u0026p=sensu\n```\n\nWithout the tags and templates you would get:\n```\nload_avg.one,host:iprint-test-sa-01.photobox.com value=1.04,duration=0.402  1444816792147\nload_avg.five,host:iprint-test-sa-01.photobox.com value=0.86,duration=0.398 1444816792147\nload_avg.fifteen,host:iprint-test-sa-01.photobox.com value=0.84,duration=0.375 1444816792147\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensu-plugins%2Fsensu-extensions-influxdb2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsensu-plugins%2Fsensu-extensions-influxdb2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensu-plugins%2Fsensu-extensions-influxdb2/lists"}