]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/pull/src/exposer.cc
1 #include "prometheus/exposer.h"
8 #include "CivetServer.h"
10 #include "prometheus/detail/future_std.h"
12 namespace prometheus
{
14 Exposer::Exposer(const std::string
& bind_address
, const std::size_t num_threads
,
15 const CivetCallbacks
* callbacks
)
17 std::vector
<std::string
>{"listening_ports", bind_address
,
18 "num_threads", std::to_string(num_threads
)},
21 Exposer::Exposer(std::vector
<std::string
> options
,
22 const CivetCallbacks
* callbacks
)
23 : server_(detail::make_unique
<CivetServer
>(std::move(options
), callbacks
)) {
26 Exposer::~Exposer() = default;
28 void Exposer::RegisterCollectable(const std::weak_ptr
<Collectable
>& collectable
,
29 const std::string
& uri
) {
30 std::lock_guard
<std::mutex
> lock
{mutex_
};
31 auto& endpoint
= GetEndpointForUri(uri
);
32 endpoint
.RegisterCollectable(collectable
);
35 void Exposer::RegisterAuth(
36 std::function
<bool(const std::string
&, const std::string
&)> authCB
,
37 const std::string
& realm
, const std::string
& uri
) {
38 std::lock_guard
<std::mutex
> lock
{mutex_
};
39 auto& endpoint
= GetEndpointForUri(uri
);
40 endpoint
.RegisterAuth(std::move(authCB
), realm
);
43 void Exposer::RemoveCollectable(const std::weak_ptr
<Collectable
>& collectable
,
44 const std::string
& uri
) {
45 std::lock_guard
<std::mutex
> lock
{mutex_
};
46 auto& endpoint
= GetEndpointForUri(uri
);
47 endpoint
.RemoveCollectable(collectable
);
50 std::vector
<int> Exposer::GetListeningPorts() const {
51 return server_
->getListeningPorts();
54 detail::Endpoint
& Exposer::GetEndpointForUri(const std::string
& uri
) {
55 auto sameUri
= [uri
](const std::unique_ptr
<detail::Endpoint
>& endpoint
) {
56 return endpoint
->GetURI() == uri
;
58 auto it
= std::find_if(std::begin(endpoints_
), std::end(endpoints_
), sameUri
);
59 if (it
!= std::end(endpoints_
)) {
63 endpoints_
.emplace_back(detail::make_unique
<detail::Endpoint
>(*server_
, uri
));
64 return *endpoints_
.back().get();
67 } // namespace prometheus