diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 0400b61b..b540bfe6 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -38,6 +38,18 @@ std::string getEnvOrDie(const std::string & key) return *value; } +State::PromMetrics::PromMetrics() + : registry(std::make_shared()) + , queue_checks_started( + prometheus::BuildCounter() + .Name("hydraqueuerunner_queue_checks_started_total") + .Help("Number of times State::getQueuedBuilds() was started") + .Register(*registry) + .Add({}) + ) +{ + +} State::State(std::optional metricsAddrOpt) : config(std::make_unique()) @@ -48,12 +60,6 @@ State::State(std::optional metricsAddrOpt) , uploadLogsToBinaryCache(config->getBoolOption("upload_logs_to_binary_cache", false)) , rootsDir(config->getStrOption("gc_roots_dir", fmt("%s/gcroots/per-user/%s/hydra-roots", settings.nixStateDir, getEnvOrDie("LOGNAME")))) , metricsAddr(config->getStrOption("queue_runner_metrics_address", std::string{"127.0.0.1:9198"})) - , registry(std::make_shared()) - , call_ctr(prometheus::BuildCounter() - .Name("queue_queued_builds_calls_total") - .Help("Number of times State::getQueuedBuilds() was called") - .Register(*registry)) - , queue_queued_builds_calls(call_ctr.Add({})) // FIXME: add the proper arguments { hydraData = getEnvOrDie("HYDRA_DATA"); @@ -774,7 +780,7 @@ void State::run(BuildID buildOne) prometheus::Exposer promExposer{metricsAddr}; auto exposerPort = promExposer.GetListeningPorts().front(); - promExposer.RegisterCollectable(registry); + promExposer.RegisterCollectable(prom.registry); std::cout << "Started the Prometheus exporter, listening on " << metricsAddr << "/metrics (port " << exposerPort << ")" diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index bcef4e2f..c4873cc5 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -82,7 +82,7 @@ struct PreviousFailure : public std::exception { bool State::getQueuedBuilds(Connection & conn, ref destStore, unsigned int & lastBuildId) { - queue_queued_builds_calls.Increment(); + prom.queue_checks_started.Increment(); printInfo("checking the queue for builds > %d...", lastBuildId); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 56e01a0e..6d1e45c4 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -437,10 +437,15 @@ private: std::string metricsAddr; - std::shared_ptr registry; + struct PromMetrics + { + std::shared_ptr registry; - prometheus::Family& call_ctr; - prometheus::Counter& queue_queued_builds_calls; + prometheus::Counter& queue_checks_started; + + PromMetrics(); + }; + PromMetrics prom; public: State(std::optional metricsAddrOpt);