<commit_before>module NewRelic::RedshiftPlugin

  # Register and run the agent
  def self.run
    # Register this agent.
    NewRelic::Plugin::Setup.install_agent :redshift, self

    # Launch the agent; this never returns.
    NewRelic::Plugin::Run.setup_and_run
  end


  class Agent < NewRelic::Plugin::Agent::Base

    agent_guid    'com.chirag.nr.redshift'
    agent_version NewRelic::RedshiftPlugin::VERSION
    agent_config_options :host, :port, :user, :password, :dbname, :label, :schema
    agent_human_labels('Redshift') { "#{label || host}" }

    def initialize(*args)
      @previous_metrics = {}
      @previous_result_for_query ||= {}
      super
    end

    #
    # Required, but not used
    #
    def setup_metrics
    end

    #
    # Picks up default port for redshift, if user doesn't specify port in yml file
    #
    def port
      @port || 5439
    end

    #
    # Get a connection to redshift
    #
    def connect
      PG::Connection.new(:host => host, :port => port, :user => user, :password => password, :dbname => dbname)
    end

    #
    # Fallowing is called for every polling cycle
    #
    def poll_cycle
      @connection = self.connect
      puts 'Connected'
      report_metrics

    rescue => e
      $stderr.puts "#{e}: #{e.backtrace.join("\n  ")}"
    ensure
      @connection.finish if @connection
    end

    def report_metrics
      @connection.exec(percentage_memory_utilization) do |result|
        report_metric "Database/Memory/PercentageUtilized", '%' , result[0]['percentage_used']
      end

      @connection.exec(memory_used) do |result|
        report_metric "Database/Memory/Used", 'Gbytes' , result[0]['memory_used']
      end

      @connection.exec(maximum_capacity) do |result|
        report_metric "Database/Memory/MaxCapacity", 'Gbytes' , result[0]['capacity_gbytes']
      end

      @connection.exec(database_connections) do |result|
        report_metric "Database/Connections/NumberOfConnections", 'count' , result[0]['database_connections']
      end
<commit_msg>Update agent.rb<commit_after>module NewRelic::RedshiftPlugin

  # Register and run the agent
  def self.run
    # Register this agent.
    NewRelic::Plugin::Setup.install_agent :redshift, self

    # Launch the agent; this never returns.
    NewRelic::Plugin::Run.setup_and_run
  end


  class Agent < NewRelic::Plugin::Agent::Base

    agent_guid    'com.chirag.nr.redshift'
    agent_version NewRelic::RedshiftPlugin::VERSION
    agent_config_options :host, :port, :user, :password, :dbname, :label, :schema
    agent_human_labels('Redshift') { "#{label || host}" }

    def initialize(*args)
      @previous_metrics = {}
      @previous_result_for_query ||= {}
      super
    end

    #
    # Required, but not used
    #
    def setup_metrics
    end

    #
    # Picks up default port for redshift, if user doesn't specify port in yml file
    #
    def port
      @port || 5439
    end

    #
    # Get a connection to redshift
    #
    def connect
      PG::Connection.new(:host => host, :port => port, :user => user, :password => password, :dbname => dbname)
    end

    #
    # Following is called for every polling cycle
    #
    def poll_cycle
      @connection = self.connect
      puts 'Connected'
      report_metrics

    rescue => e
      $stderr.puts "#{e}: #{e.backtrace.join("\n  ")}"
    ensure
      @connection.finish if @connection
    end

    def report_metrics
      @connection.exec(percentage_memory_utilization) do |result|
        report_metric "Database/Memory/PercentageUtilized", '%' , result[0]['percentage_used']
      end

      @connection.exec(memory_used) do |result|
        report_metric "Database/Memory/Used", 'Gbytes' , result[0]['memory_used']
      end

      @connection.exec(maximum_capacity) do |result|
        report_metric "Database/Memory/MaxCapacity", 'Gbytes' , result[0]['capacity_gbytes']
      end

      @connection.exec(database_connections) do |result|
        report_metric "Database/Connections/NumberOfConnections", 'count' , result[0]['database_connections']
      end

{'fraction_non_alphanumeric': 0.1131566028473245, 'fraction_numerical': 0.0039273441335297005, 'mean_word_length': 2.975609756097561, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3383058', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1219, 'n_words': 297}