mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Improve usability of Prometheus metrics backend (#16060)
This commit is contained in:
parent
00addc3e5d
commit
7c619bdc9a
3 changed files with 20 additions and 9 deletions
|
@ -2241,9 +2241,10 @@ lighting_boost_spread (Light curve boost spread) float 0.2 0.0 0.4
|
|||
enable_ipv6 (IPv6) [common] bool true
|
||||
|
||||
# Prometheus listener address.
|
||||
# If Luanti is compiled with ENABLE_PROMETHEUS option enabled,
|
||||
# enable metrics listener for Prometheus on that address.
|
||||
# Metrics can be fetched on http://127.0.0.1:30000/metrics
|
||||
# If Luanti is compiled with Prometheus support, this setting
|
||||
# enables the metrics listener for Prometheus on that address.
|
||||
# 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
|
||||
|
||||
# Maximum size of the client's outgoing chat queue.
|
||||
|
|
|
@ -284,12 +284,12 @@ Server::Server(
|
|||
throw ServerError("Supplied invalid gamespec");
|
||||
|
||||
#if USE_PROMETHEUS
|
||||
if (!simple_singleplayer_mode)
|
||||
m_metrics_backend = std::unique_ptr<MetricsBackend>(createPrometheusMetricsBackend());
|
||||
else
|
||||
#else
|
||||
if (true)
|
||||
if (!simple_singleplayer_mode) {
|
||||
// Note: may return null
|
||||
m_metrics_backend.reset(createPrometheusMetricsBackend());
|
||||
}
|
||||
#endif
|
||||
if (!m_metrics_backend)
|
||||
m_metrics_backend = std::make_unique<MetricsBackend>();
|
||||
|
||||
m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)");
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <prometheus/gauge.h>
|
||||
#include "log.h"
|
||||
#include "settings.h"
|
||||
#include "exceptions.h"
|
||||
#endif
|
||||
|
||||
/* Plain implementation */
|
||||
|
@ -183,7 +184,16 @@ MetricsBackend *createPrometheusMetricsBackend()
|
|||
{
|
||||
std::string addr;
|
||||
g_settings->getNoEx("prometheus_listener_address", addr);
|
||||
return new PrometheusMetricsBackend(addr);
|
||||
if (addr.empty())
|
||||
return nullptr;
|
||||
infostream << "Starting Prometheus metrics on " << addr << std::endl;
|
||||
try {
|
||||
return new PrometheusMetricsBackend(addr);
|
||||
} catch (std::exception &e) {
|
||||
errorstream << "Error while starting Prometheus metrics on " << addr
|
||||
<< ":\n" << e.what() << std::endl;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue