Skip to content

Instantly share code, notes, and snippets.

@zombiezen
Created April 7, 2017 22:30
Show Gist options
  • Save zombiezen/772db615686f83a713f3bbd0db6bf551 to your computer and use it in GitHub Desktop.
Save zombiezen/772db615686f83a713f3bbd0db6bf551 to your computer and use it in GitHub Desktop.
journald to Stackdriver fluentd config
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Pipe in journal entries and send them to Stackdriver.
# Requires fluent-plugin-stdin.
# Use: `journalctl --output=json --follow --no-tail --boot`
<source>
@type stdin
tag journald
format json
</source>
<filter journald>
@type record_transformer
enable_ruby
<record>
timestampSeconds ${record["__REALTIME_TIMESTAMP"].to_i/1000000}
timestampNanos ${record["__REALTIME_TIMESTAMP"].to_i % 1000000 * 1000}
severity ${{"0" => "EMERGENCY", "1" => "ALERT", "2" => "CRITICAL", "3" => "ERROR", "4" => "WARNING", "5" => "NOTICE", "6" => "INFO", "7" => "DEBUG"}[record["PRIORITY"]]}
message ${record["MESSAGE"]}
</record>
</filter>
<filter journald>
@type record_transformer
renew_time_key timestampSeconds
remove_keys MESSAGE
</filter>
<match **>
@type google_cloud
</match>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment