circonus 3.1.5 → 3.3.0

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.
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # Add a composite metric given a set of tags to filter on
3
+
4
+ require 'circonusutil'
5
+ cu = CirconusUtil.new() { |opts,options|
6
+ options[:tags] = ['application:composite']
7
+ options[:filter] = []
8
+ options[:stats] = 'mean'
9
+ options[:metric] = 'average'
10
+ options[:name] = nil
11
+ opts.on( '--tags TAGLIST',"Apply comma separated list of tags (default: empty list)" ) { |t| options[:tags] += t.split(/,/) }
12
+ opts.on( '--filter TAGLIST',"Apply comma separated list of tags to filter on" ) { |t| options[:filter] += t.split(/,/) }
13
+ opts.on( '--stats TYPE',"Take the sum/mean/min/etc.. of the group of stats (default: mean)" ) { |t| options[:stats] = t }
14
+ opts.on( '--metric TYPE',"The type (counter/average/etc..) of the datapoint (default: average)" ) { |t| options[:metric] = t }
15
+ opts.on( '--name NAME',"The name of the metric to use." ) { |t| options[:name] = t }
16
+ }
17
+ if cu.options[:filter].empty?
18
+ puts "Missing filter"
19
+ exit -1
20
+ end
21
+ if cu.options[:metric].to_s.empty?
22
+ puts "Missing metric"
23
+ exit -1
24
+ end
25
+
26
+ brokers = cu.circonus.list_broker({'_name'=>'composite'})
27
+ bid = brokers.first['_cid']
28
+
29
+ formula = "stats:#{cu.options[:stats]}(metric:#{cu.options[:metric]}(#{cu.options[:filter].sort.map {|m|'tag:'+m}.join(' and ')}, \"#{cu.options[:name]}\", 60000))"
30
+ display_name = cu.options[:filter].sort.join(' ') + ' ' + cu.options[:name] + ' composite'
31
+ bundle = {
32
+ "target"=>"composite",
33
+ "timeout"=>10,
34
+ "metrics"=> [ {"status"=>"active", "name"=>cu.options[:name], "type"=>"numeric"} ],
35
+ "brokers"=>[bid],
36
+ "period"=>60,
37
+ "display_name"=>display_name,
38
+ "tags"=> cu.options[:tags],
39
+ "notes"=>nil,
40
+ "config"=> {
41
+ "formula" => formula,
42
+ "composite_metric_name" => cu.options[:name]
43
+ },
44
+ "type"=>"composite"
45
+ }
46
+ puts "Bundle=#{bundle.inspect}"
47
+ bundles = cu.circonus.list_check_bundle({'type'=>'composite','display_name'=>display_name})
48
+ r = nil
49
+ if bundles.any?
50
+ print "Updating cid=#{bundles.first['_cid']}\n"
51
+ r = cu.circonus.update_check_bundle(bundles.first['_cid'],bundle)
52
+ else
53
+ print "Adding bundle\n"
54
+ r = cu.circonus.add_check_bundle(bundle)
55
+ end
56
+ if not r.nil? then
57
+ print "Success\n"
58
+ end
data/lib/circonus.rb CHANGED
@@ -116,7 +116,7 @@ class Circonus
116
116
  end
117
117
 
118
118
  # Not all these are available:
119
- %w{ account annotation broker check_bundle contact_group graph rule_set template user worksheet check }.each do |m|
119
+ %w{ account annotation broker check_bundle contact_group graph metric_cluster rule_set template user worksheet check }.each do |m|
120
120
  define_method("list_#{m}".to_sym) do |*filter|
121
121
  return list(m,filter.first)
122
122
  end
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'circonus'
3
+ require 'optparse'
4
+ class CirconusUtil
5
+ attr_accessor :options
6
+ attr_accessor :circonus
7
+ def add_opts(&optblock)
8
+ @addl_opts = optblock
9
+ end
10
+ def parse_opts()
11
+ OptionParser.new { |opts|
12
+ opts.banner = "Usage: #{File.basename($0)}\n"
13
+ opts.on( '-h', '--help', "This usage menu") do
14
+ puts opts
15
+ exit
16
+ end
17
+ opts.on( '-a','--appname APPNAME',"Name of application to report to Circonus (default: curl)" ) do |t|
18
+ @options[:appname] = t
19
+ end
20
+ opts.on( '-s','--server APISERVER',"API server to use (default: api.circonus.com)" ) do |t|
21
+ @options[:apiserver] = t
22
+ end
23
+ opts.on( '-t','--token APITOKEN',"API token to use (required in either .circonus.rb or in args" ) do |t|
24
+ @options[:apitoken] = t
25
+ end
26
+ unless @additional_opts.nil?
27
+ @additional_opts.call(opts,@options)
28
+ end
29
+ }.parse!
30
+ if options[:apitoken].to_s.empty?
31
+ puts "Missing apitoken!"
32
+ exit -1
33
+ end
34
+ end
35
+ def connect
36
+ @circonus = Circonus.new(@options[:apitoken],@options[:appname])
37
+ @circonus.set_server(@options[:apiserver])
38
+ end
39
+ def initialize(&addl_opts)
40
+ rbfile = "#{ENV['HOME']}/.circonus.rb"
41
+ require rbfile if File.exist? rbfile
42
+ @options = {}
43
+ @options[:apiserver] = @apiserver || "api.circonus.com" # can be something else for Circonus inside product...
44
+ @options[:appname] = @appname || "curl"
45
+ @options[:apitoken] = @apitoken
46
+ @additional_opts = addl_opts
47
+ self.parse_opts
48
+ self.connect
49
+ end
50
+ end
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: 3.1.5
4
+ version: 3.3.0
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: 2014-02-26 00:00:00.000000000 Z
12
+ date: 2014-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -62,17 +62,20 @@ dependencies:
62
62
  description: Wrapper and CLI for Circonus API
63
63
  email: david-vv@nicklay.com
64
64
  executables:
65
+ - circonus-add-composite
65
66
  - circonus-cli
66
67
  - circonus-data-cli
67
68
  - circonus-delete-host
68
69
  extensions: []
69
70
  extra_rdoc_files: []
70
71
  files:
72
+ - lib/circonusutil.rb
71
73
  - lib/circonus.rb
72
74
  - bin/circonus-delete-host
73
75
  - bin/update_all_composites.rb
74
76
  - bin/circonus_list_checkbundle
75
77
  - bin/circonus-data-cli
78
+ - bin/circonus-add-composite
76
79
  - bin/circonus_list_tags
77
80
  - bin/composite_builder.rb
78
81
  - bin/circonus-cli
@@ -113,3 +116,4 @@ signing_key:
113
116
  specification_version: 3
114
117
  summary: Circonus API wrapper and CLI
115
118
  test_files: []
119
+ has_rdoc: