Collect logs from libvirt.

Change-Id: I5e620e2b6d7640bd55c79f5549a94443794fc7a8
This commit is contained in:
Guillaume Thouvenin 2015-03-30 10:56:23 +02:00
parent 63036390c8
commit d01b700e48
5 changed files with 117 additions and 1 deletions

View File

@ -13,6 +13,8 @@ else {
class { 'lma_collector::logs::openstack': }
class { 'lma_collector::logs::libvirt': }
if $enable_notifications {
class { 'lma_collector::notifications::compute':
topics => $notification_topics,

View File

@ -48,7 +48,7 @@ Uuid = uuid_nodash + uuid_dash
--
-- The datetime string can be formatted as
-- 'YYYY-MM-DD( |T)HH:MM:SS(.ssssss)?(offset indicator)?'
TimestampTable = l.Ct(dt.rfc3339_full_date * (sp + l.P"T") * dt.rfc3339_partial_time * dt.rfc3339_time_offset^-1)
TimestampTable = l.Ct(dt.rfc3339_full_date * (sp + l.P"T") * dt.rfc3339_partial_time * (dt.rfc3339_time_offset + dt.timezone_offset)^-1)
-- Returns the parsed datetime converted to nanosec
Timestamp = TimestampTable / dt.time_to_ns

View File

@ -0,0 +1,64 @@
-- Copyright 2015 Mirantis, 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
--
-- http://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.
local l = require 'lpeg'
l.locale(l)
local string = require 'string'
local patt = require 'patterns'
local utils = require 'lma_utils'
local msg = {
Timestamp = nil,
Type = 'log',
Hostname = nil,
Payload = nil,
Pid = nil,
Fields = nil,
Severity = nil,
}
-- libvirt message logs are formatted like this:
--
-- 2015-03-26 17:24:52.126+0000: <PID>: <SEV> : Message
local timestamp = l.Cg(patt.Timestamp, "Timestamp")
local pid = l.Cg(patt.Pid, "Pid")
local severity = l.Cg(l.P"debug" + "info" + "warning" + "error", "Severity")
local message = l.Cg(patt.Message, "Message")
local grammar = l.Ct(timestamp * ": " * pid * ": " * severity * " : " * message)
function process_message ()
local log = read_message("Payload")
local m = grammar:match(log)
if not m then
return -1
end
m.Severity = string.upper(m.Severity)
msg.Timestamp = m.Timestamp
msg.Pid = m.Pid
msg.Payload = m.Message
msg.Severity = utils.label_to_severity_map[m.Severity]
msg.Fields = {}
msg.Fields.severity_label = m.Severity
msg.Fields.programname = 'libvirt'
utils.inject_tags(msg)
inject_message(msg)
return 0
end

View File

@ -0,0 +1,47 @@
# Class lma_collector::logs::libvirt
class lma_collector::logs::libvirt {
include lma_collector::params
include lma_collector::service
$libvirt_dir = '/var/log/libvirt'
$libvirt_log = 'libvirtd.log'
$libvirt_hooks_dir = '/etc/libvirt/hooks'
$libvirt_hook = "${libvirt_hooks_dir}/daemon"
$libvirt_service = $::osfamily ? {
'debian' => 'libvirt-bin',
default => 'libvirtd'
}
service {$libvirt_service: }
file { $libvirt_hooks_dir:
ensure => 'directory',
}
# libvirt is running as root and by default permission are restricted to
# root user. So we need to enable other users to read this file.
file { $libvirt_hook:
owner => 'root',
group => 'root',
mode => '0700',
content => template('lma_collector/hooks_daemon.erb'),
require => File[$libvirt_hooks_dir],
notify => Service[$libvirt_service],
}
heka::decoder::sandbox { 'libvirt':
config_dir => $lma_collector::params::config_dir,
filename => "${lma_collector::params::plugins_dir}/decoders/libvirt_log.lua",
}
heka::input::logstreamer { 'libvirt':
config_dir => $lma_collector::params::config_dir,
log_directory => $libvirt_dir,
file_match => $libvirt_log,
decoder => 'libvirt',
differentiator => '["libvirt"]',
require => Heka::Decoder::Sandbox['libvirt'],
notify => Class['lma_collector::service'],
}
}

View File

@ -0,0 +1,3 @@
#!/bin/bash
chmod 0644 <%= @libvirt_dir %>/<%= @libvirt_log %>