39 const char* buffer = std::strchr(this->
buffer_.data(),
'\n') + 1;
40 buffer = std::strchr(buffer,
'|') + 1;
43 while(buffer[0] !=
'|') {
44 while (!std::isalnum(buffer[0]))
47 while (std::isalnum(buffer[length]))
55 while(buffer[0] !=
'\n') {
56 while (!std::isalnum(buffer[0]))
59 while (std::isalnum(buffer[length]))
67 while (buffer[0] !=
'\0') {
68 while (!std::isalnum(buffer[0]))
71 while (std::isalnum(buffer[length]))
75 while (buffer[0] !=
'\n')
90 size_t baseIndex = -1;
92 auto itr = std::find(this->rxFieldNames_.begin(), this->rxFieldNames_.end(), fieldName[3]);
93 if (itr != this->rxFieldNames_.end()) {
96 baseIndex = std::distance(this->rxFieldNames_.begin(), itr);
100 auto itr = std::find(this->txFieldNames_.begin(), this->txFieldNames_.end(), fieldName[3]);
101 if (itr != this->txFieldNames_.end()) {
104 baseIndex = this->rxFieldNames_.size() + std::distance(this->txFieldNames_.begin(), itr);
109 if (baseIndex < this->rxFieldNames_.size() + this->txFieldNames_.size()) {
110 if (fieldName[1] == fieldNameAll) {
111 std::vector<size_t> indexes;
112 indexes.resize(this->interfaces_.size(), 0);
113 for (
size_t i = 0; i < indexes.size(); i++)
114 indexes[i] = i * (this->rxFieldNames_.size() + this->txFieldNames_.size()) + baseIndex;
117 auto itr = std::find(this->interfaces_.begin(), this->interfaces_.end(), fieldName[1]);
118 if (itr != this->interfaces_.end())
119 return {std::distance(this->interfaces_.begin(), itr) * (this->rxFieldNames_.size() + this->txFieldNames_.size()) + baseIndex};
130 size_t ifIndex = index / (this->rxFieldNames_.size() + this->txFieldNames_.size());
131 size_t fieldIndex = index % (this->rxFieldNames_.size() + this->txFieldNames_.size());
132 bool isRx = fieldIndex < this->rxFieldNames_.size();
134 fieldIndex -= this->rxFieldNames_.size();
136 std::string fieldName = (isRx ? this->rxFieldNames_[fieldIndex] : this->txFieldNames_[fieldIndex]);
143 std::vector<FieldInfo> info;
159 size_t remainingInterfaces = this->
interfaces_.size();
160 const char* buffer = this->
buffer_.data();
161 while (buffer[0] !=
'\n')
164 while (buffer[0] !=
'\n')
168 while (remainingInterfaces > 0 && buffer[0] !=
'\0') {
169 while (buffer[0] !=
':')
172 while (buffer[0] !=
'\n') {
178 remainingInterfaces--;
184 if (interests.none())
187 for (
size_t i = 0; i < this->fieldCount(); i++) {
188 *diff =
static_cast<DiffValueType>((*current - *previous) * factor);
Object used to describe a field (or metric)
std::vector< std::string > rxFieldNames_
Reception metric names.
static constexpr std::array fieldUnitsAssociation
Metric units associations.
std::vector< std::string > txFieldNames_
Transmission metric names.
const std::vector< size_t > indexesOfFieldName(const FieldName &fieldName, Interests *interests=nullptr) const noexcept override final
Search for fields associated to a specific name.
std::vector< std::string > FieldName
Type used for field names (an array of strings)
bool readFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to read file into buffer.
Namespace for sources of metrics objects and operations.
std::ifstream file_
File descriptor.
std::vector< DataValueType >::const_iterator ConstIterator
Const iterator type of MetricsDataArray.
uint64_t parseUint(const char *&buffer) noexcept
Fast and unsafe unsigned integer parser.
void fetchData(const Interests &interests, DataArray::Iterator current) override final
Fetch the latest metrics.
std::vector< char > buffer_
Buffer to put file contents into.
SourceProcNetDev()
Private default constructor.
const std::vector< FieldInfo > allFieldsInfo() const noexcept override final
Get all fields details, field which share a common name should appear only once.
static constexpr std::string_view fieldNameAll
Metrics name wildcard.
static constexpr std::string_view sourcePrefix
Metrics name source prefix.
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.
static constexpr std::string_view filePath
Network metrics file path.
int64_t DataValueType
Type of fetched raw metrics.
bool none() const
Checks wether all bit are false.
Boolean array to keep track of which fields a source has to fetch metrics for.
std::vector< DiffValueType >::iterator Iterator
Iterator type of MetricsDiffArray.
size_t fieldCount() const noexcept override final
Get the number of field the source has.
bool resetFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to open a file and set buffer size accordingly.
static constexpr std::string_view fieldRecieve
Metrics name category.
static constexpr std::string_view defaultUnit
Metric unit.
void parseFields()
File parser function.
static constexpr std::string_view fieldTransmit
Metrics name category.
static constexpr std::string_view fieldNameInterfaceDescription
Metrics name category description.
const std::string fieldNameSourcePrefix() const noexcept override final
Get the prefix by which all field names should begin with.
std::string findUnit(const std::string &name, const std::array< KeyUnit, N > &keyUnitAssociation, const std::string_view &defaultUnit)
Tries to associate a field name with a unit, falling back on the default unit if none matches...
std::vector< DataValueType >::iterator Iterator
Iterator type of MetricsDataArray.
std::vector< std::string > interfaces_
Network interfaces names.
const FieldInfo fieldInfoAtIndex(size_t index) const noexcept override final
Get details about a specific field.
double DiffValueType
Type of metric variation.