Last active
June 15, 2016 12:36
-
-
Save lafka/851a7371722b0868263cdd0eb974843a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Reports some basic LXC container stats to Riemann | |
require File.expand_path('../../lib/riemann/tools', __FILE__) | |
class Riemann::Tools::LXC | |
include Riemann::Tools | |
def initialize | |
@hostname = `hostname`.chomp | |
end | |
def tick | |
File.open("/sys/fs/cgroup/memory/lxc/" + @hostname + "/memory.stat", "r") do |file| | |
file.each_line do |stat| | |
stat = stat.split | |
send("mem #{stat[0]}", stat[1].to_i) | |
end | |
end | |
usage = File.readlines("/sys/fs/cgroup/memory/lxc/" + @hostname + "/memory.usage_in_bytes", "r")[0] | |
send("mem usage bytes", usage.to_i) | |
File.open("/sys/fs/cgroup/cpuacct/lxc/" + @hostname + "/cpuacct.stat", "r") do |file| | |
file.each_line do |stat| | |
stat = stat.split | |
send("cpu #{stat[0]}", stat[1].to_i) | |
end | |
end | |
end | |
def send(type, metric) | |
report( | |
:host => @hostname, | |
:service => "cgroup #{type}", | |
:metric => metric, | |
:state => "ok", | |
:description => nil | |
) | |
end | |
end | |
Riemann::Tools::LXC.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment