1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Improve usability of Prometheus metrics backend (#16060)

This commit is contained in:
sfan5 2025-04-23 09:30:04 +02:00 committed by GitHub
parent 00addc3e5d
commit 7c619bdc9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 9 deletions

View file

@ -2241,9 +2241,10 @@ lighting_boost_spread (Light curve boost spread) float 0.2 0.0 0.4
enable_ipv6 (IPv6) [common] bool true enable_ipv6 (IPv6) [common] bool true
# Prometheus listener address. # Prometheus listener address.
# If Luanti is compiled with ENABLE_PROMETHEUS option enabled, # If Luanti is compiled with Prometheus support, this setting
# enable metrics listener for Prometheus on that address. # enables the metrics listener for Prometheus on that address.
# Metrics can be fetched on http://127.0.0.1:30000/metrics # By default you can fetch metrics from http://127.0.0.1:30000/metrics.
# An empty value disables the metrics listener.
prometheus_listener_address (Prometheus listener address) [server] string 127.0.0.1:30000 prometheus_listener_address (Prometheus listener address) [server] string 127.0.0.1:30000
# Maximum size of the client's outgoing chat queue. # Maximum size of the client's outgoing chat queue.

View file

@ -284,12 +284,12 @@ Server::Server(
throw ServerError("Supplied invalid gamespec"); throw ServerError("Supplied invalid gamespec");
#if USE_PROMETHEUS #if USE_PROMETHEUS
if (!simple_singleplayer_mode) if (!simple_singleplayer_mode) {
m_metrics_backend = std::unique_ptr<MetricsBackend>(createPrometheusMetricsBackend()); // Note: may return null
else m_metrics_backend.reset(createPrometheusMetricsBackend());
#else }
if (true)
#endif #endif
if (!m_metrics_backend)
m_metrics_backend = std::make_unique<MetricsBackend>(); m_metrics_backend = std::make_unique<MetricsBackend>();
m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)"); m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)");

View file

@ -11,6 +11,7 @@
#include <prometheus/gauge.h> #include <prometheus/gauge.h>
#include "log.h" #include "log.h"
#include "settings.h" #include "settings.h"
#include "exceptions.h"
#endif #endif
/* Plain implementation */ /* Plain implementation */
@ -183,7 +184,16 @@ MetricsBackend *createPrometheusMetricsBackend()
{ {
std::string addr; std::string addr;
g_settings->getNoEx("prometheus_listener_address", addr); g_settings->getNoEx("prometheus_listener_address", addr);
if (addr.empty())
return nullptr;
infostream << "Starting Prometheus metrics on " << addr << std::endl;
try {
return new PrometheusMetricsBackend(addr); return new PrometheusMetricsBackend(addr);
} catch (std::exception &e) {
errorstream << "Error while starting Prometheus metrics on " << addr
<< ":\n" << e.what() << std::endl;
throw e;
}
} }
#endif #endif