Fanout queries generated series - palkan/influxer GitHub Wiki
NOTE: Only for Influxer 0.2.x.
If you're using InfluxDB 0.8 or less then you are likely to use fanout queries which generate a lot of series.
Suppose you have series of the following kind: visits_by_<day|hour|month>_user_<user_id>
.
Influxer provide an easy way to handle such series as one.
class VisitsMetrics < Influxer::Metrics
# order should be exactly the same you're using in continuous queries
fanout :by, :user
end
VisitsMetrics.where(user: 1, by: :hour) #=> select * from visits_by_hour_user_1
# you can use regexp values too
VisitsMetrics.where(user: /(1-4|15)/, by: :hour) #=> select * from merge(/^visits_by_hour_user_(1-4|15)$/)
# in this case return points would contain fanouted values too
#
# Example: assume we have two series (each has one point): "visits_by_hour_user_1" ({"time_spent": 100}) and
# "visits_by_hour_user_2" ({"time_spent": 200})
VisitsMetrics.where(user: /(1-4|15)/, by: :hour).to_a
#=> [{ "by" => "hour", "user" => "1", "time_spent" => 100" }, { "by" => "hour", "user" => "2", "time_spent" => 200}]