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:
Cole Helbling 2022-03-10 12:21:30 -08:00
parent 5bbaa18a8f
commit 3bf31bd6a6
3 changed files with 25 additions and 1 deletions

View file

@ -565,6 +565,7 @@
(if lib.versionAtLeast lib.version "20.03pre"
then nlohmann_json
else nlohmann_json.override { multipleHeaders = true; })
prometheus-cpp
];
checkInputs = [

View file

@ -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

View file

@ -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);