fluent-plugin-cmetrics 0.1.0.rc2 → 0.1.0.rc6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65548cae758782bc23022e7078dbab4a7c566b6175a652e7c5cee348a3b1ef93
|
4
|
+
data.tar.gz: e5fe401babbfe22ac5038130dd72d29135a794c155e4a294c59fbc4b5898dd41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6991cae004f796934cd0b4dd7d5d1ef9f175798c7c799ac0c417860451b6c4c04deb2d9c9fb0776a20eae180f826854b8c089b31ea79cdc2ea1ced376defe1a1
|
7
|
+
data.tar.gz: 28fd06e6a2df8d259aab80eff36a27cc2bd3a2155e47c45170c6d5704c24882d42226d3ff1f8f55fd8e6a73c1825adb45d1e05d46cffae0bea56e7b1097edd51
|
data/README.md
CHANGED
@@ -32,22 +32,69 @@ $ bundle
|
|
32
32
|
|
33
33
|
## Fluent::Plugin::CMetricsParserFilter
|
34
34
|
|
35
|
-
###
|
35
|
+
### cmetrics_metric_key (string) (optional)
|
36
36
|
|
37
37
|
cmetrics metric key
|
38
38
|
|
39
39
|
Default value: `cmetrics`.
|
40
40
|
|
41
|
-
###
|
41
|
+
### cmetrics_labels_key (string) (optional)
|
42
42
|
|
43
43
|
cmetrics labels key
|
44
44
|
|
45
45
|
Default value: `labels`.
|
46
46
|
|
47
|
-
###
|
47
|
+
### host_key (string) (optional)
|
48
48
|
|
49
|
-
|
49
|
+
hostname key
|
50
50
|
|
51
|
+
Default value: `host`.
|
52
|
+
|
53
|
+
### format_to_splunk_metric (bool) (optional)
|
54
|
+
|
55
|
+
format to Splunk metrics
|
56
|
+
|
57
|
+
### dimensions_key (string) (optional)
|
58
|
+
|
59
|
+
dimensions key
|
60
|
+
|
61
|
+
## Fluent::Plugin::CMetricsSplunkMetricPayloadFormatter
|
62
|
+
|
63
|
+
### cmetrics_name_key (string) (optional)
|
64
|
+
|
65
|
+
cmetrics metrics name key
|
66
|
+
|
67
|
+
Default value: `name`.
|
68
|
+
|
69
|
+
### cmetrics_value_key (string) (optional)
|
70
|
+
|
71
|
+
cmetrics metrics value key
|
72
|
+
|
73
|
+
Default value: `value`.
|
74
|
+
|
75
|
+
### cmetrics_dims_key (string) (optional)
|
76
|
+
|
77
|
+
cmetrics metrics dimensions key
|
78
|
+
|
79
|
+
Default value: `dims`.
|
80
|
+
|
81
|
+
### host_key (string) (optional)
|
82
|
+
|
83
|
+
Specify host key
|
84
|
+
|
85
|
+
Default value: `host`.
|
86
|
+
|
87
|
+
### index (string) (optional)
|
88
|
+
|
89
|
+
Specify splunk index name
|
90
|
+
|
91
|
+
### source (string) (optional)
|
92
|
+
|
93
|
+
Specify splunk source name
|
94
|
+
|
95
|
+
### sourcetype (string) (optional)
|
96
|
+
|
97
|
+
Specify splunk sourcetype name
|
51
98
|
|
52
99
|
## Copyright
|
53
100
|
|
@@ -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.
|
6
|
+
spec.version = "0.1.0.rc6"
|
7
7
|
spec.authors = ["Hiroshi Hatake"]
|
8
8
|
spec.email = ["cosmo0920.oucc@gmail.com"]
|
9
9
|
|
@@ -30,43 +30,55 @@ 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 "
|
34
|
-
config_param :
|
33
|
+
desc "hostname key"
|
34
|
+
config_param :host_key, :string, default: "host"
|
35
|
+
desc "format to Splunk metrics"
|
36
|
+
config_param :format_to_splunk_metric, :bool, default: false
|
37
|
+
desc "dimensions key"
|
38
|
+
config_param :dimensions_key, :string, default: nil
|
35
39
|
|
36
40
|
def configure(conf)
|
37
41
|
super
|
38
42
|
@serde = ::CMetrics::Serde.new
|
39
43
|
@record_accessor = record_accessor_create(@cmetrics_metric_key)
|
40
44
|
@labels_accessor = record_accessor_create(@cmetrics_labels_key)
|
45
|
+
@hostname_accessor = record_accessor_create(@host_key)
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
48
|
+
def format_to_splunk_style_with_dims(inner)
|
44
49
|
subsystem = inner.delete("subsystem")
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}.join("_")
|
53
|
-
end
|
50
|
+
# labels will be treated as dimensions.
|
51
|
+
dimensions = Hash.new(0)
|
52
|
+
if labels = @labels_accessor.call(inner)
|
53
|
+
labels.map {|k,v|
|
54
|
+
dimensions[k] = v
|
55
|
+
}
|
56
|
+
end
|
54
57
|
name = inner.delete("name")
|
55
|
-
[subsystem,
|
58
|
+
return [subsystem, name].compact.reject{|e| e.empty?}.join("."), dimensions
|
56
59
|
end
|
57
60
|
|
58
61
|
def filter_stream(tag, es)
|
59
62
|
new_es = Fluent::MultiEventStream.new
|
60
63
|
es.each do |time, record|
|
61
64
|
data = @record_accessor.call(record)
|
65
|
+
hostname = @hostname_accessor.call(record)
|
62
66
|
@serde.feed_each(data) do |cmetrics|
|
63
67
|
metrics = cmetrics.metrics
|
64
68
|
metrics.each do |metric|
|
65
69
|
next if metric.empty?
|
66
70
|
|
67
71
|
metric.each do |inner|
|
68
|
-
if @
|
69
|
-
inner["name"] =
|
72
|
+
if @format_to_splunk_metric
|
73
|
+
inner["name"], dims = format_to_splunk_style_with_dims(inner)
|
74
|
+
if @dimensions_key
|
75
|
+
inner[@dimensions_key] = dims
|
76
|
+
else
|
77
|
+
inner.merge!(dims)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
if hostname
|
81
|
+
inner[@host_key] = hostname
|
70
82
|
end
|
71
83
|
time = Time.at(inner.delete("timestamp"))
|
72
84
|
new_es.add(Fluent::EventTime.new(time.to_i, time.nsec), inner)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2021- Calyptia Inc.
|
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 "fluent/plugin/formatter"
|
17
|
+
require 'fluent/plugin_helper/record_accessor'
|
18
|
+
require 'fluent/plugin_helper'
|
19
|
+
require "fluent/event"
|
20
|
+
require "fluent/time"
|
21
|
+
require "yajl"
|
22
|
+
require "socket"
|
23
|
+
|
24
|
+
module Fluent
|
25
|
+
module Plugin
|
26
|
+
class CMetricsSplunkMetricPayloadFormatter < Fluent::Plugin::Formatter
|
27
|
+
include PluginHelper::Mixin
|
28
|
+
|
29
|
+
Fluent::Plugin.register_formatter('cmetrics_splunk_metric_payload', self)
|
30
|
+
|
31
|
+
helpers :record_accessor
|
32
|
+
|
33
|
+
desc "cmetrics metrics name key"
|
34
|
+
config_param :cmetrics_name_key, :string, default: "name"
|
35
|
+
desc "cmetrics metrics value key"
|
36
|
+
config_param :cmetrics_value_key, :string, default: "value"
|
37
|
+
desc "cmetrics metrics dimensions key"
|
38
|
+
config_param :cmetrics_dims_key, :string, default: "dims"
|
39
|
+
desc "Specify host key"
|
40
|
+
config_param :host_key, :string, default: "host"
|
41
|
+
desc "Specify splunk index name"
|
42
|
+
config_param :index, :string, default: nil
|
43
|
+
desc "Specify splunk source name"
|
44
|
+
config_param :source, :string, default: nil
|
45
|
+
desc "Specify splunk sourcetype name"
|
46
|
+
config_param :sourcetype, :string, default: nil
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
super
|
50
|
+
@default_host = Socket.gethostname
|
51
|
+
end
|
52
|
+
|
53
|
+
def configure(conf)
|
54
|
+
super
|
55
|
+
|
56
|
+
@cmetrics_name_accessor = record_accessor_create(@cmetrics_name_key)
|
57
|
+
@cmetrics_value_accessor = record_accessor_create(@cmetrics_value_key)
|
58
|
+
@cmetrics_dims_accessor = record_accessor_create(@cmetrics_dims_key)
|
59
|
+
@host_key_accessor = record_accessor_create(@host_key)
|
60
|
+
end
|
61
|
+
|
62
|
+
def format(tag, time, record)
|
63
|
+
host = if host = @host_key_accessor.call(record)
|
64
|
+
host
|
65
|
+
else
|
66
|
+
@default_host
|
67
|
+
end
|
68
|
+
payload = {
|
69
|
+
host: host,
|
70
|
+
# From the API reference
|
71
|
+
# https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTinput#services.2Fcollector
|
72
|
+
time: time.to_f.to_s,
|
73
|
+
event: 'metric',
|
74
|
+
}
|
75
|
+
payload[:index] = @index if @index
|
76
|
+
payload[:source] = @source if @source
|
77
|
+
payload[:sourcetype] = @sourcetype if @sourcetype
|
78
|
+
fields = {
|
79
|
+
"metric_name:#{@cmetrics_name_accessor.call(record)}" => @cmetrics_value_accessor.call(record)
|
80
|
+
}
|
81
|
+
if dims = @cmetrics_dims_accessor.call(record)
|
82
|
+
fields.merge!(dims)
|
83
|
+
end
|
84
|
+
payload.merge!(fields)
|
85
|
+
Yajl.dump(payload)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require "helper"
|
2
2
|
require "fluent/plugin/filter_cmetrics_parser.rb"
|
3
|
+
require 'socket'
|
3
4
|
|
4
5
|
class CmetricsParserTest < Test::Unit::TestCase
|
5
6
|
setup do
|
6
7
|
Fluent::Test.setup
|
7
8
|
end
|
8
9
|
|
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}', "
|
10
|
-
"filefd" => ['{"namespace":"node","subsystem":"filefd","name":"maximum","description":"File descriptor statistics: maximum.","value":9.223372036854776e+18}', "
|
11
|
-
"disk" => ['{"namespace":"node","subsystem":"disk","labels":{"device":"nvme0n1"},"name":"io_now","description":"The number of I/Os currently in progress.","value":0.0}', "
|
12
|
-
"network" => ['{"namespace":"node","subsystem":"network","labels":{"device":"eth0"},"name":"transmit_bytes_total","description":"Network device statistic bytes.","value":997193.0}', "
|
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)|
|
10
|
+
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"}],
|
11
|
+
"filefd" => ['{"namespace":"node","subsystem":"filefd","name":"maximum","description":"File descriptor statistics: maximum.","value":9.223372036854776e+18}', "filefd.maximum", {}],
|
12
|
+
"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"}],
|
13
|
+
"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"}],
|
14
|
+
"none" => ['{"namespace":"node","subsystem":"","name":"load5","description":"5m load average.","value":0.94}', "load5", {}])
|
15
|
+
test "#format_record_key_to_splunk_style" do |(json_str, expected_format_key, expected_dims)|
|
15
16
|
json = Yajl.load(json_str)
|
16
|
-
d = create_driver(%[
|
17
|
-
|
18
|
-
|
17
|
+
d = create_driver(%[
|
18
|
+
format_to_splunk_metric true
|
19
|
+
dimensions_key dims
|
20
|
+
])
|
21
|
+
assert_true d.instance.format_to_splunk_metric
|
22
|
+
formatted_key, dims = d.instance.format_to_splunk_style_with_dims(json)
|
23
|
+
assert_equal expected_format_key, formatted_key
|
24
|
+
assert_equal expected_dims, dims
|
19
25
|
end
|
20
26
|
|
21
27
|
sub_test_case "Actual filtering" do
|
@@ -24,13 +30,55 @@ class CmetricsParserTest < Test::Unit::TestCase
|
|
24
30
|
@binary = File.read(@binary_path)
|
25
31
|
end
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
data("with dimensions" => "dims",
|
34
|
+
"without dimensions" => nil)
|
35
|
+
test "#filter_stream" do |data|
|
36
|
+
use_dimensions = data
|
37
|
+
d = if use_dimensions
|
38
|
+
create_driver(%[
|
39
|
+
format_to_splunk_metric true
|
40
|
+
dimensions_key dims
|
41
|
+
])
|
42
|
+
else
|
43
|
+
create_driver(%[
|
44
|
+
format_to_splunk_metric true
|
45
|
+
])
|
46
|
+
end
|
29
47
|
time = event_time("2012-01-02 13:14:15")
|
30
48
|
record = {"cmetrics" => @binary}
|
31
49
|
d.run(default_tag: 'test') do
|
32
50
|
d.feed(time, record)
|
33
51
|
end
|
52
|
+
d.filtered.map {|e| assert_equal(!!use_dimensions, e.last.has_key?("dims"))}
|
53
|
+
d.filtered.map {|e| assert_false(e.last.has_key?("hostname"))}
|
54
|
+
assert do
|
55
|
+
d.filtered.size > 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
data("with dimensions" => "dims",
|
60
|
+
"without dimensions" => nil)
|
61
|
+
test "#filter_stream with host_key" do |data|
|
62
|
+
use_dimensions = data
|
63
|
+
d = if use_dimensions
|
64
|
+
create_driver(%[
|
65
|
+
format_to_splunk_metric true
|
66
|
+
dimensions_key dims
|
67
|
+
host_key hostname
|
68
|
+
])
|
69
|
+
else
|
70
|
+
create_driver(%[
|
71
|
+
format_to_splunk_metric true
|
72
|
+
host_key hostname
|
73
|
+
])
|
74
|
+
end
|
75
|
+
time = event_time("2012-01-02 13:14:15")
|
76
|
+
record = {"cmetrics" => @binary, "hostname" => Socket.gethostname}
|
77
|
+
d.run(default_tag: 'test') do
|
78
|
+
d.feed(time, record)
|
79
|
+
end
|
80
|
+
d.filtered.map {|e| assert_equal(!!use_dimensions, e.last.has_key?("dims"))}
|
81
|
+
d.filtered.map {|e| assert_true(e.last.has_key?("hostname"))}
|
34
82
|
assert do
|
35
83
|
d.filtered.size > 0
|
36
84
|
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.
|
4
|
+
version: 0.1.0.rc6
|
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-
|
11
|
+
date: 2021-09-30 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
|
+
- lib/fluent/plugin/formatter_cmetrics_splunk_metric_payload.rb
|
103
104
|
- test/fixtures/cmetrics.bin
|
104
105
|
- test/helper.rb
|
105
106
|
- test/plugin/test_filter_cmetrics_parser.rb
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: 1.3.1
|
124
125
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.2.22
|
126
127
|
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: Fluentd plugin for cmetrics format handling.
|