fluent-plugin-newrelic-summary 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/fluent-plugin-newrelic-summary.gemspec +25 -0
- data/lib/fluent/plugin/in_newrelic_summary.rb +75 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_in_newrelic_summary.rb +52 -0
- metadata +110 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: cb1d7b35a023071695c587d10932bebfd592c978
         | 
| 4 | 
            +
              data.tar.gz: 54af1a983795b693f809d19538bccbae29139584
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: e47d3a9bdfee83471b3abcdd95802b556c63c00574c96c105ba1ce4c99b7c5f64ddfb42ca59a0a54a6c7a2918e5c03f3fcf188e9d3ce8c9a9ea4643c290f41c5
         | 
| 7 | 
            +
              data.tar.gz: c1062e83171a82e42cfea8c4ad8fbdeac55281b4945dbb0904ddfa951f7975e346dd87f99ca6467d0df5281a7f55148f682cc202b155c3e28b7cbd0ae157dbfe
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            # fluent-plugin-newrelic-summary
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Fluentd input plugin to receive NewRelic summary data.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Please visit below link for the specification of NewRelic summary API.
         | 
| 6 | 
            +
            https://docs.newrelic.com/docs/apis/rest-api-v2/application-examples-v2/summary-data-examples-v2
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## Installation
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            Add this line to your application's Gemfile:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ```ruby
         | 
| 13 | 
            +
            gem 'fluent-plugin-newrelic-summary'
         | 
| 14 | 
            +
            ```
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            And then execute:
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                $ bundle
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Or install it yourself as:
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                $ gem install fluent-plugin-newrelic-summary
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## Usage
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            The following is an example of configuration.
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ```
         | 
| 29 | 
            +
            <source>
         | 
| 30 | 
            +
              type newrelic_summary
         | 
| 31 | 
            +
              api_key xxxxxxxxx
         | 
| 32 | 
            +
              interval 60 # sec. default is 60 sec.
         | 
| 33 | 
            +
              summary applications|servers|key_transactions
         | 
| 34 | 
            +
            </source>
         | 
| 35 | 
            +
            ```
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## Contributing
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            1. Fork it ( http://github.com/hiroakis/fluent-plugin-newrelic-summary/fork )
         | 
| 40 | 
            +
            2. Create your feature branch (git checkout -b my-new-feature)
         | 
| 41 | 
            +
            3. Commit your changes (git commit -am 'Add some feature')
         | 
| 42 | 
            +
            4. Push to the branch (git push origin my-new-feature)
         | 
| 43 | 
            +
            5. Create new Pull Request
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            ## License
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            MIT
         | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name          = "fluent-plugin-newrelic-summary"
         | 
| 7 | 
            +
              spec.version       = "0.0.1"
         | 
| 8 | 
            +
              spec.authors       = ["Hiroaki Sano"]
         | 
| 9 | 
            +
              spec.email         = ["hiroaki.sano.9stories@gmail.com"]
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              spec.summary       = %q{Fluent input plugin to get NewRelic application summary.}
         | 
| 12 | 
            +
              spec.homepage      = "https://github.com/hiroakis/fluent-plugin-newrelic-summary"
         | 
| 13 | 
            +
              spec.license       = "MIT"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              spec.files         = `git ls-files`.split("\n")
         | 
| 16 | 
            +
              spec.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 17 | 
            +
              spec.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.require_paths = ["lib"]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              spec.add_development_dependency "bundler", "~> 1.10"
         | 
| 21 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 22 | 
            +
              spec.add_development_dependency "test-unit"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              spec.add_runtime_dependency "fluentd"
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            require 'net/https'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Fluent
         | 
| 4 | 
            +
              class NewRelicSummaryInput < Input
         | 
| 5 | 
            +
                Plugin.register_input('newrelic_summary', self)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                NEW_RELIC_API_DOMAIN = 'api.newrelic.com'
         | 
| 8 | 
            +
                SUMMARIES = %w(applications servers key_transactions)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                config_param :tag, :string, :default => nil
         | 
| 11 | 
            +
                config_param :api_key, :string, :defaut => nil, :secret => true
         | 
| 12 | 
            +
                config_param :summary, :string, :default => "applications"
         | 
| 13 | 
            +
                config_param :interval, :integer, :default => 60 # sec
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                unless method_defined?(:log)
         | 
| 16 | 
            +
                  define_method("log") { $log }
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def initialize
         | 
| 20 | 
            +
                  super
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def configure(conf)
         | 
| 24 | 
            +
                  log.trace "in_newrelic_summary: configure"
         | 
| 25 | 
            +
                  super
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  if @tag.nil?
         | 
| 28 | 
            +
                    raise Fluent::ConfigError, "newrelic_summary: 'tag' parameter is required"
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  unless SUMMARIES.include?(@summary)
         | 
| 31 | 
            +
                    raise Fluent::ConfigError, "newrelic_summary: no such 'summary' parameter. summary should be applications, servers or key_transactions"
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def start
         | 
| 36 | 
            +
                  log.trace "in_newrelic_summary: start"
         | 
| 37 | 
            +
                  super
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  @thread = Thread.new(&method(:run))
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def shutdown
         | 
| 43 | 
            +
                  log.trace "in_newrelic_summary: shutdown"
         | 
| 44 | 
            +
                  super
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  Thread.kill(@thread)
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                def run
         | 
| 50 | 
            +
                  log.trace "in_newrelic_summary: run"
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  loop do
         | 
| 53 | 
            +
                    http = Net::HTTP.new(NEW_RELIC_API_DOMAIN, 443)
         | 
| 54 | 
            +
                    http.use_ssl = true
         | 
| 55 | 
            +
                    uri = "/v2/#{@summary}.json"
         | 
| 56 | 
            +
                    req = Net::HTTP::Get.new(uri)
         | 
| 57 | 
            +
                    req["NewRelic-Api-Key"] = @api_key
         | 
| 58 | 
            +
                    res = http.request(req)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                    case res
         | 
| 61 | 
            +
                    when Net::HTTPSuccess
         | 
| 62 | 
            +
                      emit_data(JSON.parse(res.body))
         | 
| 63 | 
            +
                    else
         | 
| 64 | 
            +
                      log.error "in_newrelic_summary: error"
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                    sleep @interval
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                end # The end of run method
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                def emit_data(data)
         | 
| 71 | 
            +
                  log.trace "in_newrelic_summary: emit_data"
         | 
| 72 | 
            +
                  Engine.emit("#{tag}", Engine.now, data)
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
            end
         | 
    
        data/test/helper.rb
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
            require 'bundler'
         | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              Bundler.setup(:default, :development)
         | 
| 5 | 
            +
            rescue Bundler::BundlerError => e
         | 
| 6 | 
            +
              $stderr.puts e.message
         | 
| 7 | 
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         | 
| 8 | 
            +
              exit e.status_code
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
            require 'test/unit'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         | 
| 13 | 
            +
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         | 
| 14 | 
            +
            require 'fluent/test'
         | 
| 15 | 
            +
            unless ENV.has_key?('VERBOSE')
         | 
| 16 | 
            +
              nulllogger = Object.new
         | 
| 17 | 
            +
              nulllogger.instance_eval {|obj|
         | 
| 18 | 
            +
                def method_missing(method, *args)
         | 
| 19 | 
            +
                  # pass
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              }
         | 
| 22 | 
            +
              $log = nulllogger
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            require 'fluent/plugin/in_newrelic_summary'
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            class Test::Unit::TestCase
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            require 'helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class NewRelicSummaryTest < Test::Unit::TestCase
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def setup
         | 
| 6 | 
            +
                Fluent::Test.setup
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              CONFIG = %[
         | 
| 10 | 
            +
                type newrelic_summary
         | 
| 11 | 
            +
                api_key NEWRELIC_API_KEY
         | 
| 12 | 
            +
                interval 5
         | 
| 13 | 
            +
                summary applications
         | 
| 14 | 
            +
                tag newrelic.summary
         | 
| 15 | 
            +
              ]
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def create_driver(conf=CONFIG, tag='test')
         | 
| 18 | 
            +
                Fluent::Test::OutputTestDriver.new(Fluent::NewRelicSummaryInput, tag).configure(conf)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def test_configuration
         | 
| 22 | 
            +
                d = create_driver
         | 
| 23 | 
            +
                assert_equal 'NEWRELIC_API_KEY', d.instance.api_key
         | 
| 24 | 
            +
                assert_equal 5, d.instance.interval
         | 
| 25 | 
            +
                assert_equal 'applications', d.instance.summary
         | 
| 26 | 
            +
                assert_equal 'newrelic.summary', d.instance.tag
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def test_configuration_with_empty_tag
         | 
| 30 | 
            +
                assert_raise(Fluent::ConfigError) {
         | 
| 31 | 
            +
                  create_driver %[
         | 
| 32 | 
            +
                    type newrelic_summary
         | 
| 33 | 
            +
                    api_key NEWRELIC_API_KEY
         | 
| 34 | 
            +
                    interval 5
         | 
| 35 | 
            +
                    summary applications
         | 
| 36 | 
            +
                    # tag newrelic.summary
         | 
| 37 | 
            +
                  ]
         | 
| 38 | 
            +
                }
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              def test_configuration_with_unknown_summary
         | 
| 42 | 
            +
                assert_raise(Fluent::ConfigError) {
         | 
| 43 | 
            +
                  create_driver %[
         | 
| 44 | 
            +
                    type newrelic_summary
         | 
| 45 | 
            +
                    api_key NEWRELIC_API_KEY
         | 
| 46 | 
            +
                    interval 5
         | 
| 47 | 
            +
                    summary XXXXXXX
         | 
| 48 | 
            +
                    tag newrelic.summary
         | 
| 49 | 
            +
                  ]
         | 
| 50 | 
            +
                }
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,110 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: fluent-plugin-newrelic-summary
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Hiroaki Sano
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-01-17 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.10'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.10'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: test-unit
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: fluentd
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            description: 
         | 
| 70 | 
            +
            email:
         | 
| 71 | 
            +
            - hiroaki.sano.9stories@gmail.com
         | 
| 72 | 
            +
            executables: []
         | 
| 73 | 
            +
            extensions: []
         | 
| 74 | 
            +
            extra_rdoc_files: []
         | 
| 75 | 
            +
            files:
         | 
| 76 | 
            +
            - ".gitignore"
         | 
| 77 | 
            +
            - Gemfile
         | 
| 78 | 
            +
            - README.md
         | 
| 79 | 
            +
            - Rakefile
         | 
| 80 | 
            +
            - fluent-plugin-newrelic-summary.gemspec
         | 
| 81 | 
            +
            - lib/fluent/plugin/in_newrelic_summary.rb
         | 
| 82 | 
            +
            - test/helper.rb
         | 
| 83 | 
            +
            - test/plugin/test_in_newrelic_summary.rb
         | 
| 84 | 
            +
            homepage: https://github.com/hiroakis/fluent-plugin-newrelic-summary
         | 
| 85 | 
            +
            licenses:
         | 
| 86 | 
            +
            - MIT
         | 
| 87 | 
            +
            metadata: {}
         | 
| 88 | 
            +
            post_install_message: 
         | 
| 89 | 
            +
            rdoc_options: []
         | 
| 90 | 
            +
            require_paths:
         | 
| 91 | 
            +
            - lib
         | 
| 92 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
              requirements:
         | 
| 94 | 
            +
              - - ">="
         | 
| 95 | 
            +
                - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                  version: '0'
         | 
| 97 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 98 | 
            +
              requirements:
         | 
| 99 | 
            +
              - - ">="
         | 
| 100 | 
            +
                - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                  version: '0'
         | 
| 102 | 
            +
            requirements: []
         | 
| 103 | 
            +
            rubyforge_project: 
         | 
| 104 | 
            +
            rubygems_version: 2.4.5
         | 
| 105 | 
            +
            signing_key: 
         | 
| 106 | 
            +
            specification_version: 4
         | 
| 107 | 
            +
            summary: Fluent input plugin to get NewRelic application summary.
         | 
| 108 | 
            +
            test_files:
         | 
| 109 | 
            +
            - test/helper.rb
         | 
| 110 | 
            +
            - test/plugin/test_in_newrelic_summary.rb
         |