circonus 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/composite_builder.rb +107 -0
- metadata +3 -2
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Create composites for all unique metric names on a set of check bundles
|
4
|
+
# matching an intersection of a set of tags and a check bundle type
|
5
|
+
|
6
|
+
# This creates a total (named the same as: metricname)
|
7
|
+
# and an average (which is named as: metricname_avg)
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'circonus'
|
11
|
+
require 'optparse'
|
12
|
+
require "#{ENV['HOME']}/.circonus.rb"
|
13
|
+
|
14
|
+
|
15
|
+
def do_update_check_bundle(data)
|
16
|
+
search_check_bundle = @cached_list_check_bundle.select { |s| s['display_name'] == data['display_name'] }
|
17
|
+
existing = false
|
18
|
+
if search_check_bundle.any? # already exists...
|
19
|
+
existing = true
|
20
|
+
r = @c.update_check_bundle(search_check_bundle.first['_cid'],data)
|
21
|
+
else
|
22
|
+
r = @c.add_check_bundle(data)
|
23
|
+
end
|
24
|
+
if not r.nil? then
|
25
|
+
pp r
|
26
|
+
print "Success (#{existing ? 'updating' : 'adding'} #{data['display_name']})\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
options = {}
|
32
|
+
options[:tags] = []
|
33
|
+
OptionParser.new { |opts|
|
34
|
+
opts.banner = "Usage: #{File.basename($0)} [-h] [-t tag1,tag2,...]\n"
|
35
|
+
opts.on( '-h', '--help', "This usage menu") do
|
36
|
+
puts opts
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
opts.on( '--type TYPE',"Check bundle type" ) do |t|
|
40
|
+
options[:type] = t
|
41
|
+
end
|
42
|
+
opts.on( '-t','--tags TAGLIST',"Use comma separated list of tags for searching (takes the union)" ) do |t|
|
43
|
+
options[:tags] += t.split(/,/).sort.uniq
|
44
|
+
end
|
45
|
+
}.parse!
|
46
|
+
|
47
|
+
def usage()
|
48
|
+
print <<EOF
|
49
|
+
Usage: #{File.basename($0)} -t tag1,tag2,... --type CHECKBUNDLETYPE
|
50
|
+
-h,--help This usage menu
|
51
|
+
-t,--tags Comma separated list of tag names to use
|
52
|
+
--type check bundle type (snmp, nginx, etc.)
|
53
|
+
EOF
|
54
|
+
end
|
55
|
+
|
56
|
+
raise "No tags given" unless options[:tags].any?
|
57
|
+
raise "No type given" unless options[:type]
|
58
|
+
@c = Circonus.new(@apitoken,@appname,@agent)
|
59
|
+
|
60
|
+
# the agent that will do composites for us:
|
61
|
+
agentid = @c.list_broker({'_name'=>'composite'}).first['_cid']
|
62
|
+
|
63
|
+
# Get a cached copy for later use (this part is slow)
|
64
|
+
@cached_list_check_bundle = @c.list_check_bundle
|
65
|
+
|
66
|
+
# checkbundles matching what we want:
|
67
|
+
checkbundles = @cached_list_check_bundle.select { |s| ((s['tags'].sort.uniq & options[:tags]) == options[:tags]) and (s['type'] == options[:type]) }
|
68
|
+
|
69
|
+
# unique metric names:
|
70
|
+
metrics = checkbundles.map { |m| m['metrics'].map { |mn| mn['name'] } }.flatten.sort.uniq
|
71
|
+
|
72
|
+
# checkids in the group:
|
73
|
+
checkids = checkbundles.map { |m| m['_checks'] }.flatten
|
74
|
+
|
75
|
+
puts metrics.inspect
|
76
|
+
metrics.each do |metric|
|
77
|
+
formula = '(' + checkids.map { |cid| "metric:counter(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
|
78
|
+
bundle = {
|
79
|
+
"brokers"=>[agentid],
|
80
|
+
"config"=>{
|
81
|
+
"formula"=>formula,
|
82
|
+
"composite_metric_name"=>metric
|
83
|
+
},
|
84
|
+
"display_name"=>"Composite Sum: #{options[:tags].join(',')} - #{metric}",
|
85
|
+
"metrics"=>[
|
86
|
+
{"name"=>metric, "status"=>"active", "type"=>"numeric"}
|
87
|
+
],
|
88
|
+
"notes"=>nil,
|
89
|
+
"period"=>60,
|
90
|
+
"status"=>"active",
|
91
|
+
"tags"=>options[:tags],
|
92
|
+
"target"=>"ouzo.edge",
|
93
|
+
"timeout"=>10,
|
94
|
+
"type"=>"composite"
|
95
|
+
}
|
96
|
+
|
97
|
+
# Create total of metrics
|
98
|
+
do_update_check_bundle(bundle)
|
99
|
+
|
100
|
+
# Get average of metrics
|
101
|
+
bundle['config']['formula'] = "#{formula} / #{checkids.length}"
|
102
|
+
bundle['config']['composite_metric_name'] = "#{metric}_avg"
|
103
|
+
bundle['display_name']="Composite Avg: #{options[:tags].join(',')} - #{metric}"
|
104
|
+
bundle['metrics'].first['name'] = "#{metric}_avg"
|
105
|
+
do_update_check_bundle(bundle)
|
106
|
+
end
|
107
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circonus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- examples/cache_copy.rb
|
82
82
|
- examples/add_http_check.rb
|
83
83
|
- examples/add_apache_node.rb
|
84
|
+
- examples/composite_builder.rb
|
84
85
|
homepage: https://github.com/venturaville/circonus-api
|
85
86
|
licenses: []
|
86
87
|
post_install_message:
|