fluent-plugin-stathat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-stathat.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 f440
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Fluent::Plugin::Stathat
2
+
3
+ StatHat output plugin for Fluentd.
4
+
5
+ ## Installation
6
+
7
+ $ fluent-gem install fluent-plugin-stathat
8
+
9
+ ## Configuration
10
+
11
+ <match stathat.**>
12
+ type stathat
13
+ ezkey your_email@example.com # The ezkey for your StatHat account
14
+
15
+ stat my_graph # stat name (default: tag name)
16
+ count key_name
17
+ # or `value key_name`.
18
+ # this plugin requires either `count` or `value` is required, but not both.
19
+ </match>
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
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-stathat"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["f440"]
9
+ spec.email = ["freq440@gmail.com"]
10
+ spec.description = %q{StatHat output plugin for Fluentd.}
11
+ spec.summary = spec.description
12
+ spec.homepage = "https://github.com/f440/fluent-plugin-stathat/"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,65 @@
1
+ module Fluent
2
+ class StathatOutput < Fluent::BufferedOutput
3
+ Fluent::Plugin.register_output('stathat', self)
4
+
5
+ config_param :ezkey
6
+ config_param :count, :default => nil
7
+ config_param :value, :default => nil
8
+ config_param :stat, :default => nil
9
+
10
+ def initialize
11
+ require 'net/https'
12
+ require 'uri'
13
+ require 'json'
14
+
15
+ super
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ if (@count.nil? && @value.nil?) || (@count && @value)
22
+ raise ConfigError, "stathat_out requires either 'count' or 'value', but not both"
23
+ end
24
+
25
+ @uri = URI.parse("https://api.stathat.com/ez")
26
+
27
+ @https = Net::HTTP.new(@uri.host, @uri.port)
28
+ @https.use_ssl = true
29
+ end
30
+
31
+ def start
32
+ super
33
+ end
34
+
35
+ def shutdown
36
+ super
37
+ end
38
+
39
+ def format(tag, time, record)
40
+ [tag, time, record].to_msgpack
41
+ end
42
+
43
+ def write(chunk)
44
+ data = []
45
+ chunk.msgpack_each do |tag, time, record|
46
+ stat = (@stat || tag)
47
+
48
+ if record.has_key? @count
49
+ data << {stat: stat, t: time, count: record[@count]}
50
+ elsif record.has_key? @value
51
+ data << {stat: stat, t: time, value: record[@value]}
52
+ end
53
+ end
54
+ post(ezkey: @ezkey, data: data) if data.length > 0
55
+ end
56
+
57
+ def post(data)
58
+ req = Net::HTTP::Post.new(@uri.request_uri)
59
+ req.content_type = 'application/json'
60
+ req.body = data.to_json
61
+
62
+ @https.request(req)
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-stathat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - f440
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: StatHat output plugin for Fluentd.
47
+ email:
48
+ - freq440@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - fluent-plugin-stathat.gemspec
59
+ - lib/fluent/plugin/out_stathat.rb
60
+ homepage: https://github.com/f440/fluent-plugin-stathat/
61
+ licenses:
62
+ - MIT
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.23
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: StatHat output plugin for Fluentd.
85
+ test_files: []
86
+ has_rdoc: