hydra-queue-runner: add simple "up" exporter
There are probably better ways to achieve this (and will likely need to be refactored a bit to support further metrics).
This commit is contained in:
parent
5bbaa18a8f
commit
3bf31bd6a6
|
@ -565,6 +565,7 @@
|
|||
(if lib.versionAtLeast lib.version "20.03pre"
|
||||
then nlohmann_json
|
||||
else nlohmann_json.override { multipleHeaders = true; })
|
||||
prometheus-cpp
|
||||
];
|
||||
|
||||
checkInputs = [
|
||||
|
|
|
@ -4,5 +4,5 @@ hydra_queue_runner_SOURCES = hydra-queue-runner.cc queue-monitor.cc dispatcher.c
|
|||
builder.cc build-result.cc build-remote.cc \
|
||||
build-result.hh counter.hh state.hh db.hh \
|
||||
nar-extractor.cc nar-extractor.hh
|
||||
hydra_queue_runner_LDADD = $(NIX_LIBS) -lpqxx
|
||||
hydra_queue_runner_LDADD = $(NIX_LIBS) -lpqxx -lprometheus-cpp-pull -lprometheus-cpp-core
|
||||
hydra_queue_runner_CXXFLAGS = $(NIX_CFLAGS) -Wall -I ../libhydra -Wno-deprecated-declarations
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <prometheus/exposer.h>
|
||||
#include <prometheus/registry.h>
|
||||
#include <prometheus/gauge.h>
|
||||
|
||||
#include "state.hh"
|
||||
#include "build-result.hh"
|
||||
#include "store-api.hh"
|
||||
|
@ -854,6 +858,25 @@ int main(int argc, char * * argv)
|
|||
return handleExceptions(argv[0], [&]() {
|
||||
initNix();
|
||||
|
||||
/* Export a simple "up" metric, to allow monitoring that we're
|
||||
still alive. */
|
||||
std::thread([&]() {
|
||||
prometheus::Exposer exposer{"127.0.0.1:8080"};
|
||||
|
||||
// @note it's the users responsibility to keep the object alive
|
||||
auto registry = std::make_shared<prometheus::Registry>();
|
||||
|
||||
auto& running = prometheus::BuildGauge()
|
||||
.Name("hydra_queue_runner_running")
|
||||
.Help("Whether the queue runner is currently running")
|
||||
.Register(*registry);
|
||||
|
||||
exposer.RegisterCollectable(registry);
|
||||
running.Add({}).Set(1);
|
||||
|
||||
while (true) { }
|
||||
}).detach();
|
||||
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
|
|
Loading…
Reference in a new issue