fluent-newrelic-insights 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d0fdb58a2b7afc311cacbed34ece56ff177a8ae
4
+ data.tar.gz: 7368c80ace09daff2cddfb3d385052d2e0cc0e26
5
+ SHA512:
6
+ metadata.gz: c5f417ed9d80daad1942611177b9eed22daa954d8371ff8946ea0af8f0fa0707b430ae69b9bc014c50993f0a3a870f6778cb15f2f70f380dae33a2c623215ad3
7
+ data.tar.gz: e3f595494be6e1d4bf7ee0ee2354d7bb81200edcae4c622cb78e94f9e3dcf8ba76322f36e2b5e5a165b0e934cbe579862f591f4c08a4a75e34e18515a88a0168
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Dockerfile ADDED
@@ -0,0 +1,14 @@
1
+ FROM ruby:2.2.3
2
+
3
+ WORKDIR /app
4
+
5
+ RUN gem install fluentd
6
+
7
+ COPY fluent.conf /app/fluent.conf
8
+ COPY Gemfile.test /app/Gemfile
9
+ ADD . /app/vendor/fluent-newrelic-insights
10
+ RUN bundle install -j 4
11
+
12
+ EXPOSE 24224 9880
13
+
14
+ CMD bundle exec fluentd -c ./fluent.conf
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-newrelic-insights.gemspec
4
+ gemspec
data/Gemfile.test ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'fluentd'
4
+ gem 'fluent-newrelic-insights', path: 'vendor/fluent-newrelic-insights'
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Fluent::Newrelic::Insights
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fluent/newrelic/insights`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fluent-newrelic-insights'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fluent-newrelic-insights
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-newrelic-insights.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/newrelic/insights"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/example.json ADDED
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "eventType": "TestPurchase",
4
+ "totalAmount": 1000,
5
+ "userId": 1
6
+ },
7
+ {
8
+ "eventType": "TestPurchase",
9
+ "totalAmount": 10000,
10
+ "userId": 1
11
+ },
12
+ ]
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent/plugin/newrelic_insights/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-newrelic-insights"
8
+ spec.version = Fluent::NewrelicInsights::VERSION
9
+ spec.authors = ["Kazunori Kajihiro"]
10
+ spec.email = ["kazunori.kajihiro@gmail.com"]
11
+
12
+ spec.summary = %q{Fluent outplugins that forward logs to Newrelic Insights}
13
+ spec.description = %q{Fluent outplugins that forward logs to Newrelic Insights}
14
+ spec.homepage = "https://github.com/k2nr/fluent-newrelic-insights"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_runtime_dependency "fluentd"
26
+ spec.add_runtime_dependency "rest-client"
27
+ end
data/fluent.conf ADDED
@@ -0,0 +1,16 @@
1
+ <source>
2
+ @type forward
3
+ port 24224
4
+ </source>
5
+
6
+ # http://this.host:9880/myapp.access?json={"event":"data"}
7
+ <source>
8
+ @type http
9
+ port 9880
10
+ </source>
11
+
12
+ <match **>
13
+ @type newrelic_insights
14
+ account_id 693374
15
+ insert_key khOuPU9pe1BC0dkWg2ubEEhPa0-T0UCw
16
+ </match>
@@ -0,0 +1,25 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module Fluent::NewrelicInsights
5
+ class Client
6
+ def initialize(account_id, insert_key)
7
+ @account_id = account_id
8
+ @insert_key = insert_key
9
+ @url = "https://insights-collector.newrelic.com/v1/accounts/#{account_id}/events"
10
+ end
11
+
12
+ def insert_events(events)
13
+ response = RestClient::Request.execute(
14
+ method: :post,
15
+ url: @url,
16
+ payload: events.to_json,
17
+ headers: {
18
+ "Content-Type" => "application/json",
19
+ "X-Insert-Key" => @insert_key
20
+ }
21
+ )
22
+ JSON.load(response.to_s)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Fluent
2
+ module NewrelicInsights
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'fluent/plugin/newrelic_insights/version'
2
+ require 'fluent/plugin/newrelic_insights/client'
3
+
4
+ module Fluent
5
+ module NewrelicInsights
6
+ end
7
+ end
@@ -0,0 +1,65 @@
1
+ require "fluent/plugin/newrelic_insights"
2
+ require 'json'
3
+
4
+ module Fluent
5
+ class NewrelicInsightsOutput < BufferedOutput
6
+ Fluent::Plugin.register_output('newrelic_insights', self)
7
+
8
+ config_set_default :buffer_chunk_records_limit, 1000
9
+ config_set_default :buffer_chunk_limit, 5 * 1024 * 1024
10
+ config_set_default :flush_interval, 10
11
+
12
+ config_param :account_id, :string
13
+ config_param :insert_key, :string
14
+ config_param :event_type_key, :string, default: 'eventType'
15
+ config_param :event_data_key, :string, default: '.'
16
+
17
+ def configure(conf)
18
+ super
19
+ end
20
+
21
+ def start
22
+ super
23
+ @client = Fluent::NewrelicInsights::Client.new(@account_id, @insert_key)
24
+ end
25
+
26
+ def shutdown
27
+ super
28
+ end
29
+
30
+ def format(tag, time, record)
31
+ [tag, time, record].to_msgpack
32
+ end
33
+
34
+ def write(chunk)
35
+ events = []
36
+ chunk.msgpack_each do |tag, time, record|
37
+ event = build_event(tag, time, record)
38
+ next if event.nil?
39
+ events << event
40
+ end
41
+ @client.insert_events(events)
42
+ end
43
+
44
+ def build_event(tag, time, record)
45
+ type = record[@event_type_key]
46
+ return nil unless type
47
+ data = @event_data_key == '.' ? record : reocrd[@event_data_key]
48
+ data ||= {}
49
+ return nil unless data.is_a?(Hash)
50
+ data = flatten_hash(data)
51
+ data.merge! "eventType" => type, "fluentTag" => tag, "timestamp" => time.to_i
52
+ end
53
+
54
+ def flatten_hash(hash, prefix='', base=hash, flattened={})
55
+ hash.keys.each do |k|
56
+ if hash[k].is_a? Hash
57
+ flatten_hash(hash[k], "#{prefix}#{k}.", base, flattened)
58
+ else
59
+ flattened["#{prefix}#{k}"] = hash[k]
60
+ end
61
+ end
62
+ flattened
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-newrelic-insights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazunori Kajihiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-20 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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Fluent outplugins that forward logs to Newrelic Insights
84
+ email:
85
+ - kazunori.kajihiro@gmail.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Dockerfile
96
+ - Gemfile
97
+ - Gemfile.test
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - example.json
103
+ - fluent-newrelic-insights.gemspec
104
+ - fluent.conf
105
+ - lib/fluent/plugin/newrelic_insights.rb
106
+ - lib/fluent/plugin/newrelic_insights/client.rb
107
+ - lib/fluent/plugin/newrelic_insights/version.rb
108
+ - lib/fluent/plugin/out_newrelic_insights.rb
109
+ homepage: https://github.com/k2nr/fluent-newrelic-insights
110
+ licenses: []
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Fluent outplugins that forward logs to Newrelic Insights
132
+ test_files: []