hydra-queue-runer: split metrics functionality into its own function

This commit is contained in:
Cole Helbling 2022-03-29 10:55:28 -07:00
parent 928b3b8268
commit 4789eba92c
2 changed files with 21 additions and 11 deletions

View file

@ -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) void State::run(BuildID buildOne)
{ {
/* Can't be bothered to shut down cleanly. Goodbye! */ /* Can't be bothered to shut down cleanly. Goodbye! */
@ -762,17 +780,7 @@ void State::run(BuildID buildOne)
if (!lock) if (!lock)
throw Error("hydra-queue-runner is already running"); throw Error("hydra-queue-runner is already running");
std::cout << "Starting the Prometheus exporter on port " << metricsPort << std::endl; std::thread(&State::runMetricsExporter, this).detach();
/* 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;
Store::Params localParams; Store::Params localParams;
localParams["max-connections"] = "16"; localParams["max-connections"] = "16";

View file

@ -549,6 +549,8 @@ private:
void addRoot(const nix::StorePath & storePath); void addRoot(const nix::StorePath & storePath);
void runMetricsExporter();
public: public:
void showStatus(); void showStatus();