logstash-input-dstat 2.0.0

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: ff2dc0530d6ad438d352678607f31c72f6d4bdff
4
+ data.tar.gz: 1db52882410bf63075093d74d961c1d62fb4aa9f
5
+ SHA512:
6
+ metadata.gz: 4b0d583a077d1a21b0e01c65955b2f90dd5c1bc7d75fa2984c89516e8494bb93704cb6e399bd36d6a11765c4fd358b9b0f346c567e6f162c3d1739e0f38d4c28
7
+ data.tar.gz: f018bbb25388234e1f6968f595f99dec34a697f78973c502ed1fc52ab72b30c818fb1b36d847e7570e99c7e4a889fa8f27eed976e0c906c1533f134a36c46cd6
data/CHANGELOG.md ADDED
File without changes
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-input-dstat
2
+ Dstat input plugin.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2016 Yosuke Fujita
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash). This plugin behave like a [fluent-plugin-dstat](https://github.com/shun0102/fluent-plugin-dstat) on logsash.
4
+
5
+
6
+ ## install
7
+
8
+ - Install plugin
9
+ ```sh
10
+ bin/logstash-plugin install logstash-input-dstat
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ ```
16
+ input {
17
+ dstat {
18
+ option => "-c"
19
+ interval => 30
20
+ }
21
+ }
22
+
23
+ output {
24
+ elasticsearch {
25
+ hosts => ["localhost:9200"]
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### parameters
31
+
32
+ * option
33
+ * option for dstat
34
+ * default: empty
35
+ * interval
36
+ * interval for executing dstat (seconds)
37
+ * default: 30
38
+ * stat_hash
39
+ * set custom stat mapping
40
+ * ex.) stat_hash => {'total cpu usage' => {'usr' => 'hogehoge' 'sys' => 'fugafuga'}}
41
+
42
+ ### default stat mapping
43
+
44
+ ``` ruby
45
+ {
46
+ 'load avg' => {'1m' => 'loadavg-short', '5m' => 'loadavg-middle', '15m' => 'loadavg-long'},
47
+ 'total cpu usage' => {'usr' => 'cpu-usr', 'sys' => 'cpu-sys', 'idl' => 'cpu-idl', 'wai' => 'cpu-wai', 'hiq' => 'cpu-hiq', 'siq' => 'cpu-siq'},
48
+ 'net/total' => {'recv' => 'net-recv', 'send' => 'net-send'},
49
+ '/' => {'used' => 'disk-used', 'free' => 'disk-free'},
50
+ 'memory usage' => {'used' => 'mem-used', 'buff' => 'mem-buff', 'cach' => 'mem-cach', 'free' => 'mem-free'},
51
+ 'dsk/total' => {'read' => 'dsk-read', 'writ' => 'dsk-writ'},
52
+ 'paging' => {'in' => 'paging-in', 'out' => 'paging-out'},
53
+ 'system' => {'int' => 'sys-int', 'csw' => 'sys-csw'},
54
+ 'swap' => {'used' => 'swap-used', 'free' => 'swap-free'},
55
+ 'procs' => {'run' => 'procs-run', 'blk' => 'procs-blk', 'new' => 'procs-new'}
56
+ }
57
+ ```
58
+
59
+ ### Output
60
+
61
+ Output example of when using logstash-output-elasticsearch.
62
+
63
+
64
+ ``` json
65
+ curl -XGET localhost:9200/logstash-*/_search
66
+
67
+ {
68
+ "took": 32,
69
+ "timed_out": false,
70
+ "_shards": {
71
+ "total": 3,
72
+ "successful": 3,
73
+ "failed": 0
74
+ },
75
+ "hits": {
76
+ "total": 2,
77
+ "max_score": 3.2686834,
78
+ "hits": [
79
+ {
80
+ "_index": "logstash-2016.07.06",
81
+ "_type": "logs",
82
+ "_id": "AVW-_erHoa7OXPDibi4W",
83
+ "_score": 3.2686834,
84
+ "_source": {
85
+ "stat": "cpu-usr",
86
+ "value": "73.810",
87
+ "host": "localhost.localdomain",
88
+ "@version": "1",
89
+ "@timestamp": "2016-07-06T06:55:58.890Z"
90
+ }
91
+ },
92
+ {
93
+ "_index": "logstash-2016.07.06",
94
+ "_type": "logs",
95
+ "_id": "AVW-_hX2oa7OXPDibi4c",
96
+ "_score": 3.2686834,
97
+ "_source": {
98
+ "stat": "cpu-usr",
99
+ "value": "0.0",
100
+ "host": "localhost.localdomain",
101
+ "@version": "1",
102
+ "@timestamp": "2016-07-06T06:56:09.950Z"
103
+ }
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ ```
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "stud/interval"
5
+ require "socket"
6
+ require 'csv'
7
+
8
+ class LogStash::Inputs::Dstat < LogStash::Inputs::Base
9
+ config_name "dstat"
10
+
11
+ default :codec, "plain"
12
+
13
+ config :option, :validate => :string, :default => ""
14
+
15
+ config :interval, :validate => :number, :default => 30
16
+
17
+ config :tmpfile, :validate => :string, :default => "/tmp/logstash-dstat.csv"
18
+
19
+ config :stat_hash, :validate => :hash, :default => {
20
+ 'load avg' => {'1m' => 'loadavg-short', '5m' => 'loadavg-middle', '15m' => 'loadavg-long'},
21
+ 'total cpu usage' => {'usr' => 'cpu-usr', 'sys' => 'cpu-sys', 'idl' => 'cpu-idl', 'wai' => 'cpu-wai', 'hiq' => 'cpu-hiq', 'siq' => 'cpu-siq'},
22
+ 'net/total' => {'recv' => 'net-recv', 'send' => 'net-send'},
23
+ '/' => {'used' => 'disk-used', 'free' => 'disk-free'},
24
+ 'memory usage' => {'used' => 'mem-used', 'buff' => 'mem-buff', 'cach' => 'mem-cach', 'free' => 'mem-free'},
25
+ 'dsk/total' => {'read' => 'dsk-read', 'writ' => 'dsk-writ'},
26
+ 'paging' => {'in' => 'paging-in', 'out' => 'paging-out'},
27
+ 'system' => {'int' => 'sys-int', 'csw' => 'sys-csw'},
28
+ 'swap' => {'used' => 'swap-used', 'free' => 'swap-free'},
29
+ 'procs' => {'run' => 'procs-run', 'blk' => 'procs-blk', 'new' => 'procs-new'}
30
+ }
31
+
32
+ public
33
+ def register
34
+ @logger.info("Registering Dstat Input", :type => @type, :command => @option, :interval => @interval)
35
+ @host = Socket.gethostname
36
+ @command = 'dstat ' + option + ' --output ' + @tmpfile + ' 1 1'
37
+ end
38
+
39
+ def run(queue)
40
+ while !stop?
41
+ clear_tmpfile(@tmpfile)
42
+ lines = exec_dstat(@command, @tmpfile)
43
+ events = create_dstat_events(lines)
44
+ events.each{|event|
45
+ decorate(event)
46
+ queue << event
47
+ }
48
+ Stud.stoppable_sleep(@interval) { stop? }
49
+ end
50
+ end
51
+
52
+ def stop
53
+ end
54
+
55
+ def exec_dstat(cmd, tmpfile)
56
+ @logger.debug? && @logger.debug("Executing dstat", :command => cmd)
57
+ begin
58
+ `#{cmd}`
59
+ File.open(tmpfile) do |file|
60
+ file.read.split("\n")
61
+ end
62
+ rescue Exception => e
63
+ @logger.error("Exception while running dstat",
64
+ :command => option, :e => e, :backtrace => e.backtrace)
65
+ ensure
66
+ stop
67
+ end
68
+ end
69
+
70
+ def clear_tmpfile(file)
71
+ File.open(file,"w") do |file|
72
+ end
73
+ end
74
+
75
+ def create_dstat_events(lines)
76
+ events = []
77
+ top_columns = []
78
+ second_columns = []
79
+
80
+ lines.each_with_index do |line, line_number|
81
+ line.delete!("\"")
82
+ next if line == ""
83
+ case line_number
84
+ when 0..4
85
+ when 5
86
+ top_columns = CSV.parse_line(line)
87
+ top_columns.each_with_index do |value, i|
88
+ if value.nil? || value == ""
89
+ top_columns[i] = top_columns[i-1]
90
+ end
91
+ end
92
+ when 6
93
+ second_columns = CSV.parse_line(line)
94
+ when 7
95
+ when 8
96
+ CSV.parse_line(line).each_with_index do |value, i|
97
+ stat = resolve_stat(top_columns[i], second_columns[i])
98
+ if !stat.nil?
99
+ event = LogStash::Event.new("stat" => stat, "value" => value, "host" => @host)
100
+ events << event
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ events
107
+ end
108
+
109
+ def resolve_stat(top_column, second_column)
110
+ @stat_hash[top_column] ? @stat_hash[top_column][second_column] : nil
111
+ end
112
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-dstat'
3
+ s.version = '2.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This example input streams a string at a definable interval."
6
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["yfujita"]
8
+ s.email = 'yfujita@n2sm.net'
9
+ s.homepage = ""
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/dstat"
4
+
5
+ describe LogStash::Inputs::Dstat do
6
+
7
+ it_behaves_like "an interruptible input plugin" do
8
+ let(:config) { { "interval" => 100 } }
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-dstat
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - yfujita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-codec-plain
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.0.22
53
+ name: stud
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.22
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ name: logstash-devutils
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
76
+ email: yfujita@n2sm.net
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - CHANGELOG.md
82
+ - DEVELOPER.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - lib/logstash/inputs/dstat.rb
87
+ - logstash-input-dstat.gemspec
88
+ - spec/inputs/dstat_spec.rb
89
+ homepage: ''
90
+ licenses:
91
+ - Apache License (2.0)
92
+ metadata:
93
+ logstash_plugin: 'true'
94
+ logstash_group: input
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: This example input streams a string at a definable interval.
115
+ test_files:
116
+ - spec/inputs/dstat_spec.rb