Class: Intranet::System::LinuxStatsProvider
- Inherits:
-
Object
- Object
- Intranet::System::LinuxStatsProvider
- Defined in:
- lib/intranet/system/linux_stats_provider.rb
Overview
Provides system statistics for a Linux system.
Constant Summary collapse
- STATS_REFRESH_DELAY_S =
The system statistics refresh delay, in seconds. Under Linux, it is not necessary to refresh statistics more frequently than 5s since this is the refresh rate of the load average.
5
Instance Method Summary collapse
-
#initialize ⇒ LinuxStatsProvider
constructor
Initializes a new Linux statistics provider.
-
#stats ⇒ Hash
Returns the latest system statistics.
Constructor Details
#initialize ⇒ LinuxStatsProvider
Initializes a new Linux statistics provider.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/intranet/system/linux_stats_provider.rb', line 24 def initialize @stats = { hostname: Socket.gethostname, loadavg: nil, cpu: { model: cpu_model, nb_cores: nb_cores }, ram: { total: ram_available }, swaps: {}, partitions: {} } @stats_date = Time.now - STATS_REFRESH_DELAY_S end |
Instance Method Details
#stats ⇒ Hash
Returns the latest system statistics. System statistics are updated if they are outdated.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/intranet/system/linux_stats_provider.rb', line 38 def stats now = Time.now if outdated?(now) @stats[:loadavg] = load_average @stats[:ram][:used] = ram_used @stats[:swaps] = swaps_usage @stats[:partitions] = partitions_usage @stats_date = now end @stats end |