-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prometheus naming + deduplication and use gersemi for CMake formatting (
#325) * allow naming of prometheus stats * fix compile error * fix naming * deduplicate code * fix issues * move init to baseclass * move to private * init base variables * add gersemi
- Loading branch information
Showing
13 changed files
with
163 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <prometheus/registry.h> | ||
|
||
#define QUANTILE_DEFAULTS \ | ||
prometheus::Summary::Quantiles \ | ||
{ \ | ||
{0.5, 0.1}, {0.9, 0.1}, { 0.99, 0.1 } \ | ||
} | ||
|
||
/** | ||
* @class BaseServerStats | ||
* Represents the base statistics for a server. | ||
*/ | ||
class BaseServerStats { | ||
private: | ||
prometheus::Summary *_processingTime{nullptr}; ///< Value of the command processing performance | ||
prometheus::Gauge *_maxProcessingTime{nullptr}; ///< Maximum value of the command processing performance | ||
prometheus::Gauge *_minProcessingTime{nullptr}; ///< Minimum value of the command processing performance | ||
prometheus::Counter *_succeededCommand{nullptr}; ///< Number of succeeded commands | ||
prometheus::Counter *_failedCommand{nullptr}; ///< Number of failed commands | ||
prometheus::Counter *_totalCommand{nullptr}; ///< Number of total received commands | ||
|
||
protected: | ||
void initBaseStats(const std::shared_ptr<prometheus::Registry> ®, const std::string &name); | ||
|
||
void consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "Running pre-commit checks" | ||
pre-commit run --all-files | ||
|
||
echo "Running clang-format" | ||
clang-format include/**/*.hpp src/*.cpp src/**/*.cpp --verbose --dry-run --Werror | ||
|
||
echo "Running cppcheck" | ||
cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++14 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr | ||
|
||
echo "Running clang-tidy" | ||
run-clang-tidy -j`nproc` -p=build -header-filter=`pwd`/include/ src/*.cpp src/**/*.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "utils/BaseServerStats.hpp" | ||
|
||
#include <prometheus/counter.h> | ||
#include <prometheus/summary.h> | ||
|
||
void BaseServerStats::initBaseStats(const std::shared_ptr<prometheus::Registry> ®, const std::string &name) | ||
{ | ||
// Command stats | ||
_succeededCommand = &prometheus::BuildCounter() | ||
.Name(name + "succeeded_commands") | ||
.Help("Number of succeeded commands") | ||
.Register(*reg) | ||
.Add({}); | ||
_failedCommand = &prometheus::BuildCounter() | ||
.Name(name + "failed_commands") | ||
.Help("Number of failed commands") | ||
.Register(*reg) | ||
.Add({}); | ||
_totalCommand = &prometheus::BuildCounter() | ||
.Name(name + "received_commands") | ||
.Help("Number of received commands") | ||
.Register(*reg) | ||
.Add({}); | ||
|
||
// Performance stats | ||
_processingTime = &prometheus::BuildSummary() | ||
.Name(name + "processing_time") | ||
.Help("Command processing performance") | ||
.Register(*reg) | ||
.Add({}, QUANTILE_DEFAULTS); | ||
_maxProcessingTime = &prometheus::BuildGauge() | ||
.Name(name + "maximum_processing_time") | ||
.Help("Maximum value of the command processing performance") | ||
.Register(*reg) | ||
.Add({}); | ||
_minProcessingTime = &prometheus::BuildGauge() | ||
.Name(name + "minimum_processing_time") | ||
.Help("Minimum value of the command processing performance") | ||
.Register(*reg) | ||
.Add({}); | ||
|
||
// Set defaults | ||
_minProcessingTime->Set(std::numeric_limits<double>::max()); | ||
} | ||
|
||
void BaseServerStats::consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime) | ||
{ | ||
// Command stats | ||
_succeededCommand->Increment(static_cast<double>(succeeded)); | ||
_failedCommand->Increment(static_cast<double>(failed)); | ||
_totalCommand->Increment(static_cast<double>(succeeded + failed)); | ||
|
||
// Performance stats | ||
if (processingTime > 0) | ||
{ | ||
_processingTime->Observe(processingTime); | ||
_maxProcessingTime->Set(std::max(_maxProcessingTime->Value(), processingTime)); | ||
_minProcessingTime->Set(std::min(_minProcessingTime->Value(), processingTime)); | ||
} | ||
} |
Oops, something went wrong.