-
Notifications
You must be signed in to change notification settings - Fork 314
/
beast_exposer.cc
55 lines (42 loc) · 1.66 KB
/
beast_exposer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "prometheus/beast_exposer.h"
#include <chrono>
#include <string>
#include <thread>
#include <boost/asio.hpp>
#include "beast_listener.h"
#include "beast_shared_state.h"
namespace prometheus {
BeastExposer::BeastExposer(const std::string host, const std::uint16_t port, const std::string& uri, const std::size_t num_threads)
: ioc_(new boost::asio::io_context(num_threads)),
exposer_registry_(std::make_shared<Registry>()),
//metrics_handler_(new detail::MetricsHandler{collectables_, *exposer_registry_}),
uri_(uri) {
RegisterCollectable(exposer_registry_);
//
auto& ioc = *ioc_;
auto const address = boost::asio::ip::make_address(host);
boost::asio::ip::tcp::endpoint endpoint{address, port};
auto shared_state = std::make_shared<BeastSharedState>(uri, collectables_);
// Create and launch a listening port
std::make_shared<BeastListener>(
ioc,
endpoint,
shared_state)->run();
// Run the I/O service on the requested number of threads
worker_.reserve(num_threads - 1);
for(auto i = num_threads; i > 0; --i) {
worker_.emplace_back(
[&ioc]
{
ioc.run();
});
}
//server_->addHandler(uri, metrics_handler_.get());
}
BeastExposer::~BeastExposer() { //server_->removeHandler(uri_);
}
void BeastExposer::RegisterCollectable(
const std::weak_ptr<Collectable>& collectable) {
collectables_.push_back(collectable);
}
} // namespace prometheus