{"id":16956973,"url":"https://github.com/jgraichen/telegraf-ruby","last_synced_at":"2025-04-09T13:06:30.890Z","repository":{"id":44787336,"uuid":"97718061","full_name":"jgraichen/telegraf-ruby","owner":"jgraichen","description":"Send events from Ruby to a Telegraf agent","archived":false,"fork":false,"pushed_at":"2025-03-08T12:52:12.000Z","size":3395,"stargazers_count":13,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-02T06:51:30.930Z","etag":null,"topics":["influx","metrics","rack","rails","ruby","telegraf"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jgraichen.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-19T13:16:46.000Z","updated_at":"2025-03-08T12:52:17.000Z","dependencies_parsed_at":"2024-03-10T21:28:27.447Z","dependency_job_id":"1be4ca9e-b7d8-4121-98d8-745b2326819e","html_url":"https://github.com/jgraichen/telegraf-ruby","commit_stats":{"total_commits":93,"total_committers":8,"mean_commits":11.625,"dds":"0.21505376344086025","last_synced_commit":"e498bebdadc0c525e45ca18d1fbb1ab735e88c77"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraichen%2Ftelegraf-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraichen%2Ftelegraf-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraichen%2Ftelegraf-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraichen%2Ftelegraf-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgraichen","download_url":"https://codeload.github.com/jgraichen/telegraf-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045231,"owners_count":21038553,"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":["influx","metrics","rack","rails","ruby","telegraf"],"created_at":"2024-10-13T22:16:30.669Z","updated_at":"2025-04-09T13:06:30.872Z","avatar_url":"https://github.com/jgraichen.png","language":"Ruby","readme":"# Telegraf\n\n[![Gem Version](https://img.shields.io/gem/v/telegraf?logo=ruby)](https://rubygems.org/gems/telegraf)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jgraichen/telegraf-ruby/test.yml?logo=github)](https://github.com/jgraichen/telegraf-ruby/actions)\n\nSend events to a local [Telegraf](https://github.com/influxdata/telegraf) agent or anything that can receive the InfluxDB line protocol.\n\nIt further includes plugins for Rack, Rails, ActiveJob and Sidekiq to collect request events. See plugin usage details below.\n\n## Examples\n\n\u003ctable cellpadding=\"0\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"./examples/app-perf-light.png\"\u003e\n        \u003cpicture\u003e\n          \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./examples/app-perf-dark.png\"\u003e\n          \u003cimg alt=\"Screenshot of a Grafana dashboard showing overview metrics about the application controllers performance such as slow actions, controller runtime breakdown, total time consumption\" src=\"./examples/app-perf-light.png\"\u003e\n        \u003c/picture\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"./examples/controller-dark.png\"\u003e\n        \u003cpicture\u003e\n          \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./examples/controller-dark.png\"\u003e\n          \u003cimg alt=\"Screenshot of a Grafana dashboard showing detailed metrics about an individual controller actions including a flamegraph for request performance\" src=\"./examples/controller-light.png\"\u003e\n        \u003c/picture\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003c/tr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"./examples/queue-time-light.png\"\u003e\n        \u003cpicture\u003e\n          \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./examples/queue-time-dark.png\"\u003e\n          \u003cimg alt=\"Screenshot of a Grafana dashboard showing detailed queue time metrics including percentiles and median for multiple applications\" src=\"./examples/queue-time-light.png\"\u003e\n        \u003c/picture\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"./examples/jobs-light.png\"\u003e\n        \u003cpicture\u003e\n          \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./examples/jobs-dark.png\"\u003e\n          \u003cimg alt=\"Screenshot of a Grafana dashboard showing metrics about sidekiq background jobs such as runtime and errors\" src=\"./examples/jobs-light.png\"\u003e\n        \u003c/picture\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Installation\n\n```ruby\ngem 'telegraf'\n```\n\nAnd then execute:\n\n```console\nbundle\n```\n\nOr install it yourself as:\n\n```ruby\ngem install telegraf\n```\n\n## Usage as a library\n\nConfigure telegraf socket listener e.g.:\n\n```toml\n[[inputs.socket_listener]]\n  service_address = \"udp://localhost:8094\"\n```\n\n```ruby\ntelegraf = Telegraf::Agent.new 'udp://localhost:8094'\ntelegraf = Telegraf::Agent.new # default: 'udp://localhost:8094'\n\ntelegraf.write('demo',\n    tags: {tag_a: 'A', tag_b: 'B'},\n    values: {value_a: 1, value_b: 1.5})\n\ntelegraf.write([{\n    series: 'demo',\n    tags: {tag_a: 'A', tag_b: 'B'},\n    values: {value_a: 1, value_b: 1.5}\n}])\n```\n\nThere is no buffer or batch handling, nor connection pooling or keep alive. Each `#write` creates a new connection (unless it's a datagram connection).\n\nThere is no exception handling.\n\n## Using the Rack and Rails plugins\n\nThis gem includes a Rails plugin and middlewares / adapters for Rack, ActiveJob and Sidekiq, to collect request and background worker events. You need to require them explicitly:\n\n### Rack\n\n```ruby\nrequire \"telegraf/rack\"\n\nagent = ::Telegraf::Agent.new\nuse ::Telegraf::Rack.new(series: 'rack', agent: agent, tags: {global: 'tag'})\n```\n\nSee middleware [class documentation](lib/telegraf/rack.rb) for more details.\n\nThe Rack middleware supports parsing the `X-Request-Start: t=\u003ctimestamp\u003e` header expecting a fractional (UTC) timestamp when the request has been started or first received by e.g. a load balancer. An additional value `queue_ms` with the queue time will be included.\n\n### Rails\n\nThe Rails plugin needs to be required, too, but will automatically install additional components (Rack, ActiveJob, Sidekiq and Rails-specific instrumentation).\n\n```ruby\n# e.g. in application.rb\n\n# Load rails plugin (!) or add `require: 'telegraf/rails'` to Gemfile\nrequire \"telegraf/rails\"\n\nclass MyApplication \u003e ::Rails::Application\n  # Configure receiver\n  config.telegraf.connect = \"udp://localhost:8094\"\n\n  # Global tags added to all events. These will override\n  # any local tag with the same name.\n  config.telegraf.tags = {}\n\n  # By default the Rack middleware to collect events is installed\n  config.telegraf.rack.enabled = true\n  config.telegraf.rack.series = \"requests\"\n  config.telegraf.rack.tags = {}\n\n  # These are the default settings when ActiveJob is detected\n  config.telegraf.active_job.enabled = true\n  config.telegraf.active_job.series = \"active_job\"\n  config.telegraf.active_job.tags = {}\n\n  # These are the default settings when Sidekiq is detected\n  config.telegraf.sidekiq.enabled = true\n  config.telegraf.sidekiq.series = \"sidekiq\"\n  config.telegraf.sidekiq.tags = {}\n\n  # Additionally the application is instrumented to tag events with\n  # controller and action as well as to collect app, database and view timings\n  config.telegraf.instrumentation = true\nend\n```\n\nReceived event example:\n\n```text\nrequests,action=index,controller=TestController,instance=TestController#index,method=GET,status=200 db_ms=0.0,view_ms=2.6217450003969134,action_ms=2.702335,app_ms=4.603561000294576,send_ms=0.09295000018028077,request_ms=4.699011000411701,queue_ms=0.00003000028323014\n```\n\nSee the various classes' documentation for more details on the collected tags and values:\n\n- [Rack middleware](lib/telegraf/rack.rb)\n- [Rails plugin](lib/telegraf/railtie.rb)\n- [ActiveJob plugin](lib/telegraf/active_job.rb)\n- [Sidekiq middleware](lib/telegraf/sidekiq.rb)\n\n### ActiveJob\n\n```ruby\nrequire \"telegraf/active_job\"\n\nagent = ::Telegraf::Agent.new\nActiveSupport::Notifications.subscribe(\n  'perform.active_job',\n  Telegraf::ActiveJob.new(agent: agent, series: 'active_job', tags: {global: 'tag'})\n)\n```\n\nSee plugin [class documentation](lib/telegraf/active_job.rb) for more details.\n\n### Sidekiq\n\n```ruby\nrequire \"telegraf/sidekiq\"\n\nagent = ::Telegraf::Agent.new\nSidekiq.configure_server do |config|\n  config.server_middleware do |chain|\n    chain.add ::Telegraf::Sidekiq::Middleware, agent, series: 'sidekiq', tags: {global: 'tag'}\n  end\nend\n```\n\nSee middleware [class documentation](lib/telegraf/sidekiq.rb) for more details.\n\n## License\n\nCopyright (C) 2017-2024 Jan Graichen\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License along with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgraichen%2Ftelegraf-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgraichen%2Ftelegraf-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgraichen%2Ftelegraf-ruby/lists"}