circonus 1.0.7 → 1.0.8

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.
@@ -17,6 +17,8 @@ def do_update_check_bundle(data)
17
17
  existing = false
18
18
  if search_check_bundle.any? # already exists...
19
19
  existing = true
20
+ pp search_check_bundle.first['_cid']
21
+ pp data
20
22
  r = @c.update_check_bundle(search_check_bundle.first['_cid'],data)
21
23
  else
22
24
  r = @c.add_check_bundle(data)
@@ -30,15 +32,32 @@ end
30
32
 
31
33
  options = {}
32
34
  options[:tags] = []
35
+ options[:datatype] = 'counter'
36
+ options[:consolidation] = 'sum'
33
37
  OptionParser.new { |opts|
34
38
  opts.banner = "Usage: #{File.basename($0)} [-h] [-t tag1,tag2,...]\n"
35
39
  opts.on( '-h', '--help', "This usage menu") do
36
40
  puts opts
37
41
  exit
38
42
  end
43
+ opts.on( '--counter',"Counter" ) do
44
+ options[:datatype] = 'counter'
45
+ end
46
+ opts.on( '--gauge',"Gauge" ) do
47
+ options[:datatype] = 'gauge'
48
+ end
49
+ opts.on( '--average',"Average" ) do
50
+ options[:consolidation] = 'average'
51
+ end
52
+ opts.on( '--sum',"Sum" ) do
53
+ options[:consolidation] = 'sum'
54
+ end
39
55
  opts.on( '--type TYPE',"Check bundle type" ) do |t|
40
56
  options[:type] = t
41
57
  end
58
+ opts.on( '--metric METRICNAME',"Metric name" ) do |m|
59
+ options[:metric] = m
60
+ end
42
61
  opts.on( '-t','--tags TAGLIST',"Use comma separated list of tags for searching (takes the union)" ) do |t|
43
62
  options[:tags] += t.split(/,/).sort.uniq
44
63
  end
@@ -47,9 +66,14 @@ OptionParser.new { |opts|
47
66
  def usage()
48
67
  print <<EOF
49
68
  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.)
69
+ -h,--help This usage menu
70
+ -t,--tags Comma separated list of tag names to use
71
+ -m,--metric METRIC Metric name
72
+ --counter Set if the metric is a counter (default)
73
+ --gauge Set if the metric is a gauge
74
+ --sum Set if you want a sum (default)
75
+ --average Set if you want an average
76
+ --type check bundle type (snmp, nginx, etc.)
53
77
  EOF
54
78
  end
55
79
 
@@ -68,13 +92,20 @@ checkbundles = @cached_list_check_bundle.select { |s| ((s['tags'].sort.uniq & op
68
92
 
69
93
  # unique metric names:
70
94
  metrics = checkbundles.map { |m| m['metrics'].map { |mn| mn['name'] } }.flatten.sort.uniq
95
+ if options[:metric]
96
+ if not metrics.include? options[:metric]
97
+ raise "No matching metric name (#{options[:metric]}) found in check bundle"
98
+ else
99
+ metrics = [options[:metric]]
100
+ end
101
+ end
71
102
 
72
103
  # checkids in the group:
73
104
  checkids = checkbundles.map { |m| m['_checks'] }.flatten
74
105
 
75
106
  puts metrics.inspect
76
107
  metrics.each do |metric|
77
- formula = '(' + checkids.map { |cid| "metric:counter(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
108
+ formula = '(' + checkids.map { |cid| "metric:#{options[:datatype]}(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
78
109
  bundle = {
79
110
  "brokers"=>[agentid],
80
111
  "config"=>{
@@ -94,14 +125,18 @@ metrics.each do |metric|
94
125
  "type"=>"composite"
95
126
  }
96
127
 
97
- # Create total of metrics
98
- do_update_check_bundle(bundle)
128
+ if options[:consolidation] == 'sum'
129
+ # Create total of metrics
130
+ do_update_check_bundle(bundle)
131
+ end
99
132
 
100
133
  # Get average of metrics
101
134
  bundle['config']['formula'] = "#{formula} / #{checkids.length}"
102
135
  bundle['config']['composite_metric_name'] = "#{metric}_avg"
103
136
  bundle['display_name']="Composite Avg: #{options[:tags].join(',')} - #{metric}"
104
137
  bundle['metrics'].first['name'] = "#{metric}_avg"
105
- do_update_check_bundle(bundle)
138
+ if options[:consolidation] == 'average'
139
+ do_update_check_bundle(bundle)
140
+ end
106
141
  end
107
142
 
data/lib/circonus.rb CHANGED
@@ -19,8 +19,8 @@ class Circonus
19
19
  end
20
20
 
21
21
  DEFAULT_OPTIONS = {
22
- :timeout => 20,
23
- :open_timeout => 20
22
+ :timeout => 300,
23
+ :open_timeout => 300
24
24
  }
25
25
 
26
26
  def initialize(apitoken,appname,agent, options={})
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.7
4
+ version: 1.0.8
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-09-12 00:00:00.000000000 Z
12
+ date: 2013-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -72,6 +72,7 @@ files:
72
72
  - bin/circonus_list_checkbundle
73
73
  - bin/circonus-data-cli
74
74
  - bin/circonus_list_tags
75
+ - bin/composite_builder.rb
75
76
  - bin/circonus-cli
76
77
  - examples/add_dns_monitor.rb
77
78
  - examples/add_snmp_node.rb
@@ -83,7 +84,6 @@ files:
83
84
  - examples/cache_copy.rb
84
85
  - examples/add_http_check.rb
85
86
  - examples/add_apache_node.rb
86
- - examples/composite_builder.rb
87
87
  homepage: https://github.com/venturaville/circonus-api
88
88
  licenses:
89
89
  - MIT