fluent-plugin-stackdriver-monitoring 0.0.1

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: e30388f7688cbb1f15ba85437d4ea5dd4402527f
4
+ data.tar.gz: f957f5d472d0fa713cdeaff4852aadc79784103a
5
+ SHA512:
6
+ metadata.gz: a0634a724daddae317b894aa131691ce6f29713062e91821a7bd2543a3b98fcb3206a8d88899519e8e62d0f68ba78f7275b2cbf6a4baa95e626c17cd56348302
7
+ data.tar.gz: ee4aceb22ae5c4327291b834771d65821be38fd8251dbd224c36a437205f99e717aa4161a9b4e41de8fe419d8aac6c1613f2d402654c7ed7cc61e9d53749883d
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,30 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2.5
7
+ - 2.3.1
8
+ - ruby-head
9
+ - rbx
10
+
11
+ gemfile:
12
+ - Gemfile
13
+ - Gemfile.v0.12
14
+
15
+ branches:
16
+ only:
17
+ - master
18
+
19
+ before_install: gem update bundler
20
+ script: bundle exec rake test
21
+
22
+ sudo: false
23
+
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: ruby-head
27
+ - rvm: rbx
28
+ exclude:
29
+ - rvm: 2.0
30
+ gemfile: Gemfile
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.v0.12 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'fluentd', '~> 0.12.0'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Yoshihiro MIYAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # fluent-plugin-stackdriver-monitoring
2
+
3
+ [Stackdriver Monitoring](https://cloud.google.com/monitoring/) custom metrics output plugin for [Fluentd](http://www.fluentd.org/)
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ $ gem install fluent-plugin-stackdriver-monitoring
9
+ ```
10
+
11
+ ## Authentication
12
+
13
+ See [google-cloud-monitoring gem document](https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-monitoring#setup-authentication).
14
+
15
+ ## Configuration
16
+
17
+ Sample configuration is below.
18
+
19
+ ```
20
+ <match your.tag>
21
+ @type stackdriver_monitoring
22
+ project {{PROJECT_NAME}}
23
+
24
+ <custom_metrics>
25
+ key {{KEY_NAME}}
26
+ type custom.googleapis.com/{{METRICS_NAME}}
27
+ metric_kind GAUGE
28
+ value_type INT64
29
+ </custom_metrics>
30
+
31
+ flush_interval 1s # must be 1(sec) or above
32
+ </match>
33
+ ```
34
+
35
+ - project (string, required)
36
+ - Set your Stackdriver project id.
37
+ - <custom_metrics>
38
+ - key (string, required)
39
+ - Specify field name in your log to send to Stackdriver.
40
+ - type (string, required)
41
+ - Set name of descriptor. It must start with `custom.googleapis.com/`.
42
+ - metric_kind(enum, required)
43
+ - See [metric kind](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#MetricKind).
44
+ - You can specify `GAUGE`, `DELTA` or `CUMULATIVE`.
45
+ - value_type(enum, required)
46
+ - See [value type](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#valuetype).
47
+ - You can specify `BOOL`, `INT64`, `DOUBLE` or `STRING`.
48
+
49
+ ## TODO
50
+
51
+ - Add test!
52
+ - Support Unit and Monitored Resource in custom_metrics.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/plugin/test_*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:build]
@@ -0,0 +1,25 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'fluent-plugin-stackdriver-monitoring'
5
+ gem.description = 'Stackdriver Monitoring custom metrics output plugin for Fluentd'
6
+ gem.license = 'MIT'
7
+ gem.homepage = 'https://github.com/mia-0032/fluent-plugin-stackdriver-monitoring'
8
+ gem.summary = gem.description
9
+ gem.version = '0.0.1'
10
+ gem.authors = ['Yoshihiro MIYAI']
11
+ gem.email = 'msparrow17@gmail.com'
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_runtime_dependency 'fluentd', ['>= 0.12.0', '< 2']
19
+ gem.add_runtime_dependency 'google-cloud-monitoring', '~> 0.21.0'
20
+
21
+ gem.add_development_dependency 'bundler'
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'test-unit'
24
+ gem.add_development_dependency 'test-unit-rr'
25
+ end
@@ -0,0 +1,118 @@
1
+ require 'fluent/output'
2
+ require 'google/api/metric_pb'
3
+ require 'google/cloud/monitoring/v3/metric_service_api'
4
+ require 'google/protobuf/repeated_field'
5
+ require 'google/protobuf/timestamp_pb'
6
+
7
+ module Fluent
8
+ class StackdriverMonitoringOutput < BufferedOutput
9
+ Fluent::Plugin.register_output('stackdriver_monitoring', self)
10
+
11
+ config_param :project, :string
12
+ config_section :custom_metrics, required: true, multi: false do
13
+ config_param :key, :string
14
+ config_param :type, :string
15
+ config_param :metric_kind, :enum, list: [:GAUGE, :DELTA, :CUMULATIVE]
16
+ config_param :value_type, :enum, list: [:BOOL, :INT64, :DOUBLE, :STRING] # todo: implement :DISTRIBUTION, :MONEY
17
+ end
18
+
19
+ TYPE_PREFIX = 'custom.googleapis.com/'.freeze
20
+
21
+ def configure(conf)
22
+ super
23
+
24
+ unless @custom_metrics.type.start_with? TYPE_PREFIX
25
+ raise "custom_metrics.type must start with \"#{TYPE_PREFIX}\""
26
+ end
27
+
28
+ @project_name = Google::Cloud::Monitoring::V3::MetricServiceApi.project_path @project
29
+ @metric_name = Google::Cloud::Monitoring::V3::MetricServiceApi.metric_descriptor_path @project, @custom_metrics.type
30
+ end
31
+
32
+ def start
33
+ super
34
+
35
+ @metric_service_api = Google::Cloud::Monitoring::V3::MetricServiceApi.new
36
+ @metric_descriptor = create_metric_descriptor
37
+ end
38
+
39
+ def format(tag, time, record)
40
+ [tag, time, record].to_msgpack
41
+ end
42
+
43
+ def write(chunk)
44
+ chunk.msgpack_each do |tag, time, record|
45
+ time_series = create_time_series
46
+ value = record[@custom_metrics.key]
47
+
48
+ point = Google::Monitoring::V3::Point.new
49
+ point.interval = create_time_interval time
50
+ point.value = create_typed_value value
51
+ time_series.points.push point
52
+
53
+ log.debug "Create time series", time: Time.at(time).to_s, value: value, metric_name: @metric_name
54
+ # Only one point can be written per TimeSeries per request.
55
+ @metric_service_api.create_time_series @project_name, [time_series]
56
+ end
57
+ end
58
+
59
+ private
60
+ def create_metric_descriptor
61
+ begin
62
+ metric_descriptor = @metric_service_api.get_metric_descriptor(@metric_name)
63
+ log.info "Succeed to get metric descripter", metric_name: @metric_name
64
+ return metric_descriptor
65
+ rescue Google::Gax::RetryError
66
+ log.info "Failed to get metric descripter", metric_name: @metric_name
67
+ end
68
+
69
+ metric_descriptor = Google::Api::MetricDescriptor.new
70
+ metric_descriptor.type = @custom_metrics.type
71
+ metric_descriptor.metric_kind = @custom_metrics.metric_kind
72
+ metric_descriptor.value_type = @custom_metrics.value_type
73
+ metric_descriptor = @metric_service_api.create_metric_descriptor(@project_name, metric_descriptor)
74
+ log.info "Succeed to create metric descripter", metric_name: @metric_name
75
+
76
+ metric_descriptor
77
+ end
78
+
79
+ def create_time_series
80
+ time_series = Google::Monitoring::V3::TimeSeries.new
81
+
82
+ metric = Google::Api::Metric.new
83
+ metric.type = @metric_descriptor.type
84
+ time_series.metric = metric
85
+
86
+ time_series.metric_kind = @metric_descriptor.metric_kind
87
+ time_series.value_type = @metric_descriptor.value_type
88
+
89
+ time_series
90
+ end
91
+
92
+ def create_time_interval(time)
93
+ time_interval = Google::Monitoring::V3::TimeInterval.new
94
+ time_interval.start_time = Google::Protobuf::Timestamp.new seconds: time
95
+ time_interval.end_time = Google::Protobuf::Timestamp.new seconds: time
96
+
97
+ time_interval
98
+ end
99
+
100
+ def create_typed_value(value)
101
+ typed_value = Google::Monitoring::V3::TypedValue.new
102
+ case @metric_descriptor.value_type
103
+ when :BOOL
104
+ typed_value.bool_value = value.to_bool
105
+ when :INT64
106
+ typed_value.int64_value = value.to_i
107
+ when :DOUBLE
108
+ typed_value.double_value = value.to_f
109
+ when :STRING
110
+ typed_value.string_value = value.to_s
111
+ else
112
+ raise 'Unknown value_type!'
113
+ end
114
+
115
+ typed_value
116
+ end
117
+ end
118
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-stackdriver-monitoring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yoshihiro MIYAI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: google-cloud-monitoring
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.21.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.21.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: test-unit-rr
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: Stackdriver Monitoring custom metrics output plugin for Fluentd
104
+ email: msparrow17@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - Gemfile.v0.12
113
+ - LICENSE
114
+ - README.md
115
+ - Rakefile
116
+ - fluent-plugin-stackdriver-monitoring.gemspec
117
+ - lib/fluent/plugin/out_stackdriver_monitoring.rb
118
+ homepage: https://github.com/mia-0032/fluent-plugin-stackdriver-monitoring
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Stackdriver Monitoring custom metrics output plugin for Fluentd
142
+ test_files: []