fluent-plugin-systemd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/Dockerfile +21 -0
- data/Gemfile +3 -0
- data/LICENCE +25 -0
- data/README.md +73 -0
- data/Rakefile +27 -0
- data/fluent-plugin-systemd.gemspec +29 -0
- data/lib/fluent/plugin/in_systemd.rb +62 -0
- data/lib/fluent/plugin/systemd/pos_writer.rb +58 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 473961511b5ecf9533e4e5276317fcd91553a9b4
|
4
|
+
data.tar.gz: b340367404c3b3851dcdb720320fb0e2442a6166
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba42443dc10da1c1824a73395be4dc82dca01a45eb7a60e8d7455d6fb837b9d491c2c5dcf4c95683c5dadfbe4881e8539812d450aa960ed1ec33f4074c184bc5
|
7
|
+
data.tar.gz: b1ccb5cb033c495200a500a029e8ad72ab45413d0a4c112c7d7916789fa4e2c80634f4474999f70451288ca08cb5b4cebf648ea0b5f06569b5a1c217c81ede0d
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
FROM quay.io/assemblyline/buildpack_deps:15.10
|
2
|
+
|
3
|
+
RUN echo "deb http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu vivid main" | tee /etc/apt/sources.list.d/ruby-ng.list \
|
4
|
+
&& echo "deb-src http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu vivid main" | tee -a /etc/apt/sources.list.d/ruby-ng.list \
|
5
|
+
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C3173AA6 \
|
6
|
+
&& apt-get update -q && apt-get install -qy --no-install-recommends \
|
7
|
+
ruby2.2 \
|
8
|
+
ruby2.2-dev \
|
9
|
+
libsystemd-dev \
|
10
|
+
&& apt-get clean \
|
11
|
+
&& rm -rf /var/lib/apt/lists/* \
|
12
|
+
&& truncate -s 0 /var/log/*log \
|
13
|
+
&& gem install bundler
|
14
|
+
|
15
|
+
WORKDIR /usr/local/src
|
16
|
+
|
17
|
+
COPY Gemfile ./
|
18
|
+
COPY fluent-plugin-systemd.gemspec ./
|
19
|
+
RUN bundle install -j4 -r3
|
20
|
+
COPY . .
|
21
|
+
RUN bundle exec rake
|
data/Gemfile
ADDED
data/LICENCE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2015 Edward Robinson
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# systemd input plugin for [Fluentd](http://github.com/fluent/fluentd)
|
2
|
+
|
3
|
+
[<img src="https://travis-ci.org/reevoo/fluent-plugin-systemd.svg?branch=master"
|
4
|
+
alt="Build Status" />](https://travis-ci.org/reevoo/fluent-plugin-systemd) [<img
|
5
|
+
src="https://codeclimate.com/github/reevoo/fluent-plugin-systemd/badges/gpa.svg"
|
6
|
+
/>](https://codeclimate.com/github/reevoo/fluent-plugin-systemd)
|
7
|
+
|
8
|
+
## Overview
|
9
|
+
|
10
|
+
**systemd** input plugin reads logs from the systemd journal
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Simply use RubyGems:
|
15
|
+
|
16
|
+
gem install fluent-plugin-systemd
|
17
|
+
|
18
|
+
or
|
19
|
+
|
20
|
+
fluent-gem install fluent-plugin-systemd
|
21
|
+
|
22
|
+
or
|
23
|
+
|
24
|
+
td-agent-gem install fluent-plugin-systemd
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
|
28
|
+
<source>
|
29
|
+
type systemd
|
30
|
+
path /var/log/journal
|
31
|
+
filters [{ "_SYSTEMD_UNIT": "kube-proxy.service" }]
|
32
|
+
pos_file kube-proxy.pos
|
33
|
+
tag kube-proxy
|
34
|
+
read_from_head true
|
35
|
+
</source>
|
36
|
+
|
37
|
+
**path**
|
38
|
+
|
39
|
+
Path to the systemd journal, defaults to `/var/log/journal`
|
40
|
+
|
41
|
+
**filters**
|
42
|
+
|
43
|
+
Array of filters, see [here](http://www.rubydoc.info/gems/systemd-journal/Systemd%2FJournal%2FFilterable%3Afilter) for futher
|
44
|
+
documentation, defaults to no filtering.
|
45
|
+
|
46
|
+
**pos file**
|
47
|
+
|
48
|
+
Path to pos file, stores the journald cursor. File is created if does not exist.
|
49
|
+
|
50
|
+
**read_from_head**
|
51
|
+
|
52
|
+
If true reads all avalible journal from head, otherwise starts reading from tail,
|
53
|
+
ignored if pos file exists. Defaults to false.
|
54
|
+
|
55
|
+
**tag**
|
56
|
+
|
57
|
+
Required the tag for events generated by this input plugin.
|
58
|
+
|
59
|
+
## Dependencies
|
60
|
+
|
61
|
+
This plugin depends on libsystemd
|
62
|
+
|
63
|
+
## Running the tests
|
64
|
+
|
65
|
+
To run the tests simply run `rake test`
|
66
|
+
|
67
|
+
For systems without systemd the tests are run in a docker container. So you will need docker or systemd installed to work on this.
|
68
|
+
|
69
|
+
## Licence etc
|
70
|
+
|
71
|
+
[MIT](LICENCE)
|
72
|
+
|
73
|
+
Issues and pull requests welcome
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'reevoocop/rake_task'
|
4
|
+
|
5
|
+
ReevooCop::RakeTask.new(:reevoocop)
|
6
|
+
|
7
|
+
Rake::TestTask.new(:tests) do |t|
|
8
|
+
t.test_files = Dir['test/**/test_*.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: :test
|
12
|
+
task build: :test
|
13
|
+
task tests: :reevoocop
|
14
|
+
|
15
|
+
namespace :docker do
|
16
|
+
task :test do
|
17
|
+
sh 'docker build .'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task :test do
|
22
|
+
if system('which journalctl')
|
23
|
+
Rake::Task['tests'].invoke
|
24
|
+
else
|
25
|
+
Rake::Task['docker:test'].invoke
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fluent-plugin-systemd'
|
8
|
+
spec.version = '0.0.1'
|
9
|
+
spec.authors = ['Ed Robinson']
|
10
|
+
spec.email = ['ed@reevoo.com']
|
11
|
+
|
12
|
+
spec.summary = 'Input plugin to read from systemd journal.'
|
13
|
+
spec.description = 'This is a fluentd input plugin. It reads logs from the systemd journal.'
|
14
|
+
spec.homepage = 'https://github.com/assemblyline/fluent-plugin-systemd'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
|
19
|
+
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
24
|
+
spec.add_development_dependency 'test-unit', '~> 3.1'
|
25
|
+
spec.add_development_dependency 'reevoocop'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'fluentd', '~> 0.12'
|
28
|
+
spec.add_runtime_dependency 'systemd-journal', '~> 1.2'
|
29
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'systemd/journal'
|
2
|
+
require 'fluent/plugin/systemd/pos_writer'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
class SystemdInput < Input
|
6
|
+
Fluent::Plugin.register_input('systemd', self)
|
7
|
+
|
8
|
+
config_param :path, :string, default: '/var/log/journal'
|
9
|
+
config_param :filters, :array, default: []
|
10
|
+
config_param :pos_file, :string, default: nil
|
11
|
+
config_param :read_from_head, :bool, default: false
|
12
|
+
config_param :tag, :string
|
13
|
+
|
14
|
+
attr_reader :tag
|
15
|
+
|
16
|
+
def configure(conf)
|
17
|
+
super
|
18
|
+
@pos_writer = PosWriter.new(conf['pos_file'])
|
19
|
+
@journal = Systemd::Journal.new(path: path)
|
20
|
+
journal.filter(*filters)
|
21
|
+
read_from = @pos_writer.cursor || (conf['read_from_head'] ? :head : :tail)
|
22
|
+
journal.seek(read_from)
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
super
|
27
|
+
@running = true
|
28
|
+
pos_writer.start
|
29
|
+
@thread = Thread.new(&method(:run))
|
30
|
+
end
|
31
|
+
|
32
|
+
def shutdown
|
33
|
+
@running = false
|
34
|
+
@thread.join
|
35
|
+
pos_writer.shutdown
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :journal, :running, :lock, :cursor, :path, :pos_writer
|
41
|
+
|
42
|
+
def run
|
43
|
+
watch do |entry|
|
44
|
+
router.emit(tag, entry.realtime_timestamp.to_i, formatted(entry))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def formatted(entry)
|
49
|
+
entry.to_h
|
50
|
+
end
|
51
|
+
|
52
|
+
def watch
|
53
|
+
while running
|
54
|
+
next unless journal.wait(1_000_000)
|
55
|
+
while journal.move_next && running
|
56
|
+
yield journal.current_entry
|
57
|
+
pos_writer.update(journal.cursor)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Fluent
|
2
|
+
class SystemdInput < Input
|
3
|
+
class PosWriter
|
4
|
+
def initialize(pos_file)
|
5
|
+
@path = pos_file
|
6
|
+
setup
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :cursor
|
10
|
+
|
11
|
+
def start
|
12
|
+
return unless path
|
13
|
+
@running = true
|
14
|
+
@thread = Thread.new(&method(:work))
|
15
|
+
end
|
16
|
+
|
17
|
+
def shutdown
|
18
|
+
return unless path
|
19
|
+
@running = false
|
20
|
+
thread.join
|
21
|
+
write_pos
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(c)
|
25
|
+
return unless path
|
26
|
+
lock.synchronize { @cursor = c }
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :path, :lock, :thread, :running
|
32
|
+
|
33
|
+
def setup
|
34
|
+
return unless path
|
35
|
+
@lock = Mutex.new
|
36
|
+
@cursor = IO.read(path).chomp if File.exist?(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def work
|
40
|
+
while running
|
41
|
+
write_pos
|
42
|
+
sleep 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_pos
|
47
|
+
lock.synchronize do
|
48
|
+
if @written_cursor != cursor
|
49
|
+
file = File.open(path, 'w+')
|
50
|
+
file.print cursor
|
51
|
+
file.close
|
52
|
+
@written_cursor = cursor
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-systemd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Robinson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: reevoocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fluentd
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: systemd-journal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
97
|
+
description: This is a fluentd input plugin. It reads logs from the systemd journal.
|
98
|
+
email:
|
99
|
+
- ed@reevoo.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Dockerfile
|
107
|
+
- Gemfile
|
108
|
+
- LICENCE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- fluent-plugin-systemd.gemspec
|
112
|
+
- lib/fluent/plugin/in_systemd.rb
|
113
|
+
- lib/fluent/plugin/systemd/pos_writer.rb
|
114
|
+
homepage: https://github.com/assemblyline/fluent-plugin-systemd
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.2.3
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Input plugin to read from systemd journal.
|
138
|
+
test_files: []
|