fluent-plugin-cmetrics 0.1.0.rc → 0.1.0.rc2

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: 69a99953b806c28c73bf3e734c2419e3ce5df8974e6bdd12a93d0e0d51096ceb
4
- data.tar.gz: bfe77f7b81c5f10ce5657bd5ea24b30c29f2ebd9b62fe5d10f82988d06f2e85c
3
+ metadata.gz: aa5328239515010bccb7710e1600b97fbfadf5674140056c4fda9434b65302e5
4
+ data.tar.gz: 2d0dd9208b1a9babc353fefa5cf2ffc4ae67b24b7aa18f63e402a76287198059
5
5
  SHA512:
6
- metadata.gz: 82b2b4e6bcc4f95c02e4eabfe000f6010f8e2ee07a7b7491057e30d39fc2bb9cc85555a3f7c9da0a60a901f2faba10882694ee1c08e8bf928614140302b330a6
7
- data.tar.gz: ab04d2523a2ed3bec53859b419b0ac77d25fd27dfbc7462fa7ece07bb8b63cd0f8889cd89d027414b9713f2f3f30caad8d9a96eb3e0015cd6a324dc19b062bee
6
+ metadata.gz: 6eafe5b8ab643ab1b0f7e55d06fe7d5385321bf8689e8ed5d953f7fde04953b33acdff7a691d19be120a236253ae170a75ebef878025e291d83dfd3ce6a01d70
7
+ data.tar.gz: 5141e4794e95a066b951da679fb44f09fc61bc415ed6d960b16cb23eb2dbf2fa10692ce9aa29e2195e1ca55e63c5c9885e74aaf80d37e817594d742c6d87749b
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # fluent-plugin-cmetrics
2
2
 
3
- [Fluentd](https://fluentd.org/) parser plugin to do something.
4
-
5
- TODO: write description for you plugin.
3
+ [Fluentd](https://fluentd.org/) plugin for cmetrics format handling.
6
4
 
7
5
  ## Installation
8
6
 
@@ -26,15 +24,30 @@ And then execute:
26
24
  $ bundle
27
25
  ```
28
26
 
29
- ## Configuration
27
+ ## Plugin helpers
30
28
 
31
- You can generate configuration template:
29
+ * [record_accessor](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-record_accessor)
32
30
 
33
- ```
34
- $ fluent-plugin-config-format parser cmetrics
35
- ```
31
+ * See also: [Filter Plugin Overview](https://docs.fluentd.org/v/1.0/filter#overview)
32
+
33
+ ## Fluent::Plugin::CMetricsParserFilter
34
+
35
+ ### cmetric_metric_key (string) (optional)
36
+
37
+ cmetrics metric key
38
+
39
+ Default value: `cmetrics`.
40
+
41
+ ### cmetric_labels_key (string) (optional)
42
+
43
+ cmetrics labels key
44
+
45
+ Default value: `labels`.
46
+
47
+ ### format_name_key_for_splunk_metric (bool) (optional)
48
+
49
+ format name key for Splunk metrics
36
50
 
37
- You can copy and paste generated documents here.
38
51
 
39
52
  ## Copyright
40
53
 
@@ -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-cmetrics"
6
- spec.version = "0.1.0.rc"
6
+ spec.version = "0.1.0.rc2"
7
7
  spec.authors = ["Hiroshi Hatake"]
8
8
  spec.email = ["cosmo0920.oucc@gmail.com"]
9
9
 
@@ -27,17 +27,32 @@ module Fluent
27
27
  helpers :record_accessor
28
28
 
29
29
  desc "cmetrics metric key"
30
- config_param :cmetric_metric_key, :string, default: "cmetric"
30
+ config_param :cmetrics_metric_key, :string, default: "cmetrics"
31
31
  desc "cmetrics labels key"
32
- config_param :cmetric_labels_key, :string, default: "labels"
32
+ config_param :cmetrics_labels_key, :string, default: "labels"
33
33
  desc "format name key for Splunk metrics"
34
34
  config_param :format_name_key_for_splunk_metric, :bool, default: false
35
35
 
36
36
  def configure(conf)
37
37
  super
38
38
  @serde = ::CMetrics::Serde.new
39
- @record_accessor = record_accessor_create(@cmetric_metric_key)
40
- @labels_accessor = record_accessor_create(@cmetric_labels_key)
39
+ @record_accessor = record_accessor_create(@cmetrics_metric_key)
40
+ @labels_accessor = record_accessor_create(@cmetrics_labels_key)
41
+ end
42
+
43
+ def format_record_key_to_splunk_style(inner)
44
+ subsystem = inner.delete("subsystem")
45
+ labels_str = if labels = @labels_accessor.call(inner)
46
+ labels_str = labels.map {|k,v|
47
+ if k == "cpu"
48
+ "id_#{v}"
49
+ else
50
+ "#{k}_#{v}"
51
+ end
52
+ }.join("_")
53
+ end
54
+ name = inner.delete("name")
55
+ [subsystem, labels_str, name].compact.reject{|e| e.empty?}.join("_")
41
56
  end
42
57
 
43
58
  def filter_stream(tag, es)
@@ -50,10 +65,8 @@ module Fluent
50
65
  next if metric.empty?
51
66
 
52
67
  metric.each do |inner|
53
- if @format_name_key_for_splunk_metric && labels = @labels_accessor.call(inner)
54
- name = inner.delete("name")
55
- labels_str = labels.map {|k,v| "#{k}_#{v}"}.join("_")
56
- inner["name"] = "#{labels_str}_#{name}"
68
+ if @format_name_key_for_splunk_metric
69
+ inner["name"] = format_record_key_to_splunk_style(inner)
57
70
  end
58
71
  time = Time.at(inner.delete("timestamp"))
59
72
  new_es.add(Fluent::EventTime.new(time.to_i, time.nsec), inner)
Binary file
data/test/helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
2
  require "test-unit"
3
3
  require "fluent/test"
4
- require "fluent/test/driver/parser"
4
+ require "fluent/test/driver/filter"
5
5
  require "fluent/test/helpers"
6
6
 
7
7
  Test::Unit::TestCase.include(Fluent::Test::Helpers)
@@ -6,8 +6,35 @@ class CmetricsParserTest < Test::Unit::TestCase
6
6
  Fluent::Test.setup
7
7
  end
8
8
 
9
- test "failure" do
10
- flunk
9
+ data("cpu" => ['{"namespace":"node","subsystem":"cpu","labels":{"cpu":"10","mode":"system"},"name":"seconds_total","description":"Seconds the CPUs spent in each mode.","value":13153.09}', "cpu_id_10_mode_system_seconds_total"],
10
+ "filefd" => ['{"namespace":"node","subsystem":"filefd","name":"maximum","description":"File descriptor statistics: maximum.","value":9.223372036854776e+18}', "filefd_maximum"],
11
+ "disk" => ['{"namespace":"node","subsystem":"disk","labels":{"device":"nvme0n1"},"name":"io_now","description":"The number of I/Os currently in progress.","value":0.0}', "disk_device_nvme0n1_io_now"],
12
+ "network" => ['{"namespace":"node","subsystem":"network","labels":{"device":"eth0"},"name":"transmit_bytes_total","description":"Network device statistic bytes.","value":997193.0}', "network_device_eth0_transmit_bytes_total"],
13
+ "none" => ['{"namespace":"node","subsystem":"","name":"load5","description":"5m load average.","value":0.94}', "load5"])
14
+ test "#format_record_key_to_splunk_style" do |(json_str, expected_format_key)|
15
+ json = Yajl.load(json_str)
16
+ d = create_driver(%[format_name_key_for_splunk_metric true])
17
+ assert_true d.instance.format_name_key_for_splunk_metric
18
+ assert_equal expected_format_key, d.instance.format_record_key_to_splunk_style(json)
19
+ end
20
+
21
+ sub_test_case "Actual filtering" do
22
+ setup do
23
+ @binary_path = File.join(File.dirname(__dir__), "fixtures", "cmetrics.bin")
24
+ @binary = File.read(@binary_path)
25
+ end
26
+
27
+ test "#filter_stream" do
28
+ d = create_driver(%[format_name_key_for_splunk_metric true])
29
+ time = event_time("2012-01-02 13:14:15")
30
+ record = {"cmetrics" => @binary}
31
+ d.run(default_tag: 'test') do
32
+ d.feed(time, record)
33
+ end
34
+ assert do
35
+ d.filtered.size > 0
36
+ end
37
+ end
11
38
  end
12
39
 
13
40
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cmetrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc
4
+ version: 0.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-24 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - Rakefile
101
101
  - fluent-plugin-cmetrics.gemspec
102
102
  - lib/fluent/plugin/filter_cmetrics_parser.rb
103
+ - test/fixtures/cmetrics.bin
103
104
  - test/helper.rb
104
105
  - test/plugin/test_filter_cmetrics_parser.rb
105
106
  homepage: https://github.com/calyptia/fluent-plugin-cmetrics
@@ -121,10 +122,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: 1.3.1
123
124
  requirements: []
124
- rubygems_version: 3.2.22
125
+ rubygems_version: 3.1.4
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Fluentd plugin for cmetrics format handling.
128
129
  test_files:
130
+ - test/fixtures/cmetrics.bin
129
131
  - test/helper.rb
130
132
  - test/plugin/test_filter_cmetrics_parser.rb