lib/heartbeat-client.rb in heartbeat-client-0.5.0 vs lib/heartbeat-client.rb in heartbeat-client-0.6.0
- old
+ new
@@ -35,10 +35,11 @@
apache_status = config['apache_status']
mongostat_arguments = config['mongostat_arguments']
keen_project_token = config['keen_project_token']
keen_api_key = config['keen_api_key']
keen_collection = config['keen_collection']
+ docker_command = config['docker_command']
if gather_metrics
procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
load_avg = []
cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
@@ -46,10 +47,11 @@
memory = {'free' => 0, 'used' => 0}
disks = {}
swap = {'free' => 0, 'used' => 0}
apache = {}
mongodb = {}
+ docker_containers = []
log.debug("Dumping top output...")
if is_linux?
`top -b -n1 > /tmp/top.out`
else
@@ -66,10 +68,15 @@
if mongostat_arguments
log.debug("Dumping mongostat output...")
`mongostat #{mongostat_arguments} > /tmp/mongodb.out`
end
+
+ if docker_command
+ log.debug("Dumping docker output...")
+ `#{docker_command} > /tmp/docker.out`
+ end
if File.exists?('/tmp/top.out')
counter = 0; proc_count = 0
File.open("/tmp/top.out", "r") do |infile|
while (line = infile.gets)
@@ -119,10 +126,21 @@
lines << line
end
mongodb_status(mongodb, lines)
end
end
+
+ if File.exists?('/tmp/docker.out')
+ File.open("/tmp/docker.out", "r") do |infile|
+ counter = 0; lines = []
+ while (line = infile.gets)
+ lines << line if counter > 0
+ counter += 1
+ end
+ docker(docker_containers, lines)
+ end
+ end
options = {
:body => {
:heartbeat => {
:client_version => version,
@@ -138,11 +156,12 @@
:processes => processes,
:memory => memory,
:disks => disks,
:swap => swap,
:apache_status => apache,
- :mongodb_status => mongodb
+ :mongodb_status => mongodb,
+ :docker_containers => docker_containers
}
}
}
}
@@ -267,9 +286,21 @@
mongodb['res'] = mo[index].strip if h == 'res'
mongodb['netIn'] = mo[index].strip if h == 'netIn'
mongodb['netOut'] = mo[index].strip if h == 'netOut'
mongodb['conn'] = mo[index].strip if h == 'conn'
end
+ end
+ end
+ end
+
+ def self.docker(docker_containers, lines)
+ if lines and lines.size > 0
+ lines.each do |line|
+ container = {}
+ parts = line.split(" ")
+ container['name'] = parts[0]
+ container['image'] = parts[1]
+ docker_containers << container
end
end
end
def self.disk_usage(disks, str)