Skip to content

Commit

Permalink
[OMON-406] Add example for Pull Client (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Jan 17, 2023
1 parent 792f4e3 commit 89d4273
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ set(EXAMPLES

if(RdKafka_FOUND)
list(APPEND EXAMPLES "examples/11-KafkaToWebsocket.cxx")
list(APPEND EXAMPLES "examples/13-PullClient.cxx")
endif()

foreach (example ${EXAMPLES})
Expand Down
27 changes: 27 additions & 0 deletions examples/13-PullClient.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
///
/// \file 13-PullClient.cxx
/// \author Adam Wegrzynek <[email protected]>
///

#include "Monitoring/MonitoringFactory.h"

using namespace o2::monitoring;

int main()
{
/// List of topics to subscribe
std::vector<std::string> topics = {"cru.link_status"};
/// Connect to server
auto client = MonitoringFactory::GetPullClient("adam-kafka:9092", topics);
for (;;) {
auto metrics = client->pull();
if (!metrics.empty()) {
for (auto& metric : metrics) {
/// metric.first => topic name; metric.second => metric itself as string
/// metric sample: link,serialId=983,endpoint=1,CRU=1,id=11,type=CRU pciAddress="b0:00.0",status=1i 1673940809860009855
std::cout << metric.second << std::endl;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

0 comments on commit 89d4273

Please sign in to comment.