fluent-plugin-calyptia-monitoring 0.1.0.rc6 → 0.1.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc96c5b09c542854a7fc86e735d01c1b8d15d6ffcacc35d21bc4e02578f7d379
4
- data.tar.gz: 1deccf93ccb4b41f802099d72b33670459d78c65917af979dd074041de6b964f
3
+ metadata.gz: 7cfa17ee6e7d7b29c255151a698bdc9c004e936a1760a2f39ece7b204627f868
4
+ data.tar.gz: '098ab10f65f463b7de64f1a30adb828877285ff4aa6482fd3fec6e02e1e2de59'
5
5
  SHA512:
6
- metadata.gz: ba2e21ff1a791fcf81d33d3c568874ac672c3b9882e942007e57c403f2f0d0a12d211b473244bff8303f58bb5b853f2d9acb6c2d527e0d9623484c0a626f26b1
7
- data.tar.gz: 62b0c374c5917ca03d8b836fdf2508838e4cc134d04e25873021fd972fa9914f5a38888e2de62d335b5576883307c343ec72b3f00d5959eb502cf9cd8ec9e87d
6
+ metadata.gz: e545fd36229c0be2bfbcf2a60045033ae95e131e67bd5ee810a2b784a71a4ba707684bb4d8674e7d891565ef0fce59b4f46f72c21fc4e30e60b94bf9274a6673
7
+ data.tar.gz: d408f12b6c6a12ca21e402858703c57692b87c57a7571017e5c6beef30e019c15c1adea4f5def05711cdfef79c50c01286f839babec0501a033a43ab4e7f137a
data/README.md CHANGED
@@ -84,6 +84,28 @@ And enabling RPC and configDump endpoint is required if sending Fluentd configur
84
84
  </source>
85
85
  ```
86
86
 
87
+ ## Calyptia Monitoring API config generator
88
+
89
+ Usage:
90
+
91
+ ```
92
+ Usage: calyptia-config-generator api_key [options]
93
+
94
+ Output plugin config definitions
95
+
96
+ Arguments:
97
+ api_key: Specify your API_KEY
98
+
99
+ Options:
100
+ --endpoint URL API Endpoint URL (default: nil, and if omitted, using default endpoint)
101
+ --rpc-endpoint URL Specify RPC Endpoint URL (default: 127.0.0.1:24444)
102
+ --disable-input-metrics Disable Input plugin metrics. Input metrics is enabled by default
103
+ --enable-size-metrics Enable event size metrics. Size metrics is disabled by default.
104
+ --disable-get-dump Disable RPC getDump procedure. getDump is enabled by default.
105
+ --storage-agent-token-dir DIR
106
+ Specify accesible storage token dir. (default: /path/to/accesible/dir)
107
+ ```
108
+
87
109
  ## Copyright
88
110
 
89
111
  * Copyright(c) 2021- Hiroshi Hatake
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.join(__dir__, 'lib'))
3
+ require 'fluent/command/config_generator'
4
+
5
+ CalyptiaConfigGenerator.new.call
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-calyptia-monitoring"
6
- spec.version = "0.1.0.rc6"
6
+ spec.version = "0.1.0.rc7"
7
7
  spec.authors = ["Hiroshi Hatake"]
8
8
  spec.email = ["hatake@calyptia.com"]
9
9
 
@@ -0,0 +1,136 @@
1
+ #
2
+ # fluent-plugin-calyptia-monitoring
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require "erb"
17
+ require "optparse"
18
+ require "pathname"
19
+ require "fluent/plugin"
20
+ require "fluent/env"
21
+ require "fluent/engine"
22
+ require "fluent/system_config"
23
+ require "fluent/config/element"
24
+ require 'fluent/version'
25
+
26
+ class CalyptiaConfigGenerator
27
+ def initialize(argv = ARGV)
28
+ @argv = argv
29
+ @api_key = nil
30
+ @endpoint = nil
31
+ @enable_input_metrics = true
32
+ @enable_size_metrics = false
33
+ @enable_get_dump = true
34
+ @rpc_endpoint = "127.0.0.1:24444"
35
+ @storage_agent_token_dir = default_storage_dir
36
+
37
+ prepare_option_parser
38
+ end
39
+
40
+ def default_storage_dir
41
+ if Fluent.windows?
42
+ "C:/path/to/accesible/dir"
43
+ else
44
+ "/path/to/accesible/dir"
45
+ end
46
+ end
47
+
48
+ def call
49
+ parse_options!
50
+
51
+ puts dump_configuration_for_calyptia
52
+ end
53
+
54
+ def dump_configuration_for_calyptia
55
+ dumped = ""
56
+ template = template_path("calyptia-conf.erb").read
57
+
58
+ dumped <<
59
+ if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
60
+ ERB.new(template, trim_mode: "-")
61
+ else
62
+ ERB.new(template, nil, "-")
63
+ end.result(binding)
64
+ dumped
65
+ end
66
+ private
67
+
68
+ def prepare_option_parser
69
+ @parser = OptionParser.new
70
+ @parser.version = Fluent::VERSION
71
+ @parser.banner = <<BANNER
72
+ Usage: #{$0} api_key [options]
73
+
74
+ Output plugin config definitions
75
+
76
+ Arguments:
77
+ \tapi_key: Specify your API_KEY
78
+
79
+ Options:
80
+ BANNER
81
+ @parser.on("--endpoint URL", "API Endpoint URL (default: nil, and if omitted, using default endpoint)") do |s|
82
+ @endpoint = s
83
+ end
84
+ @parser.on("--rpc-endpoint URL", "Specify RPC Endpoint URL (default: 127.0.0.1:24444)") do |s|
85
+ @rpc_endpoint = s
86
+ end
87
+ @parser.on("--disable-input-metrics", "Disable Input plugin metrics. Input metrics is enabled by default") do
88
+ @enable_input_metrics = false
89
+ end
90
+ @parser.on("--enable-size-metrics", "Enable event size metrics. Size metrics is disabled by default.") do
91
+ @enable_size_metrics = true
92
+ end
93
+ @parser.on("--disable-get-dump", "Disable RPC getDump procedure. getDump is enabled by default.") do
94
+ @enable_get_dump = false
95
+ end
96
+ @parser.on("--storage-agent-token-dir DIR", "Specify accesible storage token dir. (default: #{default_storage_dir})") do |s|
97
+ @storage_agent_token_dir = s
98
+ end
99
+ end
100
+
101
+ def usage(message = nil)
102
+ puts @parser.to_s
103
+ puts
104
+ puts "Error: #{message}" if message
105
+ exit(false)
106
+ end
107
+
108
+ def parse_options!
109
+ @parser.parse!(@argv)
110
+
111
+ raise "Must specify api_key" unless @argv.size == 1
112
+
113
+ host, port = @rpc_endpoint.split(':')
114
+ if @enable_get_dump && (!host || !port)
115
+ puts "Error: invalid rpc_endpoint format. Specify `host:port' form."
116
+ exit(false)
117
+ end
118
+
119
+ @api_key, = @argv
120
+ @options = {
121
+ api_key: @api_key,
122
+ endpoint: @endpoint,
123
+ rpc_endpoint: @rpc_endpoint,
124
+ input_metrics: @enable_input_metrics,
125
+ size_metrics: @enable_size_metrics,
126
+ enable_get_dump: @enable_get_dump,
127
+ storage_agent_token_dir: @storage_agent_token_dir,
128
+ }
129
+ rescue => e
130
+ usage(e)
131
+ end
132
+
133
+ def template_path(name)
134
+ (Pathname(__dir__) + "../../../templates/#{name}").realpath
135
+ end
136
+ end
@@ -56,8 +56,7 @@ module Fluent::Plugin
56
56
  @log.info "MachineID is not retrived from ioreg. Using UUID instead."
57
57
  "#{SecureRandom.uuid}:#{@worker_id}"
58
58
  else
59
- # TODO: The prefix should be removed?
60
- "#{SecureRandom.hex(10)}_#{o.strip}:#{@worker_id}"
59
+ "#{o.strip}:#{@worker_id}"
61
60
  end
62
61
  end
63
62
 
@@ -72,8 +71,7 @@ module Fluent::Plugin
72
71
  @log.info "MachineID is not retrived from #{DBUS_MACHINE_ID_PATH} or #{ETC_MACHINE_ID_PATH}. Using UUID instead."
73
72
  "#{SecureRandom.uuid}:#{@worker_id}"
74
73
  else
75
- # TODO: The prefix should be removed?
76
- "#{SecureRandom.hex(10)}_#{machine_id}:#{@worker_id}"
74
+ "#{machine_id}:#{@worker_id}"
77
75
  end
78
76
  end
79
77
 
@@ -88,8 +86,7 @@ module Fluent::Plugin
88
86
  @log.info "MachineID is not retrived from Registry. Using UUID instead."
89
87
  "#{SecureRandom.uuid}:#{@worker_id}"
90
88
  else
91
- # TODO: The prefix should be removed?
92
- "#{SecureRandom.hex(10)}_#{machine_id}:#{@worker_id}"
89
+ "#{machine_id}:#{@worker_id}"
93
90
  end
94
91
  end
95
92
  end
@@ -114,7 +114,7 @@ module Fluent
114
114
 
115
115
  def create_agent(current_config)
116
116
  code, agent, machine_id = @api_requester.create_agent(current_config)
117
- if agent["error"].nil?
117
+ if code.to_s.start_with?("2")
118
118
  @storage_agent.put(:agent, agent)
119
119
  @storage_agent.put(:machine_id, machine_id)
120
120
  return true
@@ -0,0 +1,23 @@
1
+ <system>
2
+ <metrics>
3
+ @type cmetrics
4
+ </metrics>
5
+ enable_input_metrics <%= @enable_input_metrics %>
6
+ enable_size_metrics <%= @enable_size_metrics %>
7
+ rpc_endpoint <%= @rpc_endpoint %>
8
+ enable_get_dump <%= @enable_get_dump %>
9
+ <system>
10
+ <source>
11
+ @type calyptia_monitoring
12
+ @id input_caplyptia_monitoring
13
+ <cloud_monitoring>
14
+ <%- if @endpoint -%>
15
+ endpoint <%= @endpoint %>
16
+ <%- end -%>
17
+ api_key <%= @api_key %>
18
+ </cloud_monitoring>
19
+ <storage>
20
+ @type local
21
+ path <%= @storage_agent_token_dir %>/agent_state
22
+ </storage>
23
+ </source>
@@ -0,0 +1,199 @@
1
+ require 'helper'
2
+ require 'tmpdir'
3
+ require 'fluent/command/config_generator'
4
+
5
+ class TestCalyptiaConfigGenerator < Test::Unit::TestCase
6
+ def stringio_stdout
7
+ out = StringIO.new
8
+ $stdout = out
9
+ yield
10
+ out.string.force_encoding('utf-8')
11
+ ensure
12
+ $stdout = STDOUT
13
+ end
14
+
15
+ def default_storage_dir
16
+ if Fluent.windows?
17
+ "C:/path/to/accesible/dir"
18
+ else
19
+ "/path/to/accesible/dir"
20
+ end
21
+ end
22
+
23
+ sub_test_case "generate configuration" do
24
+ test "with only api_key" do
25
+ dumped_config = capture_stdout do
26
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY"]).call
27
+ end
28
+ expected =<<TEXT
29
+ <system>
30
+ <metrics>
31
+ @type cmetrics
32
+ </metrics>
33
+ enable_input_metrics true
34
+ enable_size_metrics false
35
+ rpc_endpoint 127.0.0.1:24444
36
+ enable_get_dump true
37
+ <system>
38
+ <source>
39
+ @type calyptia_monitoring
40
+ @id input_caplyptia_monitoring
41
+ <cloud_monitoring>
42
+ api_key YOUR_API_KEY
43
+ </cloud_monitoring>
44
+ <storage>
45
+ @type local
46
+ path #{default_storage_dir}/agent_state
47
+ </storage>
48
+ </source>
49
+ TEXT
50
+ assert_equal(expected, dumped_config)
51
+ end
52
+
53
+ test "with api_key and enable_input_metrics" do
54
+ dumped_config = capture_stdout do
55
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY", "--disable-input-metrics"]).call
56
+ end
57
+ expected =<<TEXT
58
+ <system>
59
+ <metrics>
60
+ @type cmetrics
61
+ </metrics>
62
+ enable_input_metrics false
63
+ enable_size_metrics false
64
+ rpc_endpoint 127.0.0.1:24444
65
+ enable_get_dump true
66
+ <system>
67
+ <source>
68
+ @type calyptia_monitoring
69
+ @id input_caplyptia_monitoring
70
+ <cloud_monitoring>
71
+ api_key YOUR_API_KEY
72
+ </cloud_monitoring>
73
+ <storage>
74
+ @type local
75
+ path #{default_storage_dir}/agent_state
76
+ </storage>
77
+ </source>
78
+ TEXT
79
+ assert_equal(expected, dumped_config)
80
+ end
81
+
82
+ test "with api_key and rpc-endpoint" do
83
+ dumped_config = capture_stdout do
84
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY", "--rpc-endpoint", "localhost:24445"]).call
85
+ end
86
+ expected =<<TEXT
87
+ <system>
88
+ <metrics>
89
+ @type cmetrics
90
+ </metrics>
91
+ enable_input_metrics true
92
+ enable_size_metrics false
93
+ rpc_endpoint localhost:24445
94
+ enable_get_dump true
95
+ <system>
96
+ <source>
97
+ @type calyptia_monitoring
98
+ @id input_caplyptia_monitoring
99
+ <cloud_monitoring>
100
+ api_key YOUR_API_KEY
101
+ </cloud_monitoring>
102
+ <storage>
103
+ @type local
104
+ path #{default_storage_dir}/agent_state
105
+ </storage>
106
+ </source>
107
+ TEXT
108
+ assert_equal(expected, dumped_config)
109
+ end
110
+
111
+ test "with api_key and enable_size_metrics" do
112
+ dumped_config = capture_stdout do
113
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY", "--enable-size-metrics"]).call
114
+ end
115
+ expected =<<TEXT
116
+ <system>
117
+ <metrics>
118
+ @type cmetrics
119
+ </metrics>
120
+ enable_input_metrics true
121
+ enable_size_metrics true
122
+ rpc_endpoint 127.0.0.1:24444
123
+ enable_get_dump true
124
+ <system>
125
+ <source>
126
+ @type calyptia_monitoring
127
+ @id input_caplyptia_monitoring
128
+ <cloud_monitoring>
129
+ api_key YOUR_API_KEY
130
+ </cloud_monitoring>
131
+ <storage>
132
+ @type local
133
+ path #{default_storage_dir}/agent_state
134
+ </storage>
135
+ </source>
136
+ TEXT
137
+ assert_equal(expected, dumped_config)
138
+ end
139
+
140
+ test "with api_key and disable_get_dump" do
141
+ dumped_config = capture_stdout do
142
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY", "--disable-get-dump"]).call
143
+ end
144
+ expected =<<TEXT
145
+ <system>
146
+ <metrics>
147
+ @type cmetrics
148
+ </metrics>
149
+ enable_input_metrics true
150
+ enable_size_metrics false
151
+ rpc_endpoint 127.0.0.1:24444
152
+ enable_get_dump false
153
+ <system>
154
+ <source>
155
+ @type calyptia_monitoring
156
+ @id input_caplyptia_monitoring
157
+ <cloud_monitoring>
158
+ api_key YOUR_API_KEY
159
+ </cloud_monitoring>
160
+ <storage>
161
+ @type local
162
+ path #{default_storage_dir}/agent_state
163
+ </storage>
164
+ </source>
165
+ TEXT
166
+ assert_equal(expected, dumped_config)
167
+ end
168
+
169
+ test "with api_key and storage_agent_token_dir" do
170
+ storage_dir = Dir.tmpdir
171
+ dumped_config = capture_stdout do
172
+ CalyptiaConfigGenerator.new(["YOUR_API_KEY", "--storage_agent_token_dir", storage_dir]).call
173
+ end
174
+ expected =<<TEXT
175
+ <system>
176
+ <metrics>
177
+ @type cmetrics
178
+ </metrics>
179
+ enable_input_metrics true
180
+ enable_size_metrics false
181
+ rpc_endpoint 127.0.0.1:24444
182
+ enable_get_dump true
183
+ <system>
184
+ <source>
185
+ @type calyptia_monitoring
186
+ @id input_caplyptia_monitoring
187
+ <cloud_monitoring>
188
+ api_key YOUR_API_KEY
189
+ </cloud_monitoring>
190
+ <storage>
191
+ @type local
192
+ path #{storage_dir}/agent_state
193
+ </storage>
194
+ </source>
195
+ TEXT
196
+ assert_equal(expected, dumped_config)
197
+ end
198
+ end
199
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-calyptia-monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc6
4
+ version: 0.1.0.rc7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-02 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,8 @@ dependencies:
89
89
  description: Monitoring Fluentd via Calyptia Cloud
90
90
  email:
91
91
  - hatake@calyptia.com
92
- executables: []
92
+ executables:
93
+ - calyptia-config-generator
93
94
  extensions: []
94
95
  extra_rdoc_files: []
95
96
  files:
@@ -98,11 +99,15 @@ files:
98
99
  - LICENSE
99
100
  - README.md
100
101
  - Rakefile
102
+ - bin/calyptia-config-generator
101
103
  - fluent-plugin-calyptia-monitoring.gemspec
104
+ - lib/fluent/command/config_generator.rb
102
105
  - lib/fluent/plugin/calyptia_monitoring_calyptia_api_requester.rb
103
106
  - lib/fluent/plugin/calyptia_monitoring_ext.rb
104
107
  - lib/fluent/plugin/calyptia_monitoring_machine_id.rb
105
108
  - lib/fluent/plugin/in_calyptia_monitoring.rb
109
+ - templates/calyptia-conf.erb
110
+ - test/command/test_config_generator.rb
106
111
  - test/helper.rb
107
112
  - test/plugin/test_calyptia_montoring_machine_id.rb
108
113
  - test/plugin/test_in_calyptia_monitoring.rb
@@ -110,7 +115,7 @@ homepage: https://github.com/calyptia/fluent-plugin-calyptia-monitoring
110
115
  licenses:
111
116
  - Apache-2.0
112
117
  metadata: {}
113
- post_install_message:
118
+ post_install_message:
114
119
  rdoc_options: []
115
120
  require_paths:
116
121
  - lib
@@ -125,11 +130,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
130
  - !ruby/object:Gem::Version
126
131
  version: 1.3.1
127
132
  requirements: []
128
- rubygems_version: 3.2.22
129
- signing_key:
133
+ rubygems_version: 3.2.15
134
+ signing_key:
130
135
  specification_version: 4
131
136
  summary: Monitoring Fluentd via Calyptia Cloud
132
137
  test_files:
138
+ - test/command/test_config_generator.rb
133
139
  - test/helper.rb
134
140
  - test/plugin/test_calyptia_montoring_machine_id.rb
135
141
  - test/plugin/test_in_calyptia_monitoring.rb