Skip to content

Commit 2daddd2

Browse files
authored
[OMON-647] Scrape AliECS endpoint for inactive tasks (#330)
1 parent 9f7aa55 commit 2daddd2

File tree

3 files changed

+651
-36
lines changed

3 files changed

+651
-36
lines changed

CMakeLists.txt

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -303,44 +303,48 @@ endif()
303303
# gRPC
304304
####################################
305305
if(Protobuf_FOUND AND gRPC_FOUND)
306-
set(PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proto/odc.proto)
307-
get_filename_component(PROTO_OUTPUT_NAME ${PROTO_FILE} NAME_WE)
308-
get_filename_component(PROTO_FILE_PREFIX ${PROTO_FILE} PATH)
309-
set(PROTO_CPP_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROTO_OUTPUT_NAME}.pb.cc)
310-
set(GRPC_CPP_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROTO_OUTPUT_NAME}.grpc.pb.cc)
311-
312-
add_custom_command(
313-
OUTPUT "${PROTO_CPP_OUTPUT}"
314-
COMMAND protobuf::protoc
315-
ARGS --proto_path ${PROTO_FILE_PREFIX}
316-
--cpp_out ${CMAKE_CURRENT_BINARY_DIR}
317-
${PROTO_OUTPUT_NAME}.proto
318-
DEPENDS ${PROTO_FILE}
319-
COMMENT "Running protoc on ${PROTO_FILE}"
320-
VERBATIM)
321-
322-
add_custom_command(
323-
OUTPUT "${GRPC_CPP_OUTPUT}"
324-
COMMAND protobuf::protoc
325-
ARGS --proto_path ${PROTO_FILE_PREFIX}
326-
--grpc_out=${CMAKE_CURRENT_BINARY_DIR}
327-
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
328-
${PROTO_OUTPUT_NAME}.proto
329-
DEPENDS ${PROTO_FILE}
330-
COMMENT "Running protoc/gRPC on ${PROTO_FILE}"
331-
VERBATIM)
306+
set(PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/proto/odc.proto ${CMAKE_CURRENT_SOURCE_DIR}/proto/o2control.proto)
307+
set(EXAMPLES examples/15-ODC.cxx examples/16-AliECS.cxx)
308+
foreach(PROTO_FILE example IN ZIP_LISTS PROTO_FILES EXAMPLES)
309+
get_filename_component(PROTO_OUTPUT_NAME ${PROTO_FILE} NAME_WE)
310+
get_filename_component(PROTO_FILE_PREFIX ${PROTO_FILE} PATH)
311+
set(PROTO_CPP_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROTO_OUTPUT_NAME}.pb.cc)
312+
set(GRPC_CPP_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROTO_OUTPUT_NAME}.grpc.pb.cc)
313+
314+
add_custom_command(
315+
OUTPUT "${PROTO_CPP_OUTPUT}"
316+
COMMAND protobuf::protoc
317+
ARGS --proto_path ${PROTO_FILE_PREFIX}
318+
--cpp_out ${CMAKE_CURRENT_BINARY_DIR}
319+
${PROTO_OUTPUT_NAME}.proto
320+
DEPENDS ${PROTO_FILE}
321+
COMMENT "Running protoc on ${PROTO_FILE}"
322+
VERBATIM)
323+
324+
add_custom_command(
325+
OUTPUT "${GRPC_CPP_OUTPUT}"
326+
COMMAND protobuf::protoc
327+
ARGS --proto_path ${PROTO_FILE_PREFIX}
328+
--grpc_out=${CMAKE_CURRENT_BINARY_DIR}
329+
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
330+
${PROTO_OUTPUT_NAME}.proto
331+
DEPENDS ${PROTO_FILE}
332+
COMMENT "Running protoc/gRPC on ${PROTO_FILE}"
333+
VERBATIM)
332334

333-
set(example examples/15-ODC.cxx)
334-
get_filename_component(example_name ${example} NAME)
335-
string(REGEX REPLACE ".cxx" "" example_name ${example_name})
336-
add_executable(${example_name} ${example} ${PROTO_CPP_OUTPUT} ${GRPC_CPP_OUTPUT})
337-
target_link_libraries(${example_name} PRIVATE
338-
gRPC::grpc++
339-
protobuf::libprotobuf
340-
Boost::program_options
341-
)
342-
target_include_directories(${example_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
335+
get_filename_component(example_name ${example} NAME)
336+
string(REGEX REPLACE ".cxx" "" example_name ${example_name})
337+
add_executable(${example_name} ${example} ${PROTO_CPP_OUTPUT} ${GRPC_CPP_OUTPUT})
338+
target_link_libraries(${example_name} PRIVATE
339+
Monitoring
340+
gRPC::grpc++
341+
protobuf::libprotobuf
342+
Boost::program_options
343+
)
344+
target_include_directories(${example_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
345+
endforeach()
343346
set_target_properties(15-ODC PROPERTIES OUTPUT_NAME "o2-monitoring-odc")
347+
set_target_properties(16-AliECS PROPERTIES OUTPUT_NAME "o2-monitoring-aliecs-tasks")
344348
endif()
345349

346350
####################################

examples/16-AliECS.cxx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
///
2+
/// \file 16-AliECS.cxx
3+
/// \author Adam Wegrzynek <[email protected]>
4+
///
5+
6+
#include <iostream>
7+
#include <grpc++/grpc++.h>
8+
#include "o2control.grpc.pb.h"
9+
#include "helpers/HttpConnection.h"
10+
#include <boost/program_options.hpp>
11+
#include <thread>
12+
#include <regex>
13+
#include "../src/Backends/InfluxDB.h"
14+
#include "../src/Transports/HTTP.h"
15+
#include "../src/MonLogger.h"
16+
17+
using o2::monitoring::MonLogger;
18+
using grpc::Channel;
19+
using grpc::ClientContext;
20+
using grpc::Status;
21+
22+
using o2control::EnvironmentInfo;
23+
using namespace o2::monitoring;
24+
25+
class AliEcsClient {
26+
public:
27+
AliEcsClient(std::shared_ptr<Channel> channel) : mStub(o2control::Control::NewStub(channel)) {}
28+
void sendRunDetails(const auto& influxBackend) {
29+
o2control::GetEnvironmentsRequest request;
30+
request.set_showall(false);
31+
request.set_showtaskinfos(false);
32+
o2control::GetEnvironmentsReply reply;
33+
ClientContext context;
34+
Status status = mStub->GetEnvironments(&context, request, &reply);
35+
if (status.ok()) {
36+
MonLogger::Get() << "Status call OK" << MonLogger::End();
37+
for (int i = 0; i < reply.environments_size(); i++) {
38+
if (reply.environments(i).currentrunnumber() > 1) {
39+
MonLogger::Get() << "Env ID" << reply.environments(i).id() << MonLogger::End();
40+
auto metric = Metric{"tasks"};
41+
metric.addValue(reply.environments(i).numberofactivetasks(), "active").addValue(reply.environments(i).numberofinactivetasks(), "inactive");
42+
influxBackend->sendWithRun(metric, reply.environments(i).id(), std::to_string(reply.environments(i).currentrunnumber()));
43+
}
44+
}
45+
} else {
46+
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
47+
}
48+
}
49+
private:
50+
std::unique_ptr<o2control::Control::Stub> mStub;
51+
};
52+
53+
54+
int main(int argc, char* argv[]) {
55+
boost::program_options::options_description desc("Program options");
56+
desc.add_options()
57+
("aliecs-host", boost::program_options::value<std::string>()->required(), "AliECS hostname")
58+
("aliecs-port", boost::program_options::value<unsigned short>()->required(), "AliECS port")
59+
("influxdb-url", boost::program_options::value<std::string>()->required(), "InfluxDB hostname")
60+
("influxdb-token", boost::program_options::value<std::string>()->required(), "InfluxDB token")
61+
("influxdb-org", boost::program_options::value<std::string>()->default_value("cern"), "InfluxDB organisation")
62+
("influxdb-bucket", boost::program_options::value<std::string>()->default_value("aliecs"), "InfluxDB bucket");
63+
boost::program_options::variables_map vm;
64+
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
65+
boost::program_options::notify(vm);
66+
MonLogger::mLoggerSeverity = o2::monitoring::Severity::Debug;
67+
MonLogger::Get() << "Connected to AliECS server: " << vm["aliecs-host"].as<std::string>() << ":" << vm["aliecs-port"].as<unsigned short>() << MonLogger::End();
68+
grpc::ChannelArguments args;
69+
args.SetMaxReceiveMessageSize(20*1024*1024);
70+
AliEcsClient client(grpc::CreateCustomChannel(
71+
vm["aliecs-host"].as<std::string>() + ":" + std::to_string(vm["aliecs-port"].as<unsigned short>()),
72+
grpc::InsecureChannelCredentials(),
73+
args
74+
));
75+
auto httpTransport = std::make_unique<transports::HTTP>(
76+
vm["influxdb-url"].as<std::string>() + "/api/v2/write?" +
77+
"org=" + vm["influxdb-org"].as<std::string>() + "&" +
78+
"bucket=" + vm["influxdb-bucket"].as<std::string>()
79+
);
80+
httpTransport->addHeader("Authorization: Token " + vm["influxdb-token"].as<std::string>());
81+
auto influxdbBackend = std::make_unique<backends::InfluxDB>(std::move(httpTransport));
82+
for (;;) {
83+
client.sendRunDetails(influxdbBackend);
84+
std::this_thread::sleep_for(std::chrono::seconds(15));
85+
}
86+
}

0 commit comments

Comments
 (0)