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



386
387
388
389
390
391
392
393
# File 'lib/libosctl/cgroup/path_reader.rb', line 386

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.



437
438
439
# File 'lib/libosctl/cgroup/path_reader.rb', line 437

def cg_reader
  @cg_reader
end

Instance Method Details

#list_available_paramsArray<String>

List available CGroup parameters

Returns:

  • (Array<String>)


432
433
434
# File 'lib/libosctl/cgroup/path_reader.rb', line 432

def list_available_params
  cg_reader.list_available_params
end

#read_params(params) ⇒ Hash

Read selected CGroup parameters

Parameters:

  • params (Array)

Returns:

  • (Hash)


426
427
428
# File 'lib/libosctl/cgroup/path_reader.rb', line 426

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



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/libosctl/cgroup/path_reader.rb', line 399

def read_stats(params, precise)
  ret = {}

  params.each do |field|
    begin
      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