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



383
384
385
386
387
388
389
390
# File 'lib/libosctl/cgroup/path_reader.rb', line 383

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.



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

def cg_reader
  @cg_reader
end

Instance Method Details

#list_available_paramsArray<String>

List available CGroup parameters

Returns:

  • (Array<String>)


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

def list_available_params
  cg_reader.list_available_params
end

#read_params(params) ⇒ Hash

Read selected CGroup parameters

Parameters:

  • params (Array)

Returns:

  • (Hash)


420
421
422
# File 'lib/libosctl/cgroup/path_reader.rb', line 420

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



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/libosctl/cgroup/path_reader.rb', line 396

def read_stats(params, precise)
  ret = {}

  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

  ret
end