Class: OsCtl::Lib::CGroup::PathReader

Inherits:
Object
  • Object
show all
Defined in:
lib/libosctl/cgroup/path_reader.rb

Overview

Version-agnostic interface for reading CGroup parameters

Defined Under Namespace

Classes: Base, V1, V2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subsystems, path) ⇒ PathReader

Returns a new instance of PathReader.

Parameters:

  • subsystems (Hash)

    subsystem => absolute path, ignored on CGroupv2

  • path (String)

    path of chosen group, relative to the subsystem



438
439
440
441
442
443
444
445
# File 'lib/libosctl/cgroup/path_reader.rb', line 438

def initialize(subsystems, path)
  @cg_reader =
    if CGroup.v1?
      V1.new(subsystems, path)
    else
      V2.new(CGroup::FS, path)
    end
end

Instance Attribute Details

#cg_readerObject (readonly, protected)

Returns the value of attribute cg_reader.



489
490
491
# File 'lib/libosctl/cgroup/path_reader.rb', line 489

def cg_reader
  @cg_reader
end

Instance Method Details

#list_available_paramsArray<String>

List available CGroup parameters

Returns:

  • (Array<String>)


483
484
485
# File 'lib/libosctl/cgroup/path_reader.rb', line 483

def list_available_params
  cg_reader.list_available_params
end

#read_params(params) ⇒ Hash

Read selected CGroup parameters

Parameters:

  • params (Array)

Returns:

  • (Hash)


477
478
479
# File 'lib/libosctl/cgroup/path_reader.rb', line 477

def read_params(params)
  cg_reader.read_params(params)
end

#read_stats(params, precise) ⇒ Hash

Read and interpret selected CGroup parameters

Parameters:

  • params (Array)

    parameters to read

  • precise (Boolean)

    humanize parameter values?

Returns:

  • (Hash)

    parameter => value



451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/libosctl/cgroup/path_reader.rb', line 451

def read_stats(params, precise)
  ret = {}

  cg_reader.read_stats do
    params.each do |field|
      next if ret[field]

      v = cg_reader.read_stats_param(field, precise)
      next if v.nil?

      if v.is_a?(Hash)
        ret.update(v)
      else
        ret[field] = v
      end
    rescue Errno::ENOENT
      ret[field] = nil
    end
  end

  ret
end