graphite_graph 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +1 -0
  2. data/COPYING +202 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +14 -0
  5. data/README.md +12 -0
  6. data/Rakefile +2 -0
  7. data/bin/check_graph.rb +123 -0
  8. data/graphite_graph.gemspec +19 -0
  9. data/lib/graphite_graph/version.rb +3 -0
  10. data/lib/graphite_graph.rb +313 -0
  11. data/samples/basic/basic-field.graph +6 -0
  12. data/samples/basic/basic-field.png +0 -0
  13. data/samples/basic/basic.graph +10 -0
  14. data/samples/basic/basic.png +0 -0
  15. data/samples/basic/example.png +0 -0
  16. data/samples/group/README.md +15 -0
  17. data/samples/group/group.graph +9 -0
  18. data/samples/group/group.png +0 -0
  19. data/samples/holt-winters/aberration-with-thresholds.graph +18 -0
  20. data/samples/holt-winters/aberration-with-thresholds.png +0 -0
  21. data/samples/holt-winters/basic-with-aberration-on-y.graph +13 -0
  22. data/samples/holt-winters/basic-with-aberration-on-y.png +0 -0
  23. data/samples/holt-winters/basic-with-aberration.graph +12 -0
  24. data/samples/holt-winters/basic-with-aberration.png +0 -0
  25. data/samples/holt-winters/basic.graph +11 -0
  26. data/samples/holt-winters/basic.png +0 -0
  27. data/samples/holt-winters/custom-colors.graph +14 -0
  28. data/samples/holt-winters/custom-colors.png +0 -0
  29. data/samples/holt-winters/just-aberration.graph +15 -0
  30. data/samples/holt-winters/just-aberration.png +0 -0
  31. data/samples/lines/lines.graph +8 -0
  32. data/samples/lines/lines.png +0 -0
  33. data/samples/monitoring/README.md +27 -0
  34. data/samples/monitoring/monitor.graph +9 -0
  35. data/samples/monitoring/monitor.png +0 -0
  36. data/samples/thresholds/thresholds.graph +10 -0
  37. data/samples/thresholds/thresholds.png +0 -0
  38. metadata +91 -0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/COPYING ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2010, 2011 R.I.Pienaar
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ graphite_graph (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ graphite_graph!
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ What?
2
+ =====
3
+
4
+ Small DSL in progress to describe a graphite graph.
5
+
6
+ For full information please see the wiki pages on the
7
+ project home at GitHub
8
+
9
+ Who?
10
+ ====
11
+
12
+ R.I.Pienaar / http://devco.net/ / @ripienaar / rip@devco.net
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'graphite_graph'
6
+ require 'net/http'
7
+ require 'uri'
8
+ require 'optparse'
9
+ require 'pp'
10
+
11
+ crits = []
12
+ warns = []
13
+ check_data = {}
14
+ url = "http://localhost/render/?"
15
+ graph = nil
16
+ check_number = 3
17
+
18
+ opt = OptionParser.new
19
+
20
+ opt.on("--graphite [URL]", "Base URL for the Graphite installation") do |v|
21
+ url = v
22
+ end
23
+
24
+ opt.on("--graph [GRAPH]", "Graph defintition") do |v|
25
+ graph = v
26
+ end
27
+
28
+ opt.on("--warning [WARN]", "Warning threshold, can be specified multiple times") do |v|
29
+ warns << Float(v)
30
+ end
31
+
32
+ opt.on("--critical [CRITICAL]", "Critical threshold, can be specified multiple times") do |v|
33
+ crits << Float(v)
34
+ end
35
+
36
+ opt.on("--check [NUM]", Integer, "Number of past data items to check") do |v|
37
+ check_number = v
38
+ end
39
+
40
+ opt.parse!
41
+
42
+ def status_exit(msg, code)
43
+ puts msg
44
+ exit code
45
+ end
46
+
47
+ unless (graph && File.exist?(graph))
48
+ status_exit "UNKNOWN - Can't find graph defintion #{graph}", 3
49
+ end
50
+
51
+ def check_data(data, min, max)
52
+ fails = []
53
+
54
+ data.keys.each do |target|
55
+ if min == max # we got just one value to compare against
56
+ if min < 0
57
+ # if the threshold is < 0 we check for values below the threshold but have no way to say that
58
+ # critical / warning is above -0.5 for example unless you specify a 2 value band
59
+ if (data[target].min <= min)
60
+ fails << {:target => target, :item => data[target].min, :operator => "<=", :expected => min}
61
+ end
62
+ else
63
+ if (data[target].max >= max)
64
+ fails << {:target => target, :item => data[target].max, :operator => ">=", :expected => max}
65
+ end
66
+ end
67
+ else # we have a range of values to compare against and the values must be between
68
+ if (data[target].min <= min)
69
+ fails << {:target => target, :item => data[target].min, :operator => "<=", :expected => min}
70
+ end
71
+
72
+ if (data[target].max >= max)
73
+ fails << {:target => target, :item => data[target].max, :operator => ">=", :expected => max}
74
+ end
75
+ end
76
+ end
77
+
78
+ fails.empty? ? false : fails
79
+ end
80
+
81
+ def print_and_exit(results, code)
82
+ exitcodes = ["OK", "WARNING", "CRITICAL", "UNKNOWN"]
83
+
84
+ msg = results.map do |r|
85
+ "%s %s %s %s" % [r[:target], r[:item], r[:operator], r[:expected]]
86
+ end.join(", ")
87
+
88
+ status_exit "%s - %s" % [exitcodes[code], msg], code
89
+ end
90
+
91
+
92
+ graphite = GraphiteGraph.new(graph)
93
+
94
+ uri = URI.parse("%s?%s" % [ url, graphite.url(:json) ])
95
+
96
+ json = Net::HTTP.get_response(uri)
97
+
98
+ status_exit("UNKNOWN - Could not request graph data for HTTP code #{json.code}", 3) unless json.code == "200"
99
+
100
+ data = JSON.load(json.body)
101
+
102
+ data.each do |d|
103
+ unless d["target"] =~ /(warn|crit)_[01]$/
104
+ check_data[ d["target"] ] = d["datapoints"].last(check_number).map{|i| i.first}
105
+ end
106
+ end
107
+
108
+ crits = graphite.critical_threshold if crits.empty? and graphite.critical_threshold
109
+ warns = graphite.warning_threshold if warns.empty? and graphite.warning_threshold
110
+
111
+ if crits.empty? || warns.empty? || check_data.empty?
112
+ status_exit "UNKNOWN: Graph does not have Data, Warning and Critical information", 3
113
+ end
114
+
115
+ if results = check_data(check_data, crits.min, crits.max)
116
+ print_and_exit results, 2
117
+
118
+ elsif results = check_data(check_data, warns.min, warns.max)
119
+ print_and_exit results, 1
120
+
121
+ else
122
+ status_exit "OK - All data within expected ranges", 0
123
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "graphite_graph/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "graphite_graph"
7
+ s.version = GraphiteGraph::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["R.I.Pienaar", "Tom Taylor"]
10
+ s.email = ["rip@devco.net", "tom@tomtaylor.co.uk"]
11
+ s.homepage = "https://github.com/ripienaar/graphite-graph-dsl"
12
+ s.summary = %q{DSL for generating Graphite graphs}
13
+
14
+ s.rubyforge_project = "graphite_graph"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,3 @@
1
+ class GraphiteGraph
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,313 @@
1
+ require 'uri'
2
+ require "graphite_graph/version"
3
+ # A small DSL to assist in the creation of Graphite graphs
4
+ # see https://github.com/ripienaar/graphite-graph-dsl/wiki
5
+ # for full details
6
+ class GraphiteGraph
7
+ attr_reader :info, :properties, :targets, :target_order, :critical_threshold, :warning_threshold
8
+
9
+ def initialize(file, overrides={}, info={})
10
+ @info = info
11
+ @file = file
12
+ @munin_mode = false
13
+ @overrides = overrides
14
+ @linecount = 0
15
+
16
+ @critical_threshold = []
17
+ @warning_threshold = []
18
+
19
+ load_graph
20
+ end
21
+
22
+ def defaults
23
+ @properties = {:title => nil,
24
+ :vtitle => nil,
25
+ :width => 500,
26
+ :height => 250,
27
+ :from => "-1hour",
28
+ :until => "now",
29
+ :surpress => false,
30
+ :description => nil,
31
+ :hide_legend => nil,
32
+ :hide_grid => nil,
33
+ :ymin => nil,
34
+ :ymax => nil,
35
+ :linewidth => nil,
36
+ :linemode => nil,
37
+ :fontsize => nil,
38
+ :fontbold => false,
39
+ :timezone => nil,
40
+ :draw_null_as_zero => false,
41
+ :major_grid_line_color => nil,
42
+ :minor_grid_line_color => nil,
43
+ :area => :none}.merge(@overrides)
44
+ end
45
+
46
+ def [](key)
47
+ if key == :url
48
+ url
49
+ else
50
+ @properties[key]
51
+ end
52
+ end
53
+
54
+ def method_missing(meth, *args)
55
+ if properties.include?(meth)
56
+ properties[meth] = args.first unless @overrides.include?(meth)
57
+ else
58
+ super
59
+ end
60
+ end
61
+
62
+ def load_graph
63
+ @properties = defaults
64
+ @targets = {}
65
+ @target_order = []
66
+
67
+ self.instance_eval(File.read(@file)) unless @file == :none
68
+ end
69
+
70
+ def service(service, data, &blk)
71
+ raise "No hostname given for this instance" unless info[:hostname]
72
+
73
+ @service_mode = {:service => service, :data => data}
74
+
75
+ blk.call
76
+
77
+ @service_mode = false
78
+ end
79
+
80
+ # add forecast, bands, aberrations and actual fields using the
81
+ # Holt-Winters Confidence Band prediction model
82
+ #
83
+ # hw_predict :foo, :data => "some.data.item", :alias => "Some Item"
84
+ #
85
+ # You can tweak the colors by setting:
86
+ # :forecast_color => "blue"
87
+ # :bands_color => "grey"
88
+ # :aberration_color => "red"
89
+ #
90
+ # You can add an aberration line:
91
+ #
92
+ # :aberration_line => true,
93
+ # :aberration_second_y => true
94
+ #
95
+ # You can disable the forecast line by setting:
96
+ #
97
+ # :forecast_line => false
98
+ #
99
+ # You can disable the confidence lines by settings:
100
+ #
101
+ # :bands_lines => false
102
+ #
103
+ # You can disable the display of the actual data:
104
+ #
105
+ # :actual_line => false
106
+ def hw_predict(name, args)
107
+ raise ":data is needed as an argument to a Holt-Winters Confidence forecast" unless args[:data]
108
+
109
+ unless args[:forecast_line] == false
110
+ forecast_args = args.clone
111
+ forecast_args[:data] = "holtWintersForecast(#{forecast_args[:data]})"
112
+ forecast_args[:alias] = "#{args[:alias]} Forecast"
113
+ forecast_args[:color] = args[:forecast_color] || "blue"
114
+ field "#{name}_forecast", forecast_args
115
+ end
116
+
117
+ unless args[:bands_lines] == false
118
+ bands_args = args.clone
119
+ bands_args[:data] = "holtWintersConfidenceBands(#{bands_args[:data]})"
120
+ bands_args[:color] = args[:bands_color] || "grey"
121
+ bands_args[:dashed] = true
122
+ bands_args[:alias] = "#{args[:alias]} Confidence"
123
+ field "#{name}_bands", bands_args
124
+ end
125
+
126
+ if args[:aberration_line]
127
+ aberration_args = args.clone
128
+ aberration_args[:data] = "holtWintersAberration(keepLastValue(#{aberration_args[:data]}))"
129
+ aberration_args[:color] = args[:aberration_color] || "orange"
130
+ aberration_args[:alias] = "#{args[:alias]} Aberration"
131
+ aberration_args[:second_y_axis] = true if aberration_args[:aberration_second_y]
132
+ field "#{name}_aberration", aberration_args
133
+ end
134
+
135
+ if args[:critical]
136
+ color = args[:critical_color] || "red"
137
+ critical :value => args[:critical], :color => color, :name => name
138
+ end
139
+
140
+ if args[:warning]
141
+ color = args[:warning_color] || "orange"
142
+ warning :value => args[:warning], :color => color, :name => name
143
+ end
144
+
145
+ args[:color] ||= "yellow"
146
+
147
+ field name, args unless args[:actual_line] == false
148
+ end
149
+
150
+ alias :forecast :hw_predict
151
+
152
+ # takes a series of metrics in a wildcard query and aggregates the values by a subgroup
153
+ #
154
+ # data must contain a wildcard query, a subgroup position, and an optional aggregate function.
155
+ # if the aggregate function is omitted, sumSeries will be used.
156
+ #
157
+ # group :data => "metric.*.value", :subgroup => "2", :aggregator => "sumSeries"
158
+ #
159
+ def group(name, args)
160
+ raise ":data is needed as an argument to group metrics" unless args[:data]
161
+ raise ":subgroup is needed as an argument to group metrics" unless args.include?(:subgroup)
162
+
163
+ args[:aggregator] = "sumSeries" unless args[:aggregator]
164
+
165
+ group_args = args.clone
166
+ group_args[:data] = "groupByNode(#{group_args[:data]},#{group_args[:subgroup]},\"#{group_args[:aggregator]}\")"
167
+ field "#{name}_group", group_args
168
+
169
+ end
170
+
171
+ # draws a single dashed line with predictable names, defaults to red line
172
+ #
173
+ # data can be a single item or a 2 item array, it doesn't break if you supply
174
+ # more but # more than 2 items just doesn't make sense generally
175
+ #
176
+ # critical :value => [700, -700], :color => "red"
177
+ #
178
+ # You can prevent the line from being drawn but just store the ranges for monitoring
179
+ # purposes by adding :hide => true to the arguments
180
+ def critical(options)
181
+ raise "critical lines need a value" unless options[:value]
182
+
183
+ @critical_threshold = [options[:value]].flatten
184
+
185
+ options[:color] ||= "red"
186
+
187
+ unless options[:hide]
188
+ @critical_threshold.each_with_index do |crit, index|
189
+ line :caption => "crit_#{index}", :value => crit, :color => options[:color], :dashed => true
190
+ end
191
+ end
192
+ end
193
+
194
+ # draws a single dashed line with predictable names, defaults to orange line
195
+ #
196
+ # data can be a single item or a 2 item array, it doesn't break if you supply
197
+ # more but # more than 2 items just doesn't make sense generally
198
+ #
199
+ # warning :value => [700, -700], :color => "orange"
200
+ #
201
+ # You can prevent the line from being drawn but just store the ranges for monitoring
202
+ # purposes by adding :hide => true to the arguments
203
+ def warning(options)
204
+ raise "warning lines need a value" unless options[:value]
205
+
206
+ @warning_threshold = [options[:value]].flatten
207
+
208
+ options[:color] ||= "orange"
209
+
210
+ unless options[:hide]
211
+ @warning_threshold.flatten.each_with_index do |warn, index|
212
+ line :caption => "warn_#{index}", :value => warn, :color => options[:color], :dashed => true
213
+ end
214
+ end
215
+ end
216
+
217
+ # draws a simple line on the graph with a caption, value and color.
218
+ #
219
+ # line :caption => "warning", :value => 50, :color => "orange"
220
+ def line(options)
221
+ raise "lines need a caption" unless options.include?(:caption)
222
+ raise "lines need a value" unless options.include?(:value)
223
+ raise "lines need a color" unless options.include?(:color)
224
+
225
+ options[:alias] = options[:caption] unless options[:alias]
226
+
227
+ args = {:data => "threshold(#{options[:value]})", :color => options[:color], :alias => options[:alias]}
228
+
229
+ args[:dashed] = true if options[:dashed]
230
+
231
+ field "line_#{@linecount}", args
232
+
233
+ @linecount += 1
234
+ end
235
+
236
+ # adds a field to the graph, each field needs a unique name
237
+ def field(name, args)
238
+ raise "A field called #{name} already exist for this graph" if targets.include?(name)
239
+
240
+ default = {}
241
+
242
+ if @service_mode
243
+ default[:data] = [info[:hostname], @service_mode[:service], @service_mode[:data], name].join(".")
244
+ end
245
+
246
+ targets[name] = default.merge(args)
247
+ target_order << name
248
+ end
249
+
250
+ def url(format = nil, url=true)
251
+ return nil if properties[:surpress]
252
+
253
+ url_parts = []
254
+ colors = []
255
+
256
+ [:title, :vtitle, :from, :width, :height, :until].each do |item|
257
+ url_parts << "#{item}=#{properties[item]}" if properties[item]
258
+ end
259
+
260
+ url_parts << "areaMode=#{properties[:area]}" if properties[:area]
261
+ url_parts << "hideLegend=#{properties[:hide_legend]}" if properties.include?(:hide_legend)
262
+ url_parts << "hideGrid=#{properties[:hide_grid]}" if properties[:hide_grid]
263
+ url_parts << "yMin=#{properties[:ymin]}" if properties[:ymin]
264
+ url_parts << "yMax=#{properties[:ymax]}" if properties[:ymax]
265
+ url_parts << "lineWidth=#{properties[:linewidth]}" if properties[:linewidth]
266
+ url_parts << "lineMode=#{properties[:linemode]}" if properties[:linemode]
267
+ url_parts << "fontSize=#{properties[:fontsize]}" if properties[:fontsize]
268
+ url_parts << "fontBold=#{properties[:fontbold]}" if properties[:fontbold]
269
+ url_parts << "drawNullAsZero=#{properties[:draw_null_as_zero]}" if properties[:draw_null_as_zero]
270
+ url_parts << "tz=#{properties[:timezone]}" if properties[:timezone]
271
+ url_parts << "majorGridLineColor=#{properties[:major_grid_line_color]}" if properties[:major_grid_line_color]
272
+ url_parts << "minorGridLineColor=#{properties[:minor_grid_line_color]}" if properties[:minor_grid_line_color]
273
+
274
+ target_order.each do |name|
275
+ target = targets[name]
276
+
277
+ if target[:target]
278
+ url_parts << "target=#{target[:target]}"
279
+ else
280
+ raise "field #{name} does not have any data associated with it" unless target[:data]
281
+
282
+ graphite_target = target[:data]
283
+
284
+ graphite_target = "derivative(#{graphite_target})" if target[:derivative]
285
+ graphite_target = "scale(#{graphite_target},#{target[:scale]})" if target[:scale]
286
+ graphite_target = "drawAsInfinite(#{graphite_target})" if target[:line]
287
+ graphite_target = "movingAverage(#{graphite_target},#{target[:smoothing]})" if target[:smoothing]
288
+
289
+ graphite_target = "color(#{graphite_target},\"#{target[:color]}\")" if target[:color]
290
+ graphite_target = "dashed(#{graphite_target})" if target[:dashed]
291
+ graphite_target = "secondYAxis(#{graphite_target})" if target[:second_y_axis]
292
+
293
+ unless target.include?(:subgroup)
294
+ if target[:alias]
295
+ graphite_target = "alias(#{graphite_target},\"#{target[:alias]}\")"
296
+ else
297
+ graphite_target = "alias(#{graphite_target},\"#{name.to_s.capitalize}\")"
298
+ end
299
+ end
300
+
301
+ url_parts << "target=#{graphite_target}"
302
+ end
303
+ end
304
+
305
+ url_parts << "format=#{format}" if format
306
+
307
+ if url
308
+ URI.encode(url_parts.join("&"))
309
+ else
310
+ url_parts
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,6 @@
1
+ title "Test Graph"
2
+
3
+ field :iowait, :data => "sumSeries(example.munin.load.load)",
4
+ :color => "red",
5
+ :alias => "Load Average",
6
+ :derivative => true
Binary file
@@ -0,0 +1,10 @@
1
+ # graph settings
2
+ title "Basic Graph"
3
+ vtitle "percent"
4
+ area :stacked
5
+
6
+ # individual fields
7
+ field :iowait, :scale => 0.001,
8
+ :color => "red",
9
+ :alias => "IO Wait",
10
+ :data => "sumSeries(derivative(mw*.munin.cpu.iowait))"
Binary file
Binary file
@@ -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
+
@@ -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"
Binary file
@@ -0,0 +1,18 @@
1
+ title "Male Site Users - Abereation"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male",
12
+ :aberration_line => true,
13
+ :forecast_line => false,
14
+ :bands_lines => false,
15
+ :actual_line => false,
16
+ :critical => [700, -700],
17
+ :warning => [300, -300],
18
+ :aberration_color => "blue"
@@ -0,0 +1,13 @@
1
+ title "Male Site Users - Aberration"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male",
12
+ :aberration_line => true,
13
+ :aberration_second_y => true
@@ -0,0 +1,12 @@
1
+ title "Male Site Users - Aberration"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male",
12
+ :aberration_line => true
@@ -0,0 +1,11 @@
1
+ title "Male Site Users"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male"
Binary file
@@ -0,0 +1,14 @@
1
+ title "Male Site Users"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male",
12
+ :forecast_color => "yellow",
13
+ :bands_color => "white",
14
+ :color => "green"
@@ -0,0 +1,15 @@
1
+ title "Male Site Users - Aberration"
2
+ vtitle "users"
3
+ width 800
4
+ height 500
5
+ from "-12hours"
6
+ area :none
7
+ description "Male users on the site"
8
+ hide_legend true
9
+
10
+ forecast :male, :data => "sumSeries(*.site.users.male)",
11
+ :alias => "Male",
12
+ :aberration_line => true,
13
+ :forecast_line => false,
14
+ :bands_lines => false,
15
+ :actual_line => false
@@ -0,0 +1,8 @@
1
+ title "Horizontal Lines"
2
+ width 400
3
+ height 250
4
+ ymin 0
5
+ ymax 125
6
+
7
+ line :caption => "Critical", :value => 100, :color => "red"
8
+ line :caption => "Warning", :value => 50, :color => "orange", :dashed => true
Binary file
@@ -0,0 +1,27 @@
1
+ Given a graph with critical and warning data on it
2
+ this Nagios compatible check will fetch the JSON data
3
+ of the graph and make sure no data is outside of the
4
+ warning and critical levels.
5
+
6
+ title "Down Network"
7
+ hide_legend true
8
+
9
+ forecast :down, :data => "keepLastValue(my_net.munin.if_eth0.down)",
10
+ :alias => "Down",
11
+ :aberration_line => true,
12
+ :forecast_line => false,
13
+ :bands_lines => false,
14
+ :actual_line => false,
15
+ :aberration_color => "blue"
16
+
17
+ # record the thresholds but do not draw them
18
+ critical :value => [700, -700], :hide => true
19
+ warning :value => [300, -300], :hide => true
20
+
21
+ This is a Holt Winters prediction graph of network data received
22
+ by a host, it has acceptable threshold for how aberrant the data
23
+ may be - if the prediction says the data is too far out of range
24
+ an alert will be raised.
25
+
26
+ % check_graph.rb --graph monitor.graph --graphite "http://graphite.your.net/render/"
27
+ CRITICAL - Down Aberration 1623 > 700
@@ -0,0 +1,9 @@
1
+ title "Load Average"
2
+ hide_legend true
3
+
4
+ field :iowait, :data => "keepLastValue(example.munin.load.load)",
5
+ :color => "red",
6
+ :alias => "Load Average"
7
+
8
+ critical :value => 0.3
9
+ warning :value => 0.1
Binary file
@@ -0,0 +1,10 @@
1
+ title "Threshold Lines"
2
+ width 400
3
+ height 250
4
+ ymin -130
5
+ ymax 130
6
+ hide_legend true
7
+
8
+ warning :value => [50, -50], :color => "orange"
9
+ critical :value => [100, -100], :color => "red"
10
+
Binary file
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphite_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - R.I.Pienaar
9
+ - Tom Taylor
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-16 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description:
16
+ email:
17
+ - rip@devco.net
18
+ - tom@tomtaylor.co.uk
19
+ executables:
20
+ - check_graph.rb
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - .gitignore
25
+ - COPYING
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - README.md
29
+ - Rakefile
30
+ - bin/check_graph.rb
31
+ - graphite_graph.gemspec
32
+ - lib/graphite_graph.rb
33
+ - lib/graphite_graph/version.rb
34
+ - samples/basic/basic-field.graph
35
+ - samples/basic/basic-field.png
36
+ - samples/basic/basic.graph
37
+ - samples/basic/basic.png
38
+ - samples/basic/example.png
39
+ - samples/group/README.md
40
+ - samples/group/group.graph
41
+ - samples/group/group.png
42
+ - samples/holt-winters/aberration-with-thresholds.graph
43
+ - samples/holt-winters/aberration-with-thresholds.png
44
+ - samples/holt-winters/basic-with-aberration-on-y.graph
45
+ - samples/holt-winters/basic-with-aberration-on-y.png
46
+ - samples/holt-winters/basic-with-aberration.graph
47
+ - samples/holt-winters/basic-with-aberration.png
48
+ - samples/holt-winters/basic.graph
49
+ - samples/holt-winters/basic.png
50
+ - samples/holt-winters/custom-colors.graph
51
+ - samples/holt-winters/custom-colors.png
52
+ - samples/holt-winters/just-aberration.graph
53
+ - samples/holt-winters/just-aberration.png
54
+ - samples/lines/lines.graph
55
+ - samples/lines/lines.png
56
+ - samples/monitoring/README.md
57
+ - samples/monitoring/monitor.graph
58
+ - samples/monitoring/monitor.png
59
+ - samples/thresholds/thresholds.graph
60
+ - samples/thresholds/thresholds.png
61
+ homepage: https://github.com/ripienaar/graphite-graph-dsl
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 69971418371862677
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: 69971418371862677
85
+ requirements: []
86
+ rubyforge_project: graphite_graph
87
+ rubygems_version: 1.8.11
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: DSL for generating Graphite graphs
91
+ test_files: []