-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
799 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class Available | ||
FACT_NAME = 'memory.swap.available' | ||
ALIASES = 'swapfree' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:available_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class AvailableBytes | ||
FACT_NAME = 'memory.swap.available_bytes' | ||
ALIASES = 'swapfree_mb' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:available_bytes) | ||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), | ||
Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class Capacity | ||
FACT_NAME = 'memory.swap.capacity' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:capacity) | ||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class Encrypted | ||
FACT_NAME = 'memory.swap.encrypted' | ||
ALIASES = 'swapencrypted' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:encrypted) | ||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class Total | ||
FACT_NAME = 'memory.swap.total' | ||
ALIASES = 'swapsize' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:total_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class TotalBytes | ||
FACT_NAME = 'memory.swap.total_bytes' | ||
ALIASES = 'swapsize_mb' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:total_bytes) | ||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), | ||
Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class Used | ||
FACT_NAME = 'memory.swap.used' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:used_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module Swap | ||
class UsedBytes | ||
FACT_NAME = 'memory.swap.used_bytes' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SwapMemory.resolve(:used_bytes) | ||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class Available | ||
FACT_NAME = 'memory.system.available' | ||
ALIASES = 'memoryfree' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:available_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class AvailableBytes | ||
FACT_NAME = 'memory.system.available_bytes' | ||
ALIASES = 'memoryfree_mb' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:available_bytes) | ||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), | ||
Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class Capacity | ||
FACT_NAME = 'memory.system.capacity' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:capacity) | ||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class Total | ||
FACT_NAME = 'memory.system.total' | ||
ALIASES = 'memorysize' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:total_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class TotalBytes | ||
FACT_NAME = 'memory.system.total_bytes' | ||
ALIASES = 'memorysize_mb' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:total_bytes) | ||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), | ||
Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class Used | ||
FACT_NAME = 'memory.system.used' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:used_bytes) | ||
fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value) | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Memory | ||
module System | ||
class UsedBytes | ||
FACT_NAME = 'memory.system.used_bytes' | ||
|
||
def call_the_resolver | ||
fact_value = Facter::Resolvers::Freebsd::SystemMemory.resolve(:used_bytes) | ||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Resolvers | ||
module Freebsd | ||
class SwapMemory < BaseResolver | ||
@semaphore = Mutex.new | ||
@fact_list ||= {} | ||
class << self | ||
private | ||
|
||
def post_resolve(fact_name) | ||
@fact_list.fetch(fact_name) { read_swap_memory(fact_name) } | ||
end | ||
|
||
def read_swap_memory(fact_name) # rubocop:disable Metrics/AbcSize | ||
output = Facter::Core::Execution.execute('swapinfo -k', logger: log) | ||
data = output.split("\n")[1..-1].map { |line| line.split(/\s+/) } | ||
|
||
unless data.empty? | ||
@fact_list[:total_bytes] = kilobytes_to_bytes(data.map { |line| line[1].to_i }.inject(:+)) | ||
@fact_list[:used_bytes] = kilobytes_to_bytes(data.map { |line| line[2].to_i }.inject(:+)) | ||
@fact_list[:available_bytes] = kilobytes_to_bytes(data.map { |line| line[3].to_i }.inject(:+)) | ||
@fact_list[:capacity] = compute_capacity(@fact_list[:used_bytes], @fact_list[:total_bytes]) | ||
@fact_list[:encrypted] = data.map { |line| line[0].end_with?('.eli') }.all? | ||
end | ||
|
||
@fact_list[fact_name] | ||
end | ||
|
||
def kilobytes_to_bytes(quantity) | ||
(quantity.to_f * 1024).to_i | ||
end | ||
|
||
def compute_capacity(used, total) | ||
"#{format('%<value>.2f', value: (used / total.to_f * 100))}%" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.