@@ -148,6 +148,25 @@ def hw_predict(name, args)
148
148
149
149
alias :forecast :hw_predict
150
150
151
+ # takes a series of metrics in a wildcard query and aggregates the values by a subgroup
152
+ #
153
+ # data must contain a wildcard query, a subgroup position, and an optional aggregate function.
154
+ # if the aggregate function is omitted, sumSeries will be used.
155
+ #
156
+ # group :data => "metric.*.value", :subgroup => "2", :aggregator => "sumSeries"
157
+ #
158
+ def group ( name , args )
159
+ raise ":data is needed as an argument to group metrics" unless args [ :data ]
160
+ raise ":subgroup is needed as an argument to group metrics" unless args . include? ( :subgroup )
161
+
162
+ args [ :aggregator ] = "sumSeries" unless args [ :aggregator ]
163
+
164
+ group_args = args . clone
165
+ group_args [ :data ] = "groupByNode(#{ group_args [ :data ] } ,#{ group_args [ :subgroup ] } ,\" #{ group_args [ :aggregator ] } \" )"
166
+ field "#{ name } _group" , group_args
167
+
168
+ end
169
+
151
170
# draws a single dashed line with predictable names, defaults to red line
152
171
#
153
172
# data can be a single item or a 2 item array, it doesn't break if you supply
@@ -270,10 +289,12 @@ def url(format = nil, url=true)
270
289
graphite_target = "dashed(#{ graphite_target } )" if target [ :dashed ]
271
290
graphite_target = "secondYAxis(#{ graphite_target } )" if target [ :second_y_axis ]
272
291
273
- if target [ :alias ]
274
- graphite_target = "alias(#{ graphite_target } ,\" #{ target [ :alias ] } \" )"
275
- else
276
- graphite_target = "alias(#{ graphite_target } ,\" #{ name . to_s . capitalize } \" )"
292
+ unless target . include? ( :subgroup )
293
+ if target [ :alias ]
294
+ graphite_target = "alias(#{ graphite_target } ,\" #{ target [ :alias ] } \" )"
295
+ else
296
+ graphite_target = "alias(#{ graphite_target } ,\" #{ name . to_s . capitalize } \" )"
297
+ end
277
298
end
278
299
279
300
url_parts << "target=#{ graphite_target } "
0 commit comments