15 #include <openssl/x509.h>
16 #include <openssl/pem.h>
18 #define UPDATE_STATISTIC(x) \
21 #define UPDATE_AND_OUTPUT_STATISTIC(x) \
22 os << "\"" #x "\":" << (x-m_ ## x) << ", "; \
28 #define HOST_NAME_MAX 128
31 #define JOB_UNIQUE_ID_ENV "CRAB_UNIQUE_JOB_ID"
32 #define JOB_UNIQUE_ID_ENV_V2 "DashboardJobId"
34 using namespace edm::storage;
37 m_read_single_operations(0),
38 m_read_single_bytes(0),
39 m_read_single_square(0),
40 m_read_vector_operations(0),
41 m_read_vector_bytes(0),
42 m_read_vector_square(0),
43 m_read_vector_count_sum(0),
44 m_read_vector_count_square(0),
45 m_start_time(time(
NULL))
51 ssize_t read_single_operations = 0;
52 ssize_t read_single_bytes = 0;
53 ssize_t read_single_square = 0;
54 ssize_t read_vector_operations = 0;
55 ssize_t read_vector_bytes = 0;
56 ssize_t read_vector_square = 0;
57 ssize_t read_vector_count_sum = 0;
58 ssize_t read_vector_count_square = 0;
60 for (StorageAccount::StorageStats::const_iterator
i = stats.begin ();
i != stats.end(); ++
i) {
61 if (
i->first ==
token.value()) {
64 for (StorageAccount::OperationStats::const_iterator
j =
i->second.begin();
j !=
i->second.end(); ++
j) {
66 read_vector_operations +=
j->second.attempts;
67 read_vector_bytes +=
j->second.amount;
68 read_vector_count_square +=
j->second.vector_square;
69 read_vector_square +=
j->second.amount_square;
70 read_vector_count_sum +=
j->second.vector_count;
72 read_single_operations +=
j->second.attempts;
73 read_single_bytes +=
j->second.amount;
74 read_single_square +=
j->second.amount_square;
78 int64_t single_op_count = read_single_operations - m_read_single_operations;
79 if (single_op_count > 0) {
80 double single_sum = read_single_bytes-m_read_single_bytes;
81 double single_average = single_sum/
static_cast<double>(single_op_count);
82 os <<
"\"read_single_sigma\":" <<
sqrt((static_cast<double>(read_single_square-m_read_single_square) - single_average*single_average*single_op_count)/static_cast<double>(single_op_count)) <<
", ";
83 os <<
"\"read_single_average\":" << single_average <<
", ";
85 m_read_single_square = read_single_square;
86 int64_t vector_op_count = read_vector_operations - m_read_vector_operations;
87 if (vector_op_count > 0) {
88 double vector_average =
static_cast<double>(read_vector_bytes-m_read_vector_bytes)/static_cast<double>(vector_op_count);
89 os <<
"\"read_vector_average\":" << vector_average <<
", ";
90 os <<
"\"read_vector_sigma\":" <<
sqrt((static_cast<double>(read_vector_square-m_read_vector_square) - vector_average*vector_average*vector_op_count)/static_cast<double>(vector_op_count)) <<
", ";
91 double vector_count_average =
static_cast<double>(read_vector_count_sum-m_read_vector_count_sum)/static_cast<double>(vector_op_count);
92 os <<
"\"read_vector_count_average\":" << vector_count_average <<
", ";
93 os <<
"\"read_vector_count_sigma\":" <<
sqrt((static_cast<double>(read_vector_count_square-m_read_vector_count_square) - vector_count_average*vector_count_average*vector_op_count)/static_cast<double>(vector_op_count)) <<
", ";
95 m_read_vector_square = read_vector_square;
96 m_read_vector_count_square = read_vector_count_square;
97 m_read_vector_count_sum = read_vector_count_sum;
99 os <<
"\"read_bytes\":" << (read_vector_bytes + read_single_bytes - m_read_vector_bytes - m_read_single_bytes) <<
", ";
100 os <<
"\"read_bytes_at_close\":" << (read_vector_bytes + read_single_bytes - m_read_vector_bytes - m_read_single_bytes) <<
", ";
108 os <<
"\"start_time\":" << m_start_time <<
", ";
109 m_start_time = time(
NULL);
111 os <<
"\"end_time\":" << m_start_time;
142 size_t dot_pos = servername.find(
".");
145 if (dot_pos == std::string::npos) {
146 serverhost = servername.substr(0, servername.find(
":"));
147 serverdomain =
"unknown";
149 serverhost = servername.substr(0, dot_pos);
150 serverdomain = servername.substr(dot_pos+1, servername.find(
":")-dot_pos-1);
151 if (serverdomain.empty()) {
152 serverdomain =
"unknown";
182 if (info && info->size() && (
m_userdn !=
"unknown") && (
183 (info->find(
"dn") == info->end()) ||
184 (info->find(
"nodn") != info->end()))
193 for (
const struct addrinfo *address = addresses; address !=
nullptr; address = address->ai_next) {
194 int sock = socket(address->ai_family, address->ai_socktype, address->ai_protocol);
198 if (sendto(sock, results.c_str(), results.size(), 0, address->ai_addr, address->ai_addrlen) >= 0) {
216 if (dot_pos == std::string::npos) {
226 std::ostringstream os;
230 if (!siteName.empty()) {
231 os <<
"\"site_name\":\"" << siteName <<
"\", ";
234 os <<
"\"fallback\": true, ";
244 os <<
"\"user_dn\":\"" <<
m_userdn <<
"\", ";
247 os <<
"\"server_host\":\"" << serverhost <<
"\", ";
248 os <<
"\"server_domain\":\"" << serverdomain <<
"\", ";
250 os <<
"\"file_lfn\":\"" <<
m_filelfn <<
"\", ";
255 os <<
"\"app_info\":\"" << jobId <<
"\", ";
259 os <<
"\"file_size\":" <<
m_size <<
", ";
284 static X509 *
findEEC(STACK_OF(X509) * certstack) {
285 int depth = sk_X509_num(certstack);
290 char *priorsubject =
nullptr;
291 char *subject =
nullptr;
292 X509 *x509cert = sk_X509_value(certstack, idx);
293 for (; x509cert && idx>0; idx--) {
294 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),0,0);
295 if (subject && priorsubject && (strncmp(subject, priorsubject, strlen(subject)) != 0)) {
298 x509cert = sk_X509_value(certstack, idx);
300 OPENSSL_free(subject);
305 OPENSSL_free(subject);
314 STACK_OF(X509) *certs =
nullptr;
315 char *subject =
nullptr;
316 unsigned char *
data =
nullptr;
317 char *header =
nullptr;
318 char *
name =
nullptr;
321 if((biof = BIO_new_file(filename.c_str(),
"r"))) {
323 certs = sk_X509_new_null();
324 bool encountered_error =
false;
325 while ((!encountered_error) && (!BIO_eof(biof)) && PEM_read_bio(biof, &name, &header, &data, &len)) {
326 if (strcmp(name, PEM_STRING_X509) == 0 || strcmp(name, PEM_STRING_X509_OLD) == 0) {
327 X509 * tmp_cert =
nullptr;
330 const unsigned char *
p;
332 tmp_cert = d2i_X509(&tmp_cert, &p, len);
334 sk_X509_push(certs, tmp_cert);
336 encountered_error =
true;
339 if (data) { OPENSSL_free(data); data =
nullptr;}
340 if (header) { OPENSSL_free(header); header =
nullptr;}
341 if (name) { OPENSSL_free(name); name =
nullptr;}
343 X509 *x509cert =
nullptr;
344 if (!encountered_error && sk_X509_num(certs)) {
348 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),0,0);
352 sk_X509_pop_free(certs, X509_free);
358 OPENSSL_free(subject);
367 char *
filename = getenv(
"X509_USER_PROXY");
371 std::stringstream
ss;
372 ss <<
"/tmp/x509up_u" << geteuid();
void setCurrentServer(const std::string &servername)
FileStatistics m_filestats
static const StorageStats & summary(void)
std::atomic< ssize_t > m_size
void filePreCloseEvent(std::string const &lfn, bool usedFallback)
static bool getX509Subject(std::string &)
static X509 * findEEC(STACK_OF(X509)*certstack)
tbb::concurrent_unordered_map< int, OperationStats > StorageStats
std::string m_serverdomain
#define JOB_UNIQUE_ID_ENV_V2
static StorageClassToken tokenForStorageClassName(std::string const &iName)
#define JOB_UNIQUE_ID_ENV
void determineHostnames(void)
void fillUDP(const std::string &, bool, std::string &)
void watchPreCloseFile(PreCloseFile::slot_type const &iSlot)
void fillUDP(std::ostringstream &os)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
void setSize(size_t size)
virtual std::string const & siteName(void) const =0
static const char * getJobID()
std::string m_clientdomain
StatisticsSenderService(edm::ParameterSet const &pset, edm::ActivityRegistry &ar)
virtual struct addrinfo const * statisticsDestination() const =0
static bool getX509SubjectFromFile(const std::string &filename, std::string &result)
tuple size
Write out results.
virtual std::set< std::string > const * statisticsInfo() const =0
#define UPDATE_AND_OUTPUT_STATISTIC(x)