circonus 1.0.13 → 1.0.14
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/bin/update_all_composites.rb +71 -0
- metadata +2 -1
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Use tags on existing composites to automate the updating of formulas on them
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'circonus'
|
8
|
+
require 'optparse'
|
9
|
+
require "#{ENV['HOME']}/.circonus.rb"
|
10
|
+
|
11
|
+
def do_update_check_bundle(data)
|
12
|
+
r = @c.update_check_bundle(data['_cid'],data)
|
13
|
+
if not r.nil? then
|
14
|
+
pp r
|
15
|
+
print "Success updating #{data['display_name']})\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@c = Circonus.new(@apitoken,@appname,@agent)
|
20
|
+
|
21
|
+
# the agent that will do composites for us:
|
22
|
+
agentid = @c.list_broker({'_name'=>'composite'}).first['_cid']
|
23
|
+
|
24
|
+
# Get a cached copy for later use (this part is slow)
|
25
|
+
@cached_list_check_bundle = @c.list_check_bundle()
|
26
|
+
|
27
|
+
def get_tag_values(tags)
|
28
|
+
Hash[tags.map { |e| e.split(':',2) }] # convert tag list to a hash (Note: this squashes duplicates)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Generate the composite formula
|
32
|
+
def generate_formula(checkids,consolidation,datatype,metric)
|
33
|
+
formula = '(' + checkids.map { |cid| "metric:#{datatype}(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
|
34
|
+
if consolidation == 'average'
|
35
|
+
formula = "#{formula} / #{checkids.length}"
|
36
|
+
end
|
37
|
+
formula
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test to see if the composite needs updating
|
41
|
+
def composite_update(composite,tags,select_tags)
|
42
|
+
puts composite['display_name']
|
43
|
+
|
44
|
+
# get list of check bundles given the set of tags and type
|
45
|
+
cbs = @cached_list_check_bundle.select { |s| s['type'] == tags['type'] }
|
46
|
+
select_tags.each do |tag|
|
47
|
+
cbs = cbs.select { |s| s['tags'].include? tag }
|
48
|
+
end
|
49
|
+
checkids = cbs.map { |m| m['_checks'].first.split('/').last }.sort
|
50
|
+
|
51
|
+
new_formula = generate_formula(checkids,tags['consolidation'],tags['datatype'],tags['metric'])
|
52
|
+
if composite['config']['formula'] != new_formula
|
53
|
+
composite['config']['formula'] = new_formula
|
54
|
+
composite['config']['composite_metric_name'] = tags['metric']
|
55
|
+
do_update_check_bundle(composite)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
automation_tags = %w{ consolidation datatype type source metric }
|
60
|
+
composites = @cached_list_check_bundle.select { |s|
|
61
|
+
s['tags'].include?('source:composite-builder') and (s['type'] == 'composite')
|
62
|
+
}
|
63
|
+
composites.each do |composite|
|
64
|
+
select_tags = composite['tags'].select { |s| not (automation_tags.include? s.split(':').first) } # strip automation tags
|
65
|
+
tags = get_tag_values(composite['tags'])
|
66
|
+
next if tags['type'].nil? or tags['datatype'].nil? or tags['consolidation'].nil? or tags['metric'].nil?
|
67
|
+
next if tags['type'].empty? or tags['datatype'].empty? or tags['consolidation'].empty? or tags['metric'].empty?
|
68
|
+
|
69
|
+
composite_update(composite,tags,select_tags)
|
70
|
+
end
|
71
|
+
|
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.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -69,6 +69,7 @@ extra_rdoc_files: []
|
|
69
69
|
files:
|
70
70
|
- lib/circonus.rb
|
71
71
|
- lib/circonus/values.rb
|
72
|
+
- bin/update_all_composites.rb
|
72
73
|
- bin/circonus_list_checkbundle
|
73
74
|
- bin/circonus-data-cli
|
74
75
|
- bin/circonus_list_tags
|