Chapter 09/circuit-oneops-1-master/components/cookbooks/diagnostic_cache/files/default/couchbase_monitor.rb
#Collects all bucket level metrics from the cluster and stream it to graphite clusters
Collects all bucket level metrics from the cluster and stream it to graphite clusters
Collects all bucket level metrics from the cluster and stream it to graphite clusters
def bucket_stats(url, time)
    logger.info "bucket_stats:start: url = #{url}, time = #{time.to_i}"
    jsonResponse = rest_call(url)
    buckets = JSON.parse(jsonResponse)
    buckets.each do |bucket|
      bucket_name = bucket['name'].gsub(/\./, '-')
      replica_num =  bucket['replicaNumber']
      ram_quota = bucket['quota']['ram']
      ram_quota_raw = bucket['quota']['rawRAM']
      quota_percent_used = bucket['basicStats']['quotaPercentUsed']
      ops_per_sec = bucket['basicStats']['opsPerSec']
      disk_fetches = bucket['basicStats']['diskFetches']
      item_count = bucket['basicStats']['itemCount']
      disk_used = bucket['basicStats']['diskUsed']
      data_used = bucket['basicStats']['dataUsed']
      mem_used = bucket['basicStats']['memUsed']
      node_size = bucket['nodes'].length
      data_availability_pct = data_availability(node_size, replica_num, @healthy_nodes, @failover_nodes)
      write_to_graphite( construct_metric_name("#{bucket_name}.replica_num", CONST_BUCKET_LEVEL), replica_num.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.quota_percent_used", CONST_BUCKET_LEVEL), quota_percent_used.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.ops", CONST_BUCKET_LEVEL), ops_per_sec.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.mem_used", CONST_BUCKET_LEVEL), mem_used.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.item_cnt", CONST_BUCKET_LEVEL), item_count.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.disk_used", CONST_BUCKET_LEVEL), disk_used.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.disk_fetches", CONST_BUCKET_LEVEL), disk_fetches.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.data_used", CONST_BUCKET_LEVEL), data_used.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.ram_quota", CONST_BUCKET_LEVEL), ram_quota.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.ram_quota_raw", CONST_BUCKET_LEVEL), ram_quota_raw.to_s, time)
      write_to_graphite( construct_metric_name("#{bucket_name}.data_availability_pct", CONST_BUCKET_LEVEL), data_availability_pct.to_s, time)
      get_cmd_histogram(bucket_name, @hostname , @password, 11210, time)
    end
    logger.info 'bucket_stats:end: Completed'
  end
def bucket_stats ( url , time ) logger . info "bucket_stats:start: url = #{url}, time = #{time.to_i}" jsonResponse = rest_call ( url ) buckets = JSON . parse ( jsonResponse ) buckets . each do | bucket | bucket_name = bucket [ 'name' ] . gsub ( / \. / , '-' ) replica_num = bucket [ 'replicaNumber' ] ram_quota = bucket [ 'quota' ] [ 'ram' ] ram_quota_raw = bucket [ 'quota' ] [ 'rawRAM' ] quota_percent_used = bucket [ 'basicStats' ] [ 'quotaPercentUsed' ] ops_per_sec = bucket [ 'basicStats' ] [ 'opsPerSec' ] disk_fetches = bucket [ 'basicStats' ] [ 'diskFetches' ] item_count = bucket [ 'basicStats' ] [ 'itemCount' ] disk_used = bucket [ 'basicStats' ] [ 'diskUsed' ] data_used = bucket [ 'basicStats' ] [ 'dataUsed' ] mem_used = bucket [ 'basicStats' ] [ 'memUsed' ] node_size = bucket [ 'nodes' ] . length data_availability_pct = data_availability ( node_size , replica_num , @healthy_nodes , @failover_nodes ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.replica_num" , CONST_BUCKET_LEVEL ) , replica_num . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.quota_percent_used" , CONST_BUCKET_LEVEL ) , quota_percent_used . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.ops" , CONST_BUCKET_LEVEL ) , ops_per_sec . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.mem_used" , CONST_BUCKET_LEVEL ) , mem_used . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.item_cnt" , CONST_BUCKET_LEVEL ) , item_count . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.disk_used" , CONST_BUCKET_LEVEL ) , disk_used . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.disk_fetches" , CONST_BUCKET_LEVEL ) , disk_fetches . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.data_used" , CONST_BUCKET_LEVEL ) , data_used . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.ram_quota" , CONST_BUCKET_LEVEL ) , ram_quota . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.ram_quota_raw" , CONST_BUCKET_LEVEL ) , ram_quota_raw . to_s , time ) write_to_graphite ( construct_metric_name ( "#{bucket_name}.data_availability_pct" , CONST_BUCKET_LEVEL ) , data_availability_pct . to_s , time ) get_cmd_histogram ( bucket_name , @hostname , @password , 11210 , time ) end logger . info 'bucket_stats:end: Completed' end
Collects all bucket level metrics from the cluster and stream it to graphite clusters
Collects all bucket level metrics from the cluster and stream it to graphite clusters
url
<not_specific>
time
<not_specific>