{"id":13530863,"url":"https://github.com/palkan/influxer","last_synced_at":"2025-05-15T23:04:03.942Z","repository":{"id":19197674,"uuid":"22431046","full_name":"palkan/influxer","owner":"palkan","description":"InfluxDB ActiveRecord-style","archived":false,"fork":false,"pushed_at":"2024-10-12T12:50:08.000Z","size":259,"stargazers_count":117,"open_issues_count":2,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T10:18:13.274Z","etag":null,"topics":["hacktoberfest","influxdb","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/palkan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2014-07-30T14:25:39.000Z","updated_at":"2025-01-01T17:10:31.000Z","dependencies_parsed_at":"2024-05-21T23:37:55.705Z","dependency_job_id":"a2240b9b-bb6a-411f-aafa-c5bd13b5f502","html_url":"https://github.com/palkan/influxer","commit_stats":{"total_commits":156,"total_committers":13,"mean_commits":12.0,"dds":0.4358974358974359,"last_synced_commit":"e01d37e86c51b06445c8dbf0c7cb3fe15b13ed20"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palkan%2Finfluxer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palkan%2Finfluxer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palkan%2Finfluxer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palkan%2Finfluxer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palkan","download_url":"https://codeload.github.com/palkan/influxer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765242,"owners_count":21960695,"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":["hacktoberfest","influxdb","rails","ruby"],"created_at":"2024-08-01T07:00:56.728Z","updated_at":"2025-05-15T23:04:03.904Z","avatar_url":"https://github.com/palkan.png","language":"Ruby","funding_links":[],"categories":["Queries"],"sub_categories":["Other tools"],"readme":"![Build](https://github.com/palkan/influxer/workflows/Rspec/badge.svg)\n\n# Influxer\n\nInfluxer provides an ActiveRecord-style way to work with [InfluxDB](https://influxdb.com/) with many useful features, such as:\n\n## Installation\n\nAdding to a gem:\n\n```ruby\n# my-cool-gem.gemspec\nGem::Specification.new do |spec|\n  # ...\n  spec.add_dependency \"influxer\", \"\u003e= 1.2.0\"\n  # ...\nend\n```\n\nOr adding to your project:\n\n```ruby\n# Gemfile\ngem \"influxer\", \"~\u003e 1.2\"\n```\n\n## Usage\n\n### Metrics classes\n\nTo query InfluxDB or write to it, you should define a metrics class first. Each metrics class represents a measurement/series (or multiple related measurements):\n\n```ruby\nclass VisitsMetrics \u003c Influxer::Metrics\n  # Define tags...\n  tags :account_id, :page_id\n  # ...and attributes\n  attributes :user_id, :browser\nend\n```\n\n### Querying\n\nNow you can use your metrics classes in a similar way to Active Record models to build queries. For example:\n\n```ruby\nVisitsMetrics.select(:account_id, :user_id).where(page_id: /^home\\/.*/)\n```\n\nInfluxer provides special query methods for dealing with time series:\n\n- Group by time: `Metrics.time(:hour) =\u003e # select * ... group by time(1h)`.\n- Select only points for the last hour/minute/whatever: `Metrics.past(:day) =\u003e # select * ... where time \u003e now() - 1d`.\n- Select only points since the specified time: `Metrics.since(Time.utc(2014,12,31)) =\u003e # select * ... where time \u003e 1419984000s`.\n- and more.\n\nSee [our Wiki](https://github.com/palkan/influxer/wiki/Query-methods) for more.\n\n### Scopes support\n\nYou can define scopes to re-use query conditions:\n\n```ruby\nclass Metrics \u003c Influxer::Metrics\n  tags :account_id\n  attributes :value\n\n  default_scope -\u003e { time(:hour).limit(1000) }\n\n  scope :unlimited, -\u003e { limit(nil) }\n  scope :by_account, -\u003e(id) { where(account_id: id) if id.present? }\nend\n\nMetrics.by_account(1)\n# =\u003e select * from \"metrics\" group by time(1h) where account_id=1 limit 1000\n\nMetrics.unlimited.by_account(1).time(:week)\n# =\u003e select * from \"metrics\" group by time(1w) where account_id=1\n```\n\n### Active Record integration\n\nYou can association metrics with Active Record models:\n\n```ruby\nclass UserVisits \u003c Influxer::Metrics\nend\n\nclass User \u003c ActiveRecord::Base\n  has_metrics :visits\nend\n\nuser = User.find(1)\nuser.visits.write(page_id: \"home\")\n#=\u003e \u003c creates point {user_id: 1, page_id: 'home'} in 'user_visits' series \u003e\n\nuser.visits.where(page_id: \"home\")\n#=\u003e select * from user_visits where page_id='home'\n```\n\nFind more on [Wiki](https://github.com/palkan/influxer/wiki/ActiveRecord-integration).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [https://github.com/palkan/influxer](https://github.com/palkan/influxer).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalkan%2Finfluxer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalkan%2Finfluxer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalkan%2Finfluxer/lists"}