Thread -> pmap (easier to use, them effect)
This commit is contained in:
parent
b71aad8a3c
commit
df3dc42eb9
1
Gemfile
1
Gemfile
|
@ -7,3 +7,4 @@ gem 'sd_notify'
|
||||||
gem 'cbor'
|
gem 'cbor'
|
||||||
gem 'io-extra'
|
gem 'io-extra'
|
||||||
gem 'ffi'
|
gem 'ffi'
|
||||||
|
gem 'pmap'
|
||||||
|
|
|
@ -4,6 +4,7 @@ require 'pathname'
|
||||||
require 'prometheus/client'
|
require 'prometheus/client'
|
||||||
require 'lxc'
|
require 'lxc'
|
||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
|
require 'pmap'
|
||||||
|
|
||||||
require_relative 'ns'
|
require_relative 'ns'
|
||||||
require_relative 'file-statfs'
|
require_relative 'file-statfs'
|
||||||
|
@ -199,46 +200,44 @@ class LxcCollector
|
||||||
@state.set CTStates[ct.state], labels: labels
|
@state.set CTStates[ct.state], labels: labels
|
||||||
end
|
end
|
||||||
|
|
||||||
LXC.running_containers.map do |ct|
|
LXC.running_containers.peach do |ct|
|
||||||
Thread.new ct do |ct|
|
pid, io = CBORIO.popen(:r) {|io| forked2 io, ct }
|
||||||
pid, io = CBORIO.popen(:r) {|io| forked2 io, ct }
|
begin
|
||||||
begin
|
io.map do |l|
|
||||||
io.map do |l|
|
case l[0].to_sym
|
||||||
case l[0].to_sym
|
|
||||||
|
|
||||||
when :mountpoint
|
when :mountpoint
|
||||||
st = OpenStruct.new l[1]
|
st = OpenStruct.new l[1]
|
||||||
labels = { id: st.id, mountpoint: st.mp }
|
labels = { id: st.id, mountpoint: st.mp }
|
||||||
@info.set 1, labels: labels.merge( name: st.name, fstype: st.fstypename)
|
@info.set 1, labels: labels.merge( name: st.name, fstype: st.fstypename)
|
||||||
@totalb.set st.bsize*st.blocks, labels: labels
|
@totalb.set st.bsize*st.blocks, labels: labels
|
||||||
@freeb.set st.bsize*st.bfree, labels: labels
|
@freeb.set st.bsize*st.bfree, labels: labels
|
||||||
@availb.set st.bsize*st.bavail, labels: labels
|
@availb.set st.bsize*st.bavail, labels: labels
|
||||||
@totalf.set st.files, labels: labels
|
@totalf.set st.files, labels: labels
|
||||||
@freef.set st.ffree, labels: labels
|
@freef.set st.ffree, labels: labels
|
||||||
|
|
||||||
when :os_release
|
when :os_release
|
||||||
osr = OpenStruct.new l[1]
|
osr = OpenStruct.new l[1]
|
||||||
@os_release.set 1, labels: {
|
@os_release.set 1, labels: {
|
||||||
id: osr.id, name: osr.name,
|
id: osr.id, name: osr.name,
|
||||||
os_id: osr.os_id,
|
os_id: osr.os_id,
|
||||||
os_name: osr.os_name,
|
os_name: osr.os_name,
|
||||||
os_pretty_name: osr.os_pretty_name,
|
os_pretty_name: osr.os_pretty_name,
|
||||||
os_version_codename: osr.os_version_codename
|
os_version_codename: osr.os_version_codename
|
||||||
}
|
}
|
||||||
@os_version.set osr.os_version_id, labels: { id: osr.id }
|
@os_version.set osr.os_version_id, labels: { id: osr.id }
|
||||||
|
|
||||||
when :pkgs
|
when :pkgs
|
||||||
as = OpenStruct.new l[1]
|
as = OpenStruct.new l[1]
|
||||||
@pkgs_last_update.set as.last_update, labels: { id: as.id }
|
@pkgs_last_update.set as.last_update, labels: { id: as.id }
|
||||||
@pkgs_upgradable.set as.upgradable, labels: { id: as.id }
|
@pkgs_upgradable.set as.upgradable, labels: { id: as.id }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
io.close
|
|
||||||
Process.wait pid
|
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
io.close
|
||||||
|
Process.wait pid
|
||||||
end
|
end
|
||||||
end.each &:join
|
end
|
||||||
@prometheus
|
@prometheus
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue