~ubuntu-branches/ubuntu/trusty/facter/trusty

« back to all changes in this revision

Viewing changes to lib/facter/util/uptime.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock, Nigel Kersten, Andrew Pollock
  • Date: 2009-04-13 15:20:21 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090413152021-t3uagjamr3ee4njl
Tags: 1.5.4-1
[ Nigel Kersten ]
* New upstream release
* Switch maintainer to pkg-puppet-devel list
* Modify uploaders
* Update watch file regexp to exclude release canditate tarballs
* Use upstream install.rb script to build rather than copying manually

[ Andrew Pollock ]
* debian/control: add libopenssl-ruby to build dependencies
* debian/control: bump Standards-Version (no changes)
* debian/compat: increase to 5
* debian/control: add pciutils and ${misc:Depends} to dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# A module to gather uptime facts
 
2
#
 
3
module Facter::Util::Uptime
 
4
 
 
5
    def self.get_uptime_simple
 
6
        time = Facter::Util::Resolution.exec('uptime')
 
7
            if time =~ /up\s*(\d+\s\w+)/
 
8
                $1
 
9
            elsif time =~ /up\s*(\d+:\d+)/
 
10
                $1 + " hours"
 
11
            else
 
12
                "unknown"
 
13
            end
 
14
    end
 
15
 
 
16
    def self.get_uptime
 
17
        uptime, idletime = File.open("/proc/uptime").gets.split(" ")
 
18
        uptime_seconds = uptime.to_i
 
19
    end
 
20
 
 
21
    def self.get_uptime_period(seconds, label)
 
22
        
 
23
        case label
 
24
        when 'days'
 
25
            value = seconds / 86400
 
26
        when 'hours'
 
27
            value = seconds / 3600
 
28
        when 'seconds'
 
29
            seconds
 
30
        end     
 
31
   
 
32
    end
 
33
 
 
34
end