fluent-plugin-systemd 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 027149ee076af73b625bdf8dcd22dd25a7f0e833
4
- data.tar.gz: b729df398f867f111fd1a3f188eb7298437195c4
3
+ metadata.gz: 07f12e01a1d81c731f44477a051807042230adfa
4
+ data.tar.gz: 8717ea703cd39fb947af86b5773a68de5b55c040
5
5
  SHA512:
6
- metadata.gz: 979f117f454ba7a4d72ce0c62fa82fa5cae5c18be170443a4d77160c2b6f58b2f2c7de8032d6abda96b4070ef83bdb6bf94bd6746277b56984550af1157821ff
7
- data.tar.gz: 8cbcef9a6b30dee72ee515140ede68aa7317d3c9b8d338bdb76c84897d5eae0030ba810f4b840e8d902b8aab9573d58cb81314d2e5eb5b2d71eff9b4da894a60
6
+ metadata.gz: 92b3275665979af1a9d691f05acdc65a88fd88b062c6224673cde0c691c9c7a4376a1c97c96c7e1dc9cc54f224fe27e7c39600bc0b6307c88ad182e442971520
7
+ data.tar.gz: 110c2d6ff7ebeac0eb96ceaf0d470d5bdfdf5da2e4556f8b2fc98b213e08b87553d231073f2828a5050dc88437f307e2846cea0ebfd39c131465a34b83123e5e
data/README.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/reevoo/fluent-plugin-systemd.svg?branch=master)](https://travis-ci.org/reevoo/fluent-plugin-systemd) [![Code Climate GPA](https://codeclimate.com/github/reevoo/fluent-plugin-systemd/badges/gpa.svg)](https://codeclimate.com/github/reevoo/fluent-plugin-systemd) [![Gem Version](https://badge.fury.io/rb/fluent-plugin-systemd.svg)](https://rubygems.org/gems/fluent-plugin-systemd)
4
4
 
5
+ # Requirements <a name="requirements"></a>
6
+
7
+
8
+ |fluent-plugin-systemd|fluentd|td-agent|ruby|
9
+ |----|----|----|----|
10
+ | 0.2.x | >= 0.14.11, < 2 | 3 | >= 2.1 |
11
+ | 0.0.x | ~> 0.12.0 | 2 | >= 1.9 |
12
+
13
+ * The 0.1.x series is developed from this branch (master)
14
+ * The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is developed on the [0.0.x branch](https://github.com/reevoo/fluent-plugin-systemd/tree/0.0.x)
15
+
5
16
  ## Overview
6
17
 
7
18
  **systemd** input plugin reads logs from the systemd journal
@@ -10,15 +21,11 @@
10
21
 
11
22
  Simply use RubyGems:
12
23
 
13
- gem install fluent-plugin-systemd -v 0.1.0
24
+ gem install fluent-plugin-systemd -v 0.2.0
14
25
 
15
- or
26
+ or
16
27
 
17
- fluent-gem install fluent-plugin-systemd -v 0.1.0
18
-
19
- or
20
-
21
- td-agent-gem install fluent-plugin-systemd -v 0.1.0
28
+ td-agent-gem install fluent-plugin-systemd -v 0.2.0
22
29
 
23
30
  ## Configuration
24
31
 
@@ -26,37 +33,59 @@ Simply use RubyGems:
26
33
  @type systemd
27
34
  path /var/log/journal
28
35
  filters [{ "_SYSTEMD_UNIT": "kube-proxy.service" }]
29
- pos_file kube-proxy.pos
36
+ <storage>
37
+ @type local
38
+ persistent true
39
+ path kube-proxy.pos
40
+ </storage>
30
41
  tag kube-proxy
31
42
  read_from_head true
32
43
  </source>
33
44
 
34
- **path**
45
+ <match kube-proxy>
46
+ @type stdout
47
+ </match>
48
+
49
+ **`path`**
35
50
 
36
51
  Path to the systemd journal, defaults to `/var/log/journal`
37
52
 
38
- **filters**
53
+ **`filters`**
39
54
 
40
55
  Array of filters, see [here](http://www.rubydoc.info/gems/systemd-journal/Systemd%2FJournal%2FFilterable%3Afilter) for further
41
56
  documentation, defaults to no filtering.
42
57
 
43
- **pos file**
58
+ **`pos_file`**
59
+
60
+ _This parameter is deprecated and will be removed in favour of storage in v1.0._
61
+
44
62
 
45
63
  Path to pos file, stores the journald cursor. File is created if does not exist.
46
64
 
47
- **read_from_head**
65
+ **`storage`**
66
+
67
+ Configuration for a [storage plugin](http://docs.fluentd.org/v0.14/articles/storage-plugin-overview) used to store the journald cursor.
68
+
69
+ _Upgrading from `pos_file`_
70
+
71
+ If `pos_file` is specified in addition to a storage plugin with persistent set to true, the cursor will be
72
+ copied from the `pos_file` on startup, and the old `pos_file` removed.
73
+
74
+ **`read_from_head`**
48
75
 
49
76
  If true reads all available journal from head, otherwise starts reading from tail,
50
77
  ignored if pos file exists (and is valid). Defaults to false.
51
78
 
52
- **strip_underscores**
79
+ **`strip_underscores`**
53
80
 
54
81
  If true strips underscores from the beginning of systemd field names.
55
82
  May be useful if outputting to kibana, as underscore prefixed fields are unindexed there.
56
83
 
57
- **tag**
84
+ **`tag`**
85
+
86
+ _Required_
58
87
 
59
- _Required_ A tag that will be added to events generated by this input.
88
+ A tag that will be added to events generated by this input.
60
89
 
61
90
  ## Example
62
91
 
@@ -92,3 +121,4 @@ Many thanks to our fantastic contributors
92
121
  * [Richard Megginson](https://github.com/richm)
93
122
  * [Masahiro Nakagawa](https://github.com/repeatedly)
94
123
  * [Hiroshi Hatake](https://github.com/cosmo0920)
124
+ * [neko-neko](https://github.com/neko-neko)
@@ -7,40 +7,63 @@ module Fluent
7
7
  class SystemdInput < Input
8
8
  Fluent::Plugin.register_input("systemd", self)
9
9
 
10
- helpers :timer
10
+ helpers :timer, :storage
11
+
12
+ DEFAULT_STORAGE_TYPE = "local".freeze
11
13
 
12
14
  config_param :path, :string, default: "/var/log/journal"
13
15
  config_param :filters, :array, default: []
14
- config_param :pos_file, :string, default: nil
16
+ config_param :pos_file, :string, default: nil, deprecated: "Use <storage> section with `persistent: true' instead"
15
17
  config_param :read_from_head, :bool, default: false
16
18
  config_param :strip_underscores, :bool, default: false
17
19
  config_param :tag, :string
18
20
 
21
+ config_section :storage do
22
+ config_set_default :usage, "positions"
23
+ config_set_default :@type, DEFAULT_STORAGE_TYPE
24
+ config_set_default :persistent, false
25
+ end
26
+
19
27
  def configure(conf)
20
28
  super
21
- @pos_writer = PosWriter.new(@pos_file)
22
- @journal = Systemd::Journal.new(path: @path)
23
- @journal.filter(*@filters)
24
- seek
29
+ @pos_storage = PosWriter.new(@pos_file, storage_create(usage: "positions"))
30
+ @journal = nil
25
31
  end
26
32
 
27
33
  def start
28
34
  super
29
- @pos_writer.start
35
+ @pos_storage.start
30
36
  timer_execute(:in_systemd_emit_worker, 1, &method(:run))
31
37
  end
32
38
 
33
39
  def shutdown
34
- @pos_writer.shutdown
40
+ @pos_storage.shutdown
35
41
  super
36
42
  end
37
43
 
38
44
  private
39
45
 
46
+ def init_journal
47
+ @journal = Systemd::Journal.new(path: @path)
48
+ # make sure initial call to wait doesn't return :invalidate
49
+ # see https://github.com/ledbettj/systemd-journal/issues/70
50
+ @journal.wait(0)
51
+ @journal.filter(*@filters)
52
+ seek
53
+ true
54
+ rescue Systemd::JournalError => e
55
+ log.warn("#{e.class}: #{e.message} retrying in 1s")
56
+ false
57
+ end
58
+
40
59
  def seek
41
- seek_to(@pos_writer.cursor || read_from)
60
+ cursor = @pos_storage.get(:journal)
61
+ seek_to(cursor || read_from)
42
62
  rescue Systemd::JournalError
43
- log.warn("Could not seek to cursor #{@pos_writer.cursor} found in pos file: #{@pos_writer.path}")
63
+ log.warn(
64
+ "Could not seek to cursor #{cursor} found in pos file: #{@pos_storage.path}, " \
65
+ "falling back to reading from #{read_from}",
66
+ )
44
67
  seek_to(read_from)
45
68
  end
46
69
 
@@ -50,8 +73,12 @@ module Fluent
50
73
  # record
51
74
  def seek_to(pos)
52
75
  @journal.seek(pos)
53
- return unless pos == :tail
54
- @journal.move(-2)
76
+ return if pos == :head
77
+ if pos == :tail
78
+ @journal.move(-2)
79
+ else
80
+ @journal.move(1)
81
+ end
55
82
  end
56
83
 
57
84
  def read_from
@@ -59,7 +86,8 @@ module Fluent
59
86
  end
60
87
 
61
88
  def run
62
- Thread.current.abort_on_exception = true
89
+ return unless @journal || init_journal
90
+ init_journal if @journal.wait(0) == :invalidate
63
91
  watch do |entry|
64
92
  begin
65
93
  router.emit(@tag, Fluent::EventTime.from_time(entry.realtime_timestamp), formatted(entry))
@@ -77,7 +105,7 @@ module Fluent
77
105
  def watch
78
106
  while @journal.move_next
79
107
  yield @journal.current_entry
80
- @pos_writer.update(@journal.cursor)
108
+ @pos_storage.put(:journal, @journal.cursor)
81
109
  end
82
110
  end
83
111
  end
@@ -4,15 +4,27 @@ module Fluent
4
4
  module Plugin
5
5
  class SystemdInput < Input
6
6
  class PosWriter
7
- def initialize(pos_file)
7
+ def initialize(pos_file, storage)
8
8
  @path = pos_file
9
9
  @lock = Mutex.new
10
+ @storage = storage
10
11
  @cursor = nil
11
12
  @written_cursor = nil
12
13
  setup
13
14
  end
14
15
 
15
- attr_reader :cursor, :path
16
+ def get(key)
17
+ @storage ? @storage.get(key) : @cursor
18
+ end
19
+
20
+ def put(key, cursor)
21
+ return @storage.put(key, cursor) if @storage
22
+ @lock.synchronize { @cursor = cursor }
23
+ end
24
+
25
+ def path
26
+ @path || @storage.path
27
+ end
16
28
 
17
29
  def start
18
30
  return unless @path
@@ -27,16 +39,21 @@ module Fluent
27
39
  write_pos
28
40
  end
29
41
 
30
- def update(c)
31
- return unless @path
32
- @lock.synchronize { @cursor = c }
33
- end
34
-
35
42
  private
36
43
 
37
44
  def setup
38
- return unless @path && File.exist?(@path)
39
- @cursor = IO.read(@path).chomp
45
+ if @storage.persistent
46
+ migrate_to_storage if @path && File.exist?(@path)
47
+ elsif @path
48
+ @cursor = IO.read(@path).chomp if File.exist?(@path)
49
+ @storage = nil
50
+ end
51
+ end
52
+
53
+ def migrate_to_storage
54
+ @storage.put(:journal, IO.read(@path).chomp)
55
+ File.delete(@path)
56
+ @path = nil
40
57
  end
41
58
 
42
59
  def work
@@ -49,7 +66,7 @@ module Fluent
49
66
  def write_pos
50
67
  @lock.synchronize do
51
68
  if @written_cursor != @cursor
52
- file = File.open(@path, "w+")
69
+ file = File.open(@path, "w+", 0644)
53
70
  file.print @cursor
54
71
  file.close
55
72
  @written_cursor = @cursor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,17 +107,10 @@ executables: []
107
107
  extensions: []
108
108
  extra_rdoc_files: []
109
109
  files:
110
- - Gemfile
111
- - Gemfile.lock
112
110
  - LICENCE
113
111
  - README.md
114
- - Rakefile
115
- - fluent-plugin-systemd.gemspec
116
112
  - lib/fluent/plugin/in_systemd.rb
117
113
  - lib/fluent/plugin/systemd/pos_writer.rb
118
- - pkg/fluent-plugin-systemd-0.0.3.gem
119
- - pkg/fluent-plugin-systemd-0.0.4.gem
120
- - pkg/fluent-plugin-systemd-0.0.5.gem
121
114
  homepage: https://github.com/reevoo/fluent-plugin-systemd
122
115
  licenses:
123
116
  - MIT
@@ -138,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
131
  version: '0'
139
132
  requirements: []
140
133
  rubyforge_project:
141
- rubygems_version: 2.4.5.1
134
+ rubygems_version: 2.6.9
142
135
  signing_key:
143
136
  specification_version: 4
144
137
  summary: Input plugin to read from systemd journal.
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,67 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fluent-plugin-systemd (0.1.0)
5
- fluentd (>= 0.14.11, < 2)
6
- systemd-journal (~> 1.2)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- ast (2.3.0)
12
- astrolabe (1.3.1)
13
- parser (~> 2.2)
14
- cool.io (1.4.5)
15
- ffi (1.9.14)
16
- fluentd (0.14.11)
17
- cool.io (~> 1.4.5)
18
- http_parser.rb (>= 0.5.1, < 0.7.0)
19
- msgpack (>= 0.7.0, < 2.0.0)
20
- serverengine (>= 2.0.4, < 3.0.0)
21
- sigdump (~> 0.2.2)
22
- strptime (~> 0.1.7)
23
- tzinfo (~> 1.0)
24
- tzinfo-data (~> 1.0)
25
- yajl-ruby (~> 1.0)
26
- http_parser.rb (0.6.0)
27
- msgpack (1.0.2)
28
- parser (2.3.3.1)
29
- ast (~> 2.2)
30
- powerpack (0.0.9)
31
- rainbow (2.2.1)
32
- rake (10.5.0)
33
- reevoocop (0.0.9)
34
- rubocop (= 0.28.0)
35
- rubocop (0.28.0)
36
- astrolabe (~> 1.3)
37
- parser (>= 2.2.0.pre.7, < 3.0)
38
- powerpack (~> 0.0.6)
39
- rainbow (>= 1.99.1, < 3.0)
40
- ruby-progressbar (~> 1.4)
41
- ruby-progressbar (1.8.1)
42
- serverengine (2.0.4)
43
- sigdump (~> 0.2.2)
44
- sigdump (0.2.4)
45
- strptime (0.1.9)
46
- systemd-journal (1.2.3)
47
- ffi (~> 1.9)
48
- test-unit (2.5.5)
49
- thread_safe (0.3.5)
50
- tzinfo (1.2.2)
51
- thread_safe (~> 0.1)
52
- tzinfo-data (1.2016.10)
53
- tzinfo (>= 1.0.0)
54
- yajl-ruby (1.3.0)
55
-
56
- PLATFORMS
57
- ruby
58
-
59
- DEPENDENCIES
60
- bundler (~> 1.10)
61
- fluent-plugin-systemd!
62
- rake
63
- reevoocop
64
- test-unit (~> 2.5)
65
-
66
- BUNDLED WITH
67
- 1.13.2
data/Rakefile DELETED
@@ -1,31 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
- require "reevoocop/rake_task"
4
- require "fileutils"
5
-
6
- ReevooCop::RakeTask.new(:reevoocop)
7
-
8
- Rake::TestTask.new(:test) do |t|
9
- t.test_files = Dir["test/**/test_*.rb"]
10
- end
11
-
12
- task default: "docker:test"
13
- task build: "docker:test"
14
- task default: :reevoocop
15
-
16
- namespace :docker do
17
- distros = [:ubuntu, :"tdagent-ubuntu", :"tdagent-centos"]
18
- task test: distros
19
-
20
- distros.each do |distro|
21
- task distro do
22
- puts "testing on #{distro}"
23
- begin
24
- FileUtils.cp("test/docker/Dockerfile.#{distro}", "Dockerfile")
25
- sh "docker build ."
26
- ensure
27
- FileUtils.rm("Dockerfile")
28
- end
29
- end
30
- end
31
- end
@@ -1,28 +0,0 @@
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.1.0"
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/reevoo/fluent-plugin-systemd"
15
- spec.license = "MIT"
16
-
17
-
18
- spec.files = Dir["**/**"].reject { |f| f.match(/^(test|spec|features)\//) }
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "test-unit", "~> 2.5"
24
- spec.add_development_dependency "reevoocop"
25
-
26
- spec.add_runtime_dependency "fluentd", [">= 0.14.11", "< 2"]
27
- spec.add_runtime_dependency "systemd-journal", "~> 1.2"
28
- end
Binary file
Binary file
Binary file