MetroCollect  2.3.4
MetroCollect::MetricsSource::SourceProcStat Class Reference

Sources of CPU metrics extracted from the file /proc/stat. More...

#include <SourceProcStat.h>

Inheritance diagram for MetroCollect::MetricsSource::SourceProcStat:
Collaboration diagram for MetroCollect::MetricsSource::SourceProcStat:

Public Member Functions

size_t fieldCount () const noexcept override final
 Get the number of field the source has. More...
 
const std::vector< size_t > indexesOfFieldName (const FieldName &fieldName, Interests *interests=nullptr) const noexcept override final
 Search for fields associated to a specific name. More...
 
const std::string fieldNameSourcePrefix () const noexcept override final
 Get the prefix by which all field names should begin with. More...
 
const FieldInfo fieldInfoAtIndex (size_t index) const noexcept override final
 Get details about a specific field. More...
 
const std::vector< FieldInfoallFieldsInfo () const noexcept override final
 Get all fields details, field which share a common name should appear only once. More...
 
void fetchData (const Interests &interests, DataArray::Iterator current) override final
 Fetch the latest metrics. More...
 
void computeDiff (const Interests &interests, DiffArray::Iterator diff, DataArray::ConstIterator current, DataArray::ConstIterator previous, double factor=1) noexcept override final
 Compute the variation (in appropriate unit) of metrics. More...
 
- Public Member Functions inherited from MetroCollect::MetricsSource::SourceBase
 SourceBase (const SourceBase &)=delete
 Deleted copy constructor. More...
 
void operator= (const SourceBase &)=delete
 Deleted copy operator. More...
 

Static Public Member Functions

static SourceProcStatget ()
 Get the Instance object. More...
 

Protected Member Functions

 SourceProcStat ()
 Private default constructor. More...
 
void parseFields ()
 File parser function. More...
 
- Protected Member Functions inherited from MetroCollect::MetricsSource::SourceBase
 SourceBase ()
 Protected default constructor. More...
 
 ~SourceBase ()
 Protected default destructor. More...
 

Protected Attributes

size_t cpuCount_
 Number of CPUs. More...
 
std::vector< std::string > otherFieldNames_
 Names of other CPU metrics. More...
 
std::ifstream file_
 File descriptor. More...
 
std::vector< char > buffer_
 Buffer to put file contents into. More...
 

Static Protected Attributes

static constexpr std::string_view filePath = "/proc/stat"sv
 CPU metrics file path. More...
 
static constexpr std::string_view sourcePrefix = "cpu"sv
 Metrics name source prefix. More...
 
static constexpr std::string_view fieldNameOtherPrefix = "other"sv
 Metrics name category. More...
 
static constexpr std::string_view fieldNameAllCoresPrefix = "all"sv
 Metrics name category. More...
 
static constexpr std::string_view fieldNameCorePrefix = "core"sv
 Metrics name category. More...
 
static constexpr std::string_view fieldNameCoreDescription = "cpuID"sv
 Metrics name category description. More...
 
static constexpr std::string_view fieldNameCoreAll = "*"sv
 Metrics name wildcard. More...
 
static constexpr std::string_view cpuField = "cpu"sv
 Metrics name category. More...
 
static constexpr size_t cpuFieldCount = 10
 Number of fields for each CPU. More...
 
static constexpr std::array< std::string_view, cpuFieldCountcpuFieldNames = {"user"sv, "nice"sv, "system"sv, "idle"sv, "iowait"sv, "irq"sv, "softirq"sv, "steal"sv, "guest"sv, "guestNice"sv}
 CPU states names. More...
 
static constexpr std::string_view percentUnit = "%"sv
 Metric unit. More...
 
static constexpr std::string_view defaultUnit = ""sv
 Metric unit. More...
 

Detailed Description

Sources of CPU metrics extracted from the file /proc/stat.

Definition at line 38 of file SourceProcStat.h.

Constructor & Destructor Documentation

◆ SourceProcStat()

MetroCollect::MetricsSource::SourceProcStat::SourceProcStat ( )
protected

Private default constructor.

Definition at line 29 of file SourceProcStat.cc.

Here is the call graph for this function:

Member Function Documentation

◆ allFieldsInfo()

const std::vector< FieldInfo > MetroCollect::MetricsSource::SourceProcStat::allFieldsInfo ( ) const
finaloverridevirtualnoexcept

Get all fields details, field which share a common name should appear only once.

Returns
all fields details

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 139 of file SourceProcStat.cc.

Here is the call graph for this function:

◆ computeDiff()

void MetroCollect::MetricsSource::SourceProcStat::computeDiff ( const Interests interests,
DiffArray::Iterator  diff,
DataArray::ConstIterator  current,
DataArray::ConstIterator  previous,
double  factor = 1 
)
finaloverridevirtualnoexcept

Compute the variation (in appropriate unit) of metrics.

Parameters
interestsinterests boolean array to know for which fields metrics variation should be computed
diffiterator to write metrics variation to
currentiterator to read latest metrics from
previousiterator to read previous metrics from
factorfactor to convert to unit per second, if relevant

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 202 of file SourceProcStat.cc.

◆ fetchData()

void MetroCollect::MetricsSource::SourceProcStat::fetchData ( const Interests interests,
DataArray::Iterator  current 
)
finaloverridevirtual

Fetch the latest metrics.

Parameters
interestsboolean array to know for which fields metrics should be fetched
currentiterator to write metrics to

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 151 of file SourceProcStat.cc.

Here is the call graph for this function:

◆ fieldCount()

size_t MetroCollect::MetricsSource::SourceProcStat::fieldCount ( ) const
finaloverridevirtualnoexcept

Get the number of field the source has.

Returns
Number of fields of the source

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 63 of file SourceProcStat.cc.

Here is the caller graph for this function:

◆ fieldInfoAtIndex()

const FieldInfo MetroCollect::MetricsSource::SourceProcStat::fieldInfoAtIndex ( size_t  index) const
finaloverridevirtualnoexcept

Get details about a specific field.

Parameters
indexindex of the field to get details of
Returns
details of the field

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 124 of file SourceProcStat.cc.

Here is the caller graph for this function:

◆ fieldNameSourcePrefix()

const std::string MetroCollect::MetricsSource::SourceProcStat::fieldNameSourcePrefix ( ) const
finaloverridevirtualnoexcept

Get the prefix by which all field names should begin with.

Returns
the source's names prefix

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 120 of file SourceProcStat.cc.

◆ get()

static SourceProcStat& MetroCollect::MetricsSource::SourceProcStat::get ( )
inlinestatic

Get the Instance object.

Definition at line 66 of file SourceProcStat.h.

◆ indexesOfFieldName()

const std::vector< size_t > MetroCollect::MetricsSource::SourceProcStat::indexesOfFieldName ( const FieldName fieldName,
Interests interests = nullptr 
) const
finaloverridevirtualnoexcept

Search for fields associated to a specific name.

Parameters
fieldNamethe name of the fields to search
interestsif the pointer is not nullptr, the interest bit corresponding to the fields will be set
Returns
the indexes associated with the field name

Implements MetroCollect::MetricsSource::SourceBase.

Definition at line 67 of file SourceProcStat.cc.

◆ parseFields()

void MetroCollect::MetricsSource::SourceProcStat::parseFields ( )
protected

File parser function.

Definition at line 35 of file SourceProcStat.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ buffer_

std::vector<char> MetroCollect::MetricsSource::SourceProcStat::buffer_
protected

Buffer to put file contents into.

Definition at line 57 of file SourceProcStat.h.

◆ cpuCount_

size_t MetroCollect::MetricsSource::SourceProcStat::cpuCount_
protected

Number of CPUs.

Definition at line 54 of file SourceProcStat.h.

◆ cpuField

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::cpuField = "cpu"sv
staticprotected

Metrics name category.

Definition at line 48 of file SourceProcStat.h.

◆ cpuFieldCount

constexpr size_t MetroCollect::MetricsSource::SourceProcStat::cpuFieldCount = 10
staticprotected

Number of fields for each CPU.

Definition at line 49 of file SourceProcStat.h.

◆ cpuFieldNames

constexpr std::array<std::string_view, cpuFieldCount> MetroCollect::MetricsSource::SourceProcStat::cpuFieldNames = {"user"sv, "nice"sv, "system"sv, "idle"sv, "iowait"sv, "irq"sv, "softirq"sv, "steal"sv, "guest"sv, "guestNice"sv}
staticprotected

CPU states names.

Definition at line 50 of file SourceProcStat.h.

◆ defaultUnit

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::defaultUnit = ""sv
staticprotected

Metric unit.

Definition at line 52 of file SourceProcStat.h.

◆ fieldNameAllCoresPrefix

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::fieldNameAllCoresPrefix = "all"sv
staticprotected

Metrics name category.

Definition at line 44 of file SourceProcStat.h.

◆ fieldNameCoreAll

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::fieldNameCoreAll = "*"sv
staticprotected

Metrics name wildcard.

Definition at line 47 of file SourceProcStat.h.

◆ fieldNameCoreDescription

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::fieldNameCoreDescription = "cpuID"sv
staticprotected

Metrics name category description.

Definition at line 46 of file SourceProcStat.h.

◆ fieldNameCorePrefix

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::fieldNameCorePrefix = "core"sv
staticprotected

Metrics name category.

Definition at line 45 of file SourceProcStat.h.

◆ fieldNameOtherPrefix

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::fieldNameOtherPrefix = "other"sv
staticprotected

Metrics name category.

Definition at line 43 of file SourceProcStat.h.

◆ file_

std::ifstream MetroCollect::MetricsSource::SourceProcStat::file_
protected

File descriptor.

Definition at line 56 of file SourceProcStat.h.

◆ filePath

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::filePath = "/proc/stat"sv
staticprotected

CPU metrics file path.

Definition at line 40 of file SourceProcStat.h.

◆ otherFieldNames_

std::vector<std::string> MetroCollect::MetricsSource::SourceProcStat::otherFieldNames_
protected

Names of other CPU metrics.

Definition at line 55 of file SourceProcStat.h.

◆ percentUnit

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::percentUnit = "%"sv
staticprotected

Metric unit.

Definition at line 51 of file SourceProcStat.h.

◆ sourcePrefix

constexpr std::string_view MetroCollect::MetricsSource::SourceProcStat::sourcePrefix = "cpu"sv
staticprotected

Metrics name source prefix.

Definition at line 42 of file SourceProcStat.h.


The documentation for this class was generated from the following files: