<commit_before>#! /usr/bin/env ruby

#
# This module is an agent that provides metric for
# a google cloud storage buket
# Please fill the config file before run
#

require "rubygems"
require "bundler/setup"

require "newrelic_plugin"

require_relative 'modules/googleAuth'

module GCloudStorageAgent

  #
  # Agent, Metric and PollCycle classes
  #
  # Each agent module must have an Agent, Metric and PollCycle class that inherits from their
  # Component counterparts as you can see below.
  #

  class Agent < NewRelic::Plugin::Agent::Base
    agent_guid "ch.nkcr.test.google_cloud_storage_metric3"
    agent_version "1.0.1"
    #
    # agent_config is a list of variables that the component will need
    # from its instances.
    #
    agent_config_options :google_storage_bucket_name, :google_storage_key_path,:google_storage_key_secret,:google_storage_mail
    agent_human_labels("GCloud Storage") { "Bucket /#{google_storage_bucket_name}" }

    def setup_metrics
      @google = GClient.new(google_storage_key_path,google_storage_key_secret,google_storage_mail)
      @next_day = (Time.now + 86400).day
      @last_number = @google.number(google_storage_bucket_name)
      @last_size = @google.size(google_storage_bucket_name)
      @current_element_dif = 0
      @current_size_dif = 0
      @elements_rate = NewRelic::Processor::EpochCounter.new
      @size_rate = NewRelic::Processor::EpochCounter.new
    end

    def poll_cycle
      number = @google.number(google_storage_bucket_name)
      tot_size = @google.size(google_storage_bucket_name)
      report_metric "Total/size", "Bytes", tot_size
      report_metric "Total/elements", "Elements", number
      current_day = Time.now.day
      if current_day == @next_day
        @next_day = (Time.now + 86400).day
        @current_element_dif = number - @last_number
        @last_number = number
        @current_size_dif = tot_size - @last_size
        @last_size = tot_size
        puts "[#{Time.now}] i go"
      end
      report_metric "Difference/day/elements", "Elements", @current_element_dif
      report_metric "Difference/day/size", "Bytes", @current_size_dif
      report_metric "Difference/rate/elements", "Elements", @elements_rate.process(number)
      report_metric "Difference/rate/size", "Bytes", @size_rate.process(tot_size)
    end

  end

  #
  # Register this agent with the component.<commit_msg>clean up<commit_after>#! /usr/bin/env ruby

#
# This module is an agent that provides metric for
# a google cloud storage buket
# Please fill the config file before run
#

require "rubygems"
require "bundler/setup"

require "newrelic_plugin"

require_relative 'modules/googleAuth'

module GCloudStorageAgent

  #
  # Agent, Metric and PollCycle classes
  #
  # Each agent module must have an Agent, Metric and PollCycle class that inherits from their
  # Component counterparts as you can see below.
  #

  class Agent < NewRelic::Plugin::Agent::Base
    agent_guid "ch.nkcr.test.google_cloud_storage_metric3"
    agent_version "1.0.1"
    #
    # agent_config is a list of variables that the component will need
    # from its instances.
    #
    agent_config_options :google_storage_bucket_name, :google_storage_key_path,:google_storage_key_secret,:google_storage_mail
    agent_human_labels("GCloud Storage") { "Bucket /#{google_storage_bucket_name}" }

    def setup_metrics
      @google = GClient.new(google_storage_key_path,google_storage_key_secret,google_storage_mail)
      @next_day = (Time.now + 86400).day
      @last_number = @google.number(google_storage_bucket_name)
      @last_size = @google.size(google_storage_bucket_name)
      @current_element_dif = 0
      @current_size_dif = 0
      @elements_rate = NewRelic::Processor::EpochCounter.new
      @size_rate = NewRelic::Processor::EpochCounter.new
    end

    def poll_cycle
      number = @google.number(google_storage_bucket_name)
      tot_size = @google.size(google_storage_bucket_name)
      current_day = Time.now.day
      if current_day == @next_day
        @next_day = (Time.now + 86400).day
        @current_element_dif = number - @last_number
        @last_number = number
        @current_size_dif = tot_size - @last_size
        @last_size = tot_size
        puts "[#{Time.now}] i go"
      end
      report_metric "Total/size", "Bytes", tot_size
      report_metric "Total/elements", "Elements", number
      report_metric "Difference/day/elements", "Elements", @current_element_dif
      report_metric "Difference/day/size", "Bytes", @current_size_dif
      report_metric "Difference/rate/elements", "Elements", @elements_rate.process(number)
      report_metric "Difference/rate/size", "Bytes", @size_rate.process(tot_size)
    end

  end

  #
  # Register this agent with the component.
{'fraction_non_alphanumeric': 0.09161588569027107, 'fraction_numerical': 0.006724101702038243, 'mean_word_length': 3.817813765182186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3487333', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1492, 'n_words': 340}