Sha256: ea557db9b66380f39dfd348a8730ceec925d091c05a409ee7c206db038721cc0
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true module Facter module Resolvers module Linux class DockerUptime < BaseResolver init_resolver class << self private def post_resolve(fact_name) @fact_list.fetch(fact_name) { detect_uptime(fact_name) } end def detect_uptime(fact_name) days, hours, minutes, seconds = extract_uptime_from_docker total_seconds = convert_to_seconds(days, hours, minutes, seconds) @fact_list = Facter::Util::Resolvers::UptimeHelper.create_uptime_hash(total_seconds) @fact_list[fact_name] end def extract_uptime_from_docker # time format [dd-][hh:]mm:ss time = Facter::Core::Execution.execute('ps -o etime= -p "1"', logger: log) extracted_time = time.split(/[-:]/) reversed_time = extracted_time.reverse seconds = reversed_time[0].to_i minutes = reversed_time[1].to_i hours = reversed_time[2].to_i days = reversed_time[3].to_i [days, hours, minutes, seconds] end def convert_to_seconds(days, hours, minutes, seconds) days * 24 * 3600 + hours * 3600 + minutes * 60 + seconds end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facter-4.0.49 | lib/facter/resolvers/linux/docker_uptime.rb |
facter-4.0.48 | lib/facter/resolvers/linux/docker_uptime.rb |
facter-4.0.47 | lib/facter/resolvers/linux/docker_uptime.rb |