Skip to content

Commit a130bc4

Browse files
committed
[status] Add monitoring
1 parent 3dbb409 commit a130bc4

File tree

2 files changed

+70
-65
lines changed

2 files changed

+70
-65
lines changed

src/CommandLineUtilities/Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Program : public AliceO2::Common::Program
6363
private:
6464
InfoLogger::InfoLogger mLogger;
6565
InfoLogger::InfoLogger::Severity mLogLevel = InfoLogger::InfoLogger::Severity::Info;
66-
66+
6767
const std::string MONITORING_URI = "stdout://";
6868
};
6969

src/CommandLineUtilities/ProgramStatus.cxx

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <boost/property_tree/ptree.hpp>
2828
#include <boost/property_tree/json_parser.hpp>
2929

30+
#include "Monitoring/MonitoringFactory.h"
31+
using namespace o2::monitoring;
32+
3033
using namespace AliceO2::roc::CommandLineUtilities;
3134
using namespace AliceO2::roc;
3235
namespace pt = boost::property_tree;
@@ -39,8 +42,9 @@ class ProgramStatus : public Program
3942
{
4043
return { "Status", "Return current RoC configuration status",
4144
"roc-status --id 42:00.0\n"
42-
"roc-status --id 42:00.0 --json"
43-
"roc-status --id 42:00.0 --csv" };
45+
"roc-status --id 42:00.0 --json\n"
46+
"roc-status --id 42:00.0 --csv\n"
47+
"roc-status --id 42:00.0 --monitoring\n" };
4448
}
4549

4650
virtual void addOptions(boost::program_options::options_description& options)
@@ -52,6 +56,9 @@ class ProgramStatus : public Program
5256
options.add_options()("csv-out",
5357
po::bool_switch(&mOptions.csvOut),
5458
"Toggle csv-formatted output");
59+
options.add_options()("monitoring",
60+
po::bool_switch(&mOptions.monitoring),
61+
"Toggle monitoring metrics sending");
5562
}
5663

5764
virtual void run(const boost::program_options::variables_map& map)
@@ -67,7 +74,16 @@ class ProgramStatus : public Program
6774
pt::ptree root;
6875

6976
auto cardId = Options::getOptionCardId(map);
70-
auto cardType = RocPciDevice(cardId).getCardDescriptor().cardType;
77+
auto cardIdString = Options::getOptionCardIdString(map);
78+
auto card = RocPciDevice(cardId).getCardDescriptor();
79+
auto cardType = card.cardType;
80+
81+
// Monitoring instance to send metrics
82+
std::unique_ptr<Monitoring> monitoring;
83+
if (mOptions.monitoring) {
84+
monitoring = MonitoringFactory::Get(getMonitoringUri());
85+
monitoring->addGlobalTag(tags::Key::Subsystem, tags::Value::CRU);
86+
}
7187

7288
if (cardType == CardType::type::Crorc) {
7389
formatHeader = " %-9s %-8s %-19s\n";
@@ -88,55 +104,32 @@ class ProgramStatus : public Program
88104
auto crorcBar0 = std::dynamic_pointer_cast<CrorcBar>(bar0);
89105

90106
Crorc::ReportInfo reportInfo = crorcBar0->report();
107+
std::string qsfpEnabled = reportInfo.qsfpEnabled ? "Enabled" : "Disabled";
108+
std::string offset = reportInfo.dynamicOffset ? "Dynamic" : "Fixed";
109+
std::string timeFrameDetectionEnabled = reportInfo.timeFrameDetectionEnabled ? "Enabled" : "Disabled";
91110

92111
/* GENERAL PARAMETERS */
93-
if (mOptions.jsonOut) {
94-
if (reportInfo.qsfpEnabled) {
95-
root.put("qsfp", "Enabled");
96-
} else {
97-
root.put("qsfp", "Disabled");
98-
}
99-
100-
if (reportInfo.dynamicOffset) {
101-
root.put("offset", "Dynamic");
102-
} else {
103-
root.put("offset", "Fixed");
104-
}
105-
106-
if (reportInfo.timeFrameDetectionEnabled) {
107-
root.put("timeFrameDetection", "Enabled");
108-
} else {
109-
root.put("timeFrameDetection", "Disabled");
110-
}
111-
112+
if (mOptions.monitoring) {
113+
monitoring->send(Metric{ cardIdString, "CRORC" }
114+
.addValue(qsfpEnabled, "qsfp")
115+
.addValue(offset, "offset")
116+
.addValue(timeFrameDetectionEnabled, "timeFrameDetection")
117+
.addValue(reportInfo.timeFrameLength, "timeFrameLength"));
118+
} else if (mOptions.jsonOut) {
119+
root.put("qsfp", qsfpEnabled);
120+
root.put("offset", offset);
121+
root.put("timeFrameDetection", timeFrameDetectionEnabled);
112122
root.put("timeFrameLength", reportInfo.timeFrameLength);
113123
} else if (mOptions.csvOut) {
114-
auto csvLine = std::string(",,,") + (reportInfo.qsfpEnabled ? "Enabled" : "Disabled") + "," + (reportInfo.dynamicOffset ? "Dynamic" : "Fixed") + "," + (reportInfo.timeFrameDetectionEnabled ? "Enabled" : "Disabled") + "," + std::to_string(reportInfo.timeFrameLength) + "\n";
124+
auto csvLine = std::string(",,,") + qsfpEnabled + "," + offset + "," + timeFrameDetectionEnabled + "," + std::to_string(reportInfo.timeFrameLength) + "\n";
115125
std::cout << csvLine;
116126
} else {
117127
std::cout << "-----------------------------" << std::endl;
118-
if (reportInfo.qsfpEnabled) {
119-
std::cout << "QSFP enabled | ";
120-
} else {
121-
std::cout << "QSFP disabled | ";
122-
}
123-
124-
if (reportInfo.dynamicOffset) {
125-
std::cout << "Dynamic offset" << std::endl;
126-
} else {
127-
std::cout << "Fixed offset" << std::endl;
128-
}
129-
128+
std::cout << "QSFP " << qsfpEnabled << std::endl;
129+
std::cout << offset << " offset" << std::endl;
130130
std::cout << "-----------------------------" << std::endl;
131-
132-
if (reportInfo.timeFrameDetectionEnabled) {
133-
std::cout << "Time Frame Detection enabled" << std::endl;
134-
} else {
135-
std::cout << "Time Frame Detection disabled" << std::endl;
136-
}
137-
131+
std::cout << "Time Frame Detection " << timeFrameDetectionEnabled << std::endl;
138132
std::cout << "Time Frame Length: " << reportInfo.timeFrameLength << std::endl;
139-
140133
std::cout << "-----------------------------" << std::endl;
141134
}
142135

@@ -148,7 +141,11 @@ class ProgramStatus : public Program
148141
std::string linkStatus = link.status == Crorc::LinkStatus::Up ? "UP" : "DOWN";
149142
float opticalPower = link.opticalPower;
150143

151-
if (mOptions.jsonOut) {
144+
if (mOptions.monitoring) {
145+
monitoring->send(Metric{ id, "link" }
146+
.addValue(linkStatus, "status")
147+
.addValue(opticalPower, "opticalPower"));
148+
} else if (mOptions.jsonOut) {
152149
pt::ptree linkNode;
153150

154151
// add kv pairs for this card
@@ -177,7 +174,7 @@ class ProgramStatus : public Program
177174
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2);
178175

179176
if (mOptions.csvOut) {
180-
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW),Clock,Offset\n";
177+
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW),Clock,Offset,UserLogic\n";
181178
std::cout << csvHeader;
182179
} else if (!mOptions.jsonOut) {
183180
table << lineFat << header << lineThin;
@@ -186,31 +183,27 @@ class ProgramStatus : public Program
186183
Cru::ReportInfo reportInfo = cruBar2->report();
187184

188185
std::string clock = (reportInfo.ttcClock == 0 ? "TTC" : "Local");
186+
std::string offset = (reportInfo.dynamicOffset ? "Dynamic" : "Fixed");
187+
std::string userLogic = (reportInfo.userLogicEnabled ? "Enabled" : "Disabled");
189188

190189
/* GENERAL PARAMETERS */
191-
if (mOptions.jsonOut) {
190+
if (mOptions.monitoring) {
191+
monitoring->send(Metric{ cardIdString, "CRU" }
192+
.addValue(clock, "clock")
193+
.addValue(offset, "offset")
194+
.addValue(userLogic, "userLogic"));
195+
} else if (mOptions.jsonOut) {
192196
root.put("clock", clock);
193-
if (reportInfo.dynamicOffset) {
194-
root.put("offset", "Dynamic");
195-
} else {
196-
root.put("offset", "Fixed");
197-
}
197+
root.put("offset", offset);
198+
root.put("userLogic", userLogic);
198199
} else if (mOptions.csvOut) {
199-
auto csvLine = ",,,,,,,,,," + clock + "," + (reportInfo.dynamicOffset ? "Dynamic" : "Fixed") + "\n";
200+
auto csvLine = ",,,,,,,,,," + clock + "," + offset + "," + userLogic + "\n";
200201
std::cout << csvLine;
201202
} else {
202203
std::cout << "----------------------------" << std::endl;
203204
std::cout << clock << " clock | ";
204-
if (reportInfo.dynamicOffset) {
205-
std::cout << "Dynamic offset" << std::endl;
206-
} else {
207-
std::cout << "Fixed offset" << std::endl;
208-
}
209-
if (reportInfo.userLogicEnabled) {
210-
std::cout << "User Logic Enabled" << std::endl;
211-
} else {
212-
std::cout << "User Logic Disabled" << std::endl;
213-
}
205+
std::cout << offset << " offset" << std::endl;
206+
std::cout << "User Logic " << userLogic << std::endl;
214207
std::cout << "----------------------------" << std::endl;
215208
}
216209

@@ -255,7 +248,18 @@ class ProgramStatus : public Program
255248

256249
float opticalPower = link.opticalPower;
257250

258-
if (mOptions.jsonOut) {
251+
if (mOptions.monitoring) {
252+
monitoring->send(Metric{ globalId, "link" }
253+
.addValue(gbtTxRxMode, "gbtMode")
254+
.addValue(loopback, "loopback")
255+
.addValue(gbtMux, "gbtMux")
256+
.addValue(datapathMode, "datapathMode")
257+
.addValue(enabled, "datapath")
258+
.addValue(rxFreq, "rxFreq")
259+
.addValue(txFreq, "txFreq")
260+
.addValue(linkStatus, "status")
261+
.addValue(opticalPower, "opticalPower"));
262+
} else if (mOptions.jsonOut) {
259263
pt::ptree linkNode;
260264

261265
// add kv pairs for this card
@@ -287,7 +291,7 @@ class ProgramStatus : public Program
287291

288292
if (mOptions.jsonOut) {
289293
pt::write_json(std::cout, root);
290-
} else if (!mOptions.csvOut) {
294+
} else if (!mOptions.csvOut && !mOptions.monitoring) {
291295
auto lineFat = std::string(header.length(), '=') + '\n';
292296
table << lineFat;
293297
std::cout << table.str();
@@ -298,6 +302,7 @@ class ProgramStatus : public Program
298302
struct OptionsStruct {
299303
bool jsonOut = false;
300304
bool csvOut = false;
305+
bool monitoring = false;
301306
} mOptions;
302307
};
303308

0 commit comments

Comments
 (0)