-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ore_patches_generation
- Loading branch information
Showing
16 changed files
with
292 additions
and
55 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,52 @@ | ||
#include <memory> | ||
|
||
#include <prometheus/counter.h> | ||
#include <prometheus/gauge.h> | ||
#include <prometheus/info.h> | ||
#include <prometheus/registry.h> | ||
|
||
#include "PrometheusExporter.hpp" | ||
#include "options.hpp" | ||
|
||
PrometheusExporter::PrometheusExporter(const std::string &bind): | ||
_exposer(bind), | ||
_ready(false) | ||
{ | ||
} | ||
|
||
void PrometheusExporter::registerMetrics() | ||
{ | ||
_registry = std::make_shared<prometheus::Registry>(); | ||
|
||
// clang-format off | ||
auto &packet_counter = prometheus::BuildCounter() | ||
.Name("observed_packets_total") | ||
.Help("Number of observed packets") | ||
.Register(*_registry); | ||
// clang-format on | ||
_packet_rx_counter = &packet_counter.Add({{"direction", "rx"}}); | ||
_packet_tx_counter = &packet_counter.Add({{"direction", "tx"}}); | ||
|
||
// clang-format off | ||
auto& version_info = prometheus::BuildInfo() | ||
.Name("versions") | ||
.Help("Static info about the server") | ||
.Register(*_registry); | ||
// clang-format on | ||
_version_info = &version_info.Add({{PROGRAM_NAME, PROGRAM_VERSION}}); | ||
|
||
// clang-format off | ||
auto &player_gauge = prometheus::BuildGauge() | ||
.Name("player_count") | ||
.Help("Number of players connected") | ||
.Register(*_registry); | ||
// clang-format on | ||
_player_global_gauge = &player_gauge.Add({{"dimension", "global"}}); | ||
_player_overworld_gauge = &player_gauge.Add({{"dimension", "overworld"}}); | ||
_player_nether_gauge = &player_gauge.Add({{"dimension", "nether"}}); | ||
_player_end_gauge = &player_gauge.Add({{"dimension", "end"}}); | ||
|
||
_exposer.RegisterCollectable(_registry); | ||
|
||
_ready = true; | ||
} |
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,103 @@ | ||
#ifndef D5AEBC4C_6028_4506_86F2_DA6261F54832 | ||
#define D5AEBC4C_6028_4506_86F2_DA6261F54832 | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "prometheus/counter.h" | ||
#include "prometheus/exposer.h" | ||
#include "prometheus/registry.h" | ||
|
||
class PrometheusExporter { | ||
public: | ||
PrometheusExporter(const std::string &bind); | ||
void registerMetrics(); | ||
void incrementPacketRxCounter() | ||
{ | ||
if (_ready) | ||
_packet_rx_counter->Increment(); | ||
} | ||
void incrementPacketTxCounter() | ||
{ | ||
if (_ready) | ||
_packet_tx_counter->Increment(); | ||
} | ||
void setPlayerCountGlobal(size_t n) | ||
{ | ||
if (_ready) | ||
_player_global_gauge->Set(n); | ||
} | ||
void setPlayerCountOverworld(size_t n) | ||
{ | ||
if (_ready) | ||
_player_overworld_gauge->Set(n); | ||
} | ||
void setPlayerCountNether(size_t n) | ||
{ | ||
if (_ready) | ||
_player_nether_gauge->Set(n); | ||
} | ||
void setPlayerCountEnd(size_t n) | ||
{ | ||
if (_ready) | ||
_player_end_gauge->Set(n); | ||
} | ||
void incrementPlayerCountGlobal() | ||
{ | ||
if (_ready) | ||
_player_global_gauge->Increment(); | ||
} | ||
void incrementPlayerCountOverworld() | ||
{ | ||
if (_ready) | ||
_player_overworld_gauge->Increment(); | ||
} | ||
void incrementPlayerCountNether() | ||
{ | ||
if (_ready) | ||
_player_nether_gauge->Increment(); | ||
} | ||
void incrementPlayerCountEnd() | ||
{ | ||
if (_ready) | ||
_player_end_gauge->Increment(); | ||
} | ||
void decrementPlayerCountGlobal() | ||
{ | ||
if (_ready) | ||
_player_global_gauge->Decrement(); | ||
} | ||
void decrementPlayerCountOverworld() | ||
{ | ||
if (_ready) | ||
_player_overworld_gauge->Decrement(); | ||
} | ||
void decrementPlayerCountNether() | ||
{ | ||
if (_ready) | ||
_player_nether_gauge->Decrement(); | ||
} | ||
void decrementPlayerCountEnd() | ||
{ | ||
if (_ready) | ||
_player_end_gauge->Decrement(); | ||
} | ||
|
||
private: | ||
prometheus::Exposer _exposer; | ||
std::shared_ptr<prometheus::Registry> _registry; | ||
|
||
prometheus::Counter *_packet_tx_counter; | ||
prometheus::Counter *_packet_rx_counter; | ||
|
||
prometheus::Info *_version_info; // This is not dynamic yet, but it can be in the future | ||
|
||
prometheus::Gauge *_player_global_gauge; | ||
prometheus::Gauge *_player_overworld_gauge; | ||
prometheus::Gauge *_player_nether_gauge; | ||
prometheus::Gauge *_player_end_gauge; | ||
|
||
std::atomic<bool> _ready; | ||
}; | ||
|
||
#endif /* D5AEBC4C_6028_4506_86F2_DA6261F54832 */ |
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
Oops, something went wrong.