mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Make the load_average
linux more robust by allow to inject the content of the load_average
file
Fixes: #6867 Fixes #6886
This commit is contained in:
parent
4edf17c378
commit
42166f3d52
2 changed files with 5 additions and 7 deletions
|
@ -1,4 +1,6 @@
|
|||
# encoding: utf-8
|
||||
java_import "java.lang.management.ManagementFactory"
|
||||
|
||||
module LogStash module Instrument module PeriodicPoller
|
||||
class LoadAverage
|
||||
class Windows
|
||||
|
@ -11,8 +13,8 @@ module LogStash module Instrument module PeriodicPoller
|
|||
LOAD_AVG_FILE = "/proc/loadavg"
|
||||
TOKEN_SEPARATOR = " "
|
||||
|
||||
def self.get
|
||||
load_average = ::File.read(LOAD_AVG_FILE).chomp.split(TOKEN_SEPARATOR)
|
||||
def self.get(content = ::File.read(LOAD_AVG_FILE))
|
||||
load_average = content.chomp.split(TOKEN_SEPARATOR)
|
||||
|
||||
{
|
||||
:"1m" => load_average[0].to_f,
|
||||
|
|
|
@ -13,14 +13,10 @@ describe LogStash::Instrument::PeriodicPoller::LoadAverage do
|
|||
context "when it can read the file" do
|
||||
let(:proc_loadavg) { "0.00 0.01 0.05 3/180 29727" }
|
||||
|
||||
before do
|
||||
expect(::File).to receive(:read).with("/proc/loadavg").and_return(proc_loadavg)
|
||||
end
|
||||
|
||||
it "return the 3 load average from `/proc/loadavg`" do
|
||||
avg_1m, avg_5m, avg_15m = proc_loadavg.chomp.split(" ")
|
||||
|
||||
expect(subject.get).to include(:"1m" => avg_1m.to_f, :"5m" => avg_5m.to_f, :"15m" => avg_15m.to_f)
|
||||
expect(subject.get(proc_loadavg)).to include(:"1m" => avg_1m.to_f, :"5m" => avg_5m.to_f, :"15m" => avg_15m.to_f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue