<commit_before>#!/usr/bin/env ruby
#
# Use tags on existing composites to automate the updating of formulas on them
#

require 'rubygems'
require 'circonus'
require 'optparse'
require "#{ENV['HOME']}/.circonus.rb"

def do_update_check_bundle(data)
  r = @c.update_check_bundle(search_check_bundle.first['_cid'],data)
  if not r.nil? then
    pp r
    print "Success updating #{data['display_name']})\n"
  end
end

@c = Circonus.new(@apitoken,@appname,@agent)

# the agent that will do composites for us:
agentid = @c.list_broker({'_name'=>'composite'}).first['_cid']

# Get a cached copy for later use (this part is slow)
@cached_list_check_bundle = @c.list_check_bundle()

def get_tag_values(tags)
  Hash[tags.map { |e| e.split(':',2) }] # convert tag list to a hash (Note: this squashes duplicates)
end

# Generate the composite formula
def generate_formula(checkids,consolidation,datatype,metric)
  formula = '(' + checkids.map { |cid| "metric:#{datatype}(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
  if consolidation == 'average'
    formula = "#{formula} / #{checkids.length}"
  end<commit_msg>update all composites<commit_after>#!/usr/bin/env ruby
#
# Use tags on existing composites to automate the updating of formulas on them
#

require 'rubygems'
require 'circonus'
require 'optparse'
require "#{ENV['HOME']}/.circonus.rb"

def do_update_check_bundle(data)
  r = @c.update_check_bundle(data['_cid'],data)
  if not r.nil? then
    pp r
    print "Success updating #{data['display_name']})\n"
  end
end

@c = Circonus.new(@apitoken,@appname,@agent)

# the agent that will do composites for us:
agentid = @c.list_broker({'_name'=>'composite'}).first['_cid']

# Get a cached copy for later use (this part is slow)
@cached_list_check_bundle = @c.list_check_bundle()

def get_tag_values(tags)
  Hash[tags.map { |e| e.split(':',2) }] # convert tag list to a hash (Note: this squashes duplicates)
end

# Generate the composite formula
def generate_formula(checkids,consolidation,datatype,metric)
  formula = '(' + checkids.map { |cid| "metric:#{datatype}(#{cid.split('/').last}, \"#{metric}\", 60000)" }.join(" + ") + ')'
  if consolidation == 'average'
    formula = "#{formula} / #{checkids.length}"
  end
{'fraction_non_alphanumeric': 0.1625615763546798, 'fraction_numerical': 0.005373936408419167, 'mean_word_length': 5.137362637362638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7121719', 'n_tokens_mistral': 800, 'n_tokens_neox': 782, 'n_words': 201}