Thread -> pmap (easier to use, them effect)

This commit is contained in:
root 2024-09-22 11:25:28 +02:00
parent b71aad8a3c
commit df3dc42eb9
2 changed files with 34 additions and 34 deletions

View file

@ -7,3 +7,4 @@ gem 'sd_notify'
gem 'cbor' gem 'cbor'
gem 'io-extra' gem 'io-extra'
gem 'ffi' gem 'ffi'
gem 'pmap'

View file

@ -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,8 +200,7 @@ 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|
@ -238,7 +238,6 @@ class LxcCollector
Process.wait pid Process.wait pid
end end
end end
end.each &:join
@prometheus @prometheus
end end