Skip to content

Commit 89d4273

Browse files
authored
[OMON-406] Add example for Pull Client (#311)
1 parent 792f4e3 commit 89d4273

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ set(EXAMPLES
237237

238238
if(RdKafka_FOUND)
239239
list(APPEND EXAMPLES "examples/11-KafkaToWebsocket.cxx")
240+
list(APPEND EXAMPLES "examples/13-PullClient.cxx")
240241
endif()
241242

242243
foreach (example ${EXAMPLES})

examples/13-PullClient.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
///
2+
/// \file 13-PullClient.cxx
3+
/// \author Adam Wegrzynek <[email protected]>
4+
///
5+
6+
#include "Monitoring/MonitoringFactory.h"
7+
8+
using namespace o2::monitoring;
9+
10+
int main()
11+
{
12+
/// List of topics to subscribe
13+
std::vector<std::string> topics = {"cru.link_status"};
14+
/// Connect to server
15+
auto client = MonitoringFactory::GetPullClient("adam-kafka:9092", topics);
16+
for (;;) {
17+
auto metrics = client->pull();
18+
if (!metrics.empty()) {
19+
for (auto& metric : metrics) {
20+
/// metric.first => topic name; metric.second => metric itself as string
21+
/// metric sample: link,serialId=983,endpoint=1,CRU=1,id=11,type=CRU pciAddress="b0:00.0",status=1i 1673940809860009855
22+
std::cout << metric.second << std::endl;
23+
}
24+
}
25+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
26+
}
27+
}

0 commit comments

Comments
 (0)