From 4789eba92c65df52a204e4d7a4d3ee6f512df28e Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 29 Mar 2022 10:55:28 -0700 Subject: [PATCH] hydra-queue-runer: split metrics functionality into its own function --- src/hydra-queue-runner/hydra-queue-runner.cc | 30 +++++++++++++------- src/hydra-queue-runner/state.hh | 2 ++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 3834f625..992b9995 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -750,6 +750,24 @@ void State::unlock() } +void State::runMetricsExporter() +{ + std::cout << "Starting the Prometheus exporter on port " << metricsPort << std::endl; + + /* Set up simple exporter, to show that we're still alive. */ + std::string metricsAddress{"127.0.0.1"}; + prometheus::Exposer exposer{metricsAddress + ":" + std::to_string(metricsPort)}; + auto exposerPort = exposer.GetListeningPorts().front(); + exposer.RegisterCollectable(registry); + + std::cout << "Started the Prometheus exporter, listening on " + << "http://" << metricsAddress << ":" << exposerPort << "/metrics" + << std::endl; + + while (true) {}; +} + + void State::run(BuildID buildOne) { /* Can't be bothered to shut down cleanly. Goodbye! */ @@ -762,17 +780,7 @@ void State::run(BuildID buildOne) if (!lock) throw Error("hydra-queue-runner is already running"); - std::cout << "Starting the Prometheus exporter on port " << metricsPort << std::endl; - - /* Set up simple exporter, to show that we're still alive. */ - std::string metricsAddress{"127.0.0.1"}; - prometheus::Exposer exposer{metricsAddress + ":" + std::to_string(metricsPort)}; - auto exposerPort = exposer.GetListeningPorts().front(); - exposer.RegisterCollectable(registry); - - std::cout << "Started the Prometheus exporter, listening on " - << "http://" << metricsAddress << ":" << exposerPort << "/metrics" - << std::endl; + std::thread(&State::runMetricsExporter, this).detach(); Store::Params localParams; localParams["max-connections"] = "16"; diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 63112c16..fb533559 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -549,6 +549,8 @@ private: void addRoot(const nix::StorePath & storePath); + void runMetricsExporter(); + public: void showStatus();