Commit 556057d2 authored by Klaus Wölfel's avatar Klaus Wölfel

Initial Commit

parents
/.bundle/
/Gemfile.lock
source 'https://rubygems.org'
# gem's dependencies are in .gemspec
gemspec
Copyright (C) 2015 Nexedi SA and Contributors
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.
Gem::Specification.new do |gem|
gem.name = "fluent-plugin-system"
gem.version = "0.1"
gem.authors = ["Klaus Wölfel"]
gem.email = ["klaus@nexedi.com"]
gem.summary = %q{Fluentd System Monitoring Plugin}
gem.description = %q{Fluentd input plugin to monitor data of computer hardware and posix operating system}
gem.homepage = "https://lab.nexedi.com/nexedi/fluent-plugin-system"
gem.license = "APLv2"
gem.files = `git ls-files -z`.split("\x0")
gem.require_paths = ["lib"]
gem.add_runtime_dependency "fluentd", "~> 0"
# ? net/http
# ? openssl
end
# Fluentd input plugin for general hardware monitoring
# Copyright (C) 2015 Nexedi SA and Contributors.
# Klaus Wölfel <klaus@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of 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.
# sudo gem install posixpsutil
# sudo gem install net/ping
# wget http://de.archive.ubuntu.com/ubuntu/pool/universe/n/ntpstat/ntpstat_0.0.0.1-1_amd64.deb
# sudo dpkg -i ntpstat_0.0.0.1-1_amd64.deb
require 'fluent/input'
require 'net/ping'
require 'posixpsutil'
require "time"
module Fluent
class SystemInput < Input
Plugin.register_input('system', self)
config_param :disk_usage_free :bool, :default => true
config_param :virtual_memory_free :bool, :default => true
config_param :uptime, :bool, :default => true
config_param :ntp, :bool, :default => true
config_param :ping, :bool, :default => false
config_param :system_temp_max, :bool, :default => true
config_param :cpu_total_percent, :bool, :default => true
# Interval for measurements such as cpu load
config_param :interval, :integer, :default => 60
config_param :disk_usage_free_partitions :array, :default => [
{"suffix" : "root", "mountpoint" : "/"}
]
# Host to ping to
config_param :ping_host, :integer, :default => ""
# Commands for third party programs
config_param :npstat_cmd, :string, :default => "ntpstat"
config_param :sensors_cmd, :string, :default => "sensors -u"
def configure(conf)
super
end
def start
super
@running = true
@thread = Thread.new(&method(:run))
end
def shutdown
@running = false
@thread.join
end
def run
while @running
start_time = Time.now
es = MultiEventStream.new
generate(start_time) { |record|
es.add(Fluent::Engine.now, record)
}
router.emit(@tag, es)
sleep_time = @interval - (Time.now - start_time)
sleep sleep_time if sleep_time > 0
end
end
def generate(start_time)
if @disk_usage_free
for partition in @disk_usage_free_partitions
yield {"disk_usage_free_#{partition[:suffix]}" =>
get_disk_usage_free(partition[:mounpoint])
}
end
end
if @virtual_memory_free
yield {"virtual_memory_free" => get_virtual_memory_free}
end
if @system_temp_max
yield {"system_temp_max" => get_cpu_temp}
end
if @uptime
yield {"uptime" => get_uptime}
end
if @ntp
yield {"ntp" => get_ntp?}
end
if @ping
yield {"ping" => get_ping?(@ping_host)}
end
if @cpu_total_percent
interval = @interval - (Time.now - start_time)
yield {"cpu_percent" => get_cpu_total_percent(interval)}
end
end
def get_virtual_memory_free
PosixPsutil::Memory.virtual_memory.free
end
def get_disk_usage_free(partition)
PosixPsutil::Disks.disk_usage(partition).free
end
def get_uptime
(Time.now - PosixPsutil::System.boot_time).to_f
end
def get_ping?(host)
check = Net::Ping::External.new(host)
check.ping?
end
def get_ntp?
%x(#{@ntpstat_cmd})
$?.exitstatus
end
def get_system_temp_max
# see https://lab.nexedi.com/nexedi/slapos.core/blob/master/slapos/collect/temperature/__init__.py
# Get maximum sensor temperature in system
temperatures = []
for line in %x(#{@sensors_cmd}).lines
line = line.strip
if line.start_with?("temp") && line.include?("_input")
temeratures << line.split[1]
end
end
temperatures.max
end
def get_cpu_total_percent(interval)
PosixPsutil::CPU.cpu_percent(interval=interval)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment