fluent-plugin-cmetrics 0.1.0.rc4 → 0.1.0.rc5

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: d0cb7fd9484f58d44c52df4a1420bb4ecfc3cd612e47e223bd7dd74871e477c3
4
- data.tar.gz: 0cdeabbb2069ccac75b15337f9f5141909944d5bc70ad4e6a46cecc4b6d82904
3
+ metadata.gz: 14dc765336d42503cd80ded601ff4c275a38cec0cc754b31f1f1a86d333520ac
4
+ data.tar.gz: 89cac70e738c7b3a4d65189be8a78ab9cba97210864e38e8ef47bf11aa5c7940
5
5
  SHA512:
6
- metadata.gz: 9bd6c7e03deeceae65fc856e89f8340e2c207e27aa77cf83805399d6475db7662aea8fb421c2c1314dc3cc35d2ec9f20f8d0ab2dba7c53efee6d3e06a26fd947
7
- data.tar.gz: 7349f9dd27645fbe3f8fd024bdd00e8db31c5ac728642a75bc8570157098a76827b7308e4b9526b4d3d34fbd54b81f73eb9c0f27fae3b55b65e8be1201cb359a
6
+ metadata.gz: e11f1f3c56baba25406a0294e8c84458c26f15d1070b3f9a125838e9ac536386f32b705a5cbcbbddf242234a728be397bb0f12e5dd8e72c89a09917e4799bc69
7
+ data.tar.gz: 28a10bb177b9758ac19a25abce5f04746051fb26e23842b6eef488b18c390e309ddba487656fb5df01c6975a0b34a4d5a829a1ec5add63be5f58b5fabb42ad36
data/README.md CHANGED
@@ -32,22 +32,63 @@ $ bundle
32
32
 
33
33
  ## Fluent::Plugin::CMetricsParserFilter
34
34
 
35
- ### cmetric_metric_key (string) (optional)
35
+ ### cmetrics_metric_key (string) (optional)
36
36
 
37
37
  cmetrics metric key
38
38
 
39
39
  Default value: `cmetrics`.
40
40
 
41
- ### cmetric_labels_key (string) (optional)
41
+ ### cmetrics_labels_key (string) (optional)
42
42
 
43
43
  cmetrics labels key
44
44
 
45
45
  Default value: `labels`.
46
46
 
47
- ### format_name_key_for_splunk_metric (bool) (optional)
47
+ ### format_to_splunk_metric (bool) (optional)
48
48
 
49
- format name key for Splunk metrics
49
+ format to Splunk metrics
50
50
 
51
+ ### dimensions_key (string) (optional)
52
+
53
+ dimensions key
54
+
55
+ ## Fluent::Plugin::CMetricsSplunkMetricPayloadFormatter
56
+
57
+ ### cmetrics_name_key (string) (optional)
58
+
59
+ cmetrics metrics name key
60
+
61
+ Default value: `name`.
62
+
63
+ ### cmetrics_value_key (string) (optional)
64
+
65
+ cmetrics metrics value key
66
+
67
+ Default value: `value`.
68
+
69
+ ### cmetrics_dims_key (string) (optional)
70
+
71
+ cmetrics metrics dimensions key
72
+
73
+ Default value: `dims`.
74
+
75
+ ### host_key (string) (optional)
76
+
77
+ Specify host key
78
+
79
+ Default value: `host`.
80
+
81
+ ### index (string) (optional)
82
+
83
+ Specify splunk index name
84
+
85
+ ### source (string) (optional)
86
+
87
+ Specify splunk source name
88
+
89
+ ### sourcetype (string) (optional)
90
+
91
+ Specify splunk sourcetype name
51
92
 
52
93
  ## Copyright
53
94
 
@@ -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.rc4"
6
+ spec.version = "0.1.0.rc5"
7
7
  spec.authors = ["Hiroshi Hatake"]
8
8
  spec.email = ["cosmo0920.oucc@gmail.com"]
9
9
 
@@ -30,8 +30,10 @@ module Fluent
30
30
  config_param :cmetrics_metric_key, :string, default: "cmetrics"
31
31
  desc "cmetrics labels key"
32
32
  config_param :cmetrics_labels_key, :string, default: "labels"
33
- desc "format name key for Splunk metrics"
34
- config_param :format_name_key_for_splunk_metric, :bool, default: false
33
+ desc "format to Splunk metrics"
34
+ config_param :format_to_splunk_metric, :bool, default: false
35
+ desc "dimensions key"
36
+ config_param :dimensions_key, :string, default: nil
35
37
 
36
38
  def configure(conf)
37
39
  super
@@ -40,19 +42,17 @@ module Fluent
40
42
  @labels_accessor = record_accessor_create(@cmetrics_labels_key)
41
43
  end
42
44
 
43
- def format_record_key_to_splunk_style(inner)
45
+ def format_to_splunk_style_with_dims(inner)
44
46
  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
47
+ # labels will be treated as dimensions.
48
+ dimensions = Hash.new(0)
49
+ if labels = @labels_accessor.call(inner)
50
+ labels.map {|k,v|
51
+ dimensions[k] = v
52
+ }
53
+ end
54
54
  name = inner.delete("name")
55
- [subsystem, labels_str, name].compact.reject{|e| e.empty?}.join(".")
55
+ return [subsystem, name].compact.reject{|e| e.empty?}.join("."), dimensions
56
56
  end
57
57
 
58
58
  def filter_stream(tag, es)
@@ -65,8 +65,13 @@ module Fluent
65
65
  next if metric.empty?
66
66
 
67
67
  metric.each do |inner|
68
- if @format_name_key_for_splunk_metric
69
- inner["name"] = format_record_key_to_splunk_style(inner)
68
+ if @format_to_splunk_metric
69
+ inner["name"], dims = format_to_splunk_style_with_dims(inner)
70
+ if @dimensions_key
71
+ inner[@dimensions_key] = dims
72
+ else
73
+ inner.merge!(dims)
74
+ end
70
75
  end
71
76
  time = Time.at(inner.delete("timestamp"))
72
77
  new_es.add(Fluent::EventTime.new(time.to_i, time.nsec), inner)
@@ -34,6 +34,8 @@ module Fluent
34
34
  config_param :cmetrics_name_key, :string, default: "name"
35
35
  desc "cmetrics metrics value key"
36
36
  config_param :cmetrics_value_key, :string, default: "value"
37
+ desc "cmetrics metrics dimensions key"
38
+ config_param :cmetrics_dims_key, :string, default: "dims"
37
39
  desc "Specify host key"
38
40
  config_param :host_key, :string, default: "host"
39
41
  desc "Specify splunk index name"
@@ -53,6 +55,7 @@ module Fluent
53
55
 
54
56
  @cmetrics_name_accessor = record_accessor_create(@cmetrics_name_key)
55
57
  @cmetrics_value_accessor = record_accessor_create(@cmetrics_value_key)
58
+ @cmetrics_dims_accessor = record_accessor_create(@cmetrics_dims_key)
56
59
  @host_key_accessor = record_accessor_create(@host_key)
57
60
  end
58
61
 
@@ -72,11 +75,13 @@ module Fluent
72
75
  payload[:index] = @index if @index
73
76
  payload[:source] = @source if @source
74
77
  payload[:sourcetype] = @sourcetype if @sourcetype
75
-
76
- metric_fields = {
78
+ fields = {
77
79
  "metric_name:#{@cmetrics_name_accessor.call(record)}" => @cmetrics_value_accessor.call(record)
78
80
  }
79
- payload.merge!(metric_fields)
81
+ if dims = @cmetrics_dims_accessor.call(record)
82
+ fields.merge!(dims)
83
+ end
84
+ payload.merge!(fields)
80
85
  Yajl.dump(payload)
81
86
  end
82
87
  end
@@ -6,16 +6,21 @@ class CmetricsParserTest < Test::Unit::TestCase
6
6
  Fluent::Test.setup
7
7
  end
8
8
 
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)|
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.seconds_total", {"cpu" => "10", "mode" => "system"}],
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.io_now", {"device" => "nvme0n1"}],
12
+ "network" => ['{"namespace":"node","subsystem":"network","labels":{"device":"eth0"},"name":"transmit_bytes_total","description":"Network device statistic bytes.","value":997193.0}', "network.transmit_bytes_total", {"device" => "eth0"}],
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, expected_dims)|
15
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)
16
+ d = create_driver(%[
17
+ format_to_splunk_metric true
18
+ dimensions_key dims
19
+ ])
20
+ assert_true d.instance.format_to_splunk_metric
21
+ formatted_key, dims = d.instance.format_to_splunk_style_with_dims(json)
22
+ assert_equal expected_format_key, formatted_key
23
+ assert_equal expected_dims, dims
19
24
  end
20
25
 
21
26
  sub_test_case "Actual filtering" do
@@ -24,13 +29,26 @@ class CmetricsParserTest < Test::Unit::TestCase
24
29
  @binary = File.read(@binary_path)
25
30
  end
26
31
 
27
- test "#filter_stream" do
28
- d = create_driver(%[format_name_key_for_splunk_metric true])
32
+ data("with dimensions" => "dims",
33
+ "without dimensions" => nil)
34
+ test "#filter_stream" do |data|
35
+ use_dimensions = data
36
+ d = if use_dimensions
37
+ create_driver(%[
38
+ format_to_splunk_metric true
39
+ dimensions_key dims
40
+ ])
41
+ else
42
+ create_driver(%[
43
+ format_to_splunk_metric true
44
+ ])
45
+ end
29
46
  time = event_time("2012-01-02 13:14:15")
30
47
  record = {"cmetrics" => @binary}
31
48
  d.run(default_tag: 'test') do
32
49
  d.feed(time, record)
33
50
  end
51
+ d.filtered.map {|e| assert_equal(!!use_dimensions, e.last.has_key?("dims"))}
34
52
  assert do
35
53
  d.filtered.size > 0
36
54
  end
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.rc4
4
+ version: 0.1.0.rc5
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-09-22 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler