diff --git a/flake.nix b/flake.nix index 2c4a4ddb..175aa406 100644 --- a/flake.nix +++ b/flake.nix @@ -565,6 +565,7 @@ (if lib.versionAtLeast lib.version "20.03pre" then nlohmann_json else nlohmann_json.override { multipleHeaders = true; }) + prometheus-cpp ]; checkInputs = [ diff --git a/src/hydra-queue-runner/Makefile.am b/src/hydra-queue-runner/Makefile.am index ea852334..6e01ef85 100644 --- a/src/hydra-queue-runner/Makefile.am +++ b/src/hydra-queue-runner/Makefile.am @@ -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 diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 3297730c..af7ec28d 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -6,6 +6,10 @@ #include #include +#include +#include +#include + #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(); + + 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);