Skip to content

Commit c5572bf

Browse files
committed
Merge pull request ripienaar#8 from phobos182/master
groupByNode added to the DSL
2 parents e63470d + cba741f commit c5572bf

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

graphite_graph.rb

+25-4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ def hw_predict(name, args)
148148

149149
alias :forecast :hw_predict
150150

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+
151170
# draws a single dashed line with predictable names, defaults to red line
152171
#
153172
# 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)
270289
graphite_target = "dashed(#{graphite_target})" if target[:dashed]
271290
graphite_target = "secondYAxis(#{graphite_target})" if target[:second_y_axis]
272291

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
277298
end
278299

279300
url_parts << "target=#{graphite_target}"

samples/group/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This functionality requires Graphite 1.0 to be
2+
compiled. The current stable release does not have the
3+
function groupByNode. This feature will be available
4+
when Graphite 1.0 is released.
5+
6+
Graphite 1.0 Functions
7+
[http://graphite.readthedocs.org/en/1.0/functions.html]
8+
9+
The callback aggregator is a function will be applied
10+
to the result of groups returned. In this example the
11+
group will be the hard disk name (Ex: sda1). The
12+
function "sumSeries" will be applied to each result
13+
adding the total read iops of all like named disks
14+
and graphing the result.
15+

samples/group/group.graph

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title "CollectD - Read IOPS"
2+
vtitle "iops"
3+
description "CollectD Total IOPS by Disk"
4+
from "-4hour"
5+
linemode "staircase"
6+
7+
group :iops, :data => 'collectd.*.disk.sd*1.disk_ops.read',
8+
:subgroup => 3,
9+
:aggregator => "sumSeries"

samples/group/group.png

60.9 KB
Loading

0 commit comments

Comments
 (0)