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" 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),
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;
79 if (single_op_count > 0) {
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 <<
", ";
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)) <<
", ";
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 auto close_del = [](
int* iSocket) { close(*iSocket); };
199 std::unique_ptr<int,decltype(close_del)> guard(&sock, close_del);
200 if (sendto(sock, results.c_str(), results.size(), 0, address->ai_addr, address->ai_addrlen) >= 0) {
218 if (dot_pos == std::string::npos) {
228 std::ostringstream os;
232 if (!siteName.empty()) {
233 os <<
"\"site_name\":\"" << siteName <<
"\", ";
236 os <<
"\"fallback\": true, ";
246 os <<
"\"user_dn\":\"" <<
m_userdn <<
"\", ";
249 os <<
"\"server_host\":\"" << serverhost <<
"\", ";
250 os <<
"\"server_domain\":\"" << serverdomain <<
"\", ";
252 os <<
"\"file_lfn\":\"" <<
m_filelfn <<
"\", ";
257 os <<
"\"app_info\":\"" << jobId <<
"\", ";
261 os <<
"\"file_size\":" <<
m_size <<
", ";
287 int depth = sk_X509_num(certstack);
292 char *priorsubject =
nullptr;
293 char *subject =
nullptr;
294 X509 *x509cert = sk_X509_value(certstack, idx);
295 for (; x509cert && idx>0; idx--) {
296 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),0,0);
297 if (subject && priorsubject && (strncmp(subject, priorsubject, strlen(subject)) != 0)) {
300 x509cert = sk_X509_value(certstack, idx);
302 OPENSSL_free(subject);
307 OPENSSL_free(subject);
316 STACK_OF(
X509) *certs =
nullptr;
317 char *subject =
nullptr;
318 unsigned char *
data =
nullptr;
320 char *
name =
nullptr;
323 if((biof = BIO_new_file(filename.c_str(),
"r"))) {
325 certs = sk_X509_new_null();
326 bool encountered_error =
false;
327 while ((!encountered_error) && (!BIO_eof(biof)) && PEM_read_bio(biof, &name, &header, &data, &len)) {
328 if (strcmp(name, PEM_STRING_X509) == 0 || strcmp(name, PEM_STRING_X509_OLD) == 0) {
329 X509 * tmp_cert =
nullptr;
332 const unsigned char *
p;
334 tmp_cert = d2i_X509(&tmp_cert, &p, len);
336 sk_X509_push(certs, tmp_cert);
338 encountered_error =
true;
341 if (data) { OPENSSL_free(data); data =
nullptr;}
342 if (header) { OPENSSL_free(header); header =
nullptr;}
343 if (name) { OPENSSL_free(name); name =
nullptr;}
345 X509 *x509cert =
nullptr;
346 if (!encountered_error && sk_X509_num(certs)) {
350 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),0,0);
354 sk_X509_pop_free(certs, X509_free);
360 OPENSSL_free(subject);
369 char *
filename = getenv(
"X509_USER_PROXY");
373 std::stringstream ss;
374 ss <<
"/tmp/x509up_u" << geteuid();
void setCurrentServer(const std::string &servername)
virtual struct addrinfo const * statisticsDestination() const =0
ssize_t m_read_single_operations
ssize_t m_read_vector_bytes
FileStatistics m_filestats
ssize_t m_read_single_bytes
static const StorageStats & summary(void)
std::atomic< ssize_t > m_size
void filePreCloseEvent(std::string const &lfn, bool usedFallback)
static bool getX509Subject(std::string &)
virtual std::set< std::string > const * statisticsInfo() const =0
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)
ssize_t m_read_vector_count_sum
virtual std::string const & siteName(void) const =0
#define JOB_UNIQUE_ID_ENV
void determineHostnames(void)
void fillUDP(const std::string &, bool, std::string &)
std::string toString(const std::pair< T, T > &aT)
void watchPreCloseFile(PreCloseFile::slot_type const &iSlot)
ssize_t m_read_vector_square
void fillUDP(std::ostringstream &os)
void setSize(size_t size)
char data[epos_bytes_allocation]
static const char * getJobID()
ssize_t m_read_single_square
ssize_t m_read_vector_operations
std::string m_clientdomain
StatisticsSenderService(edm::ParameterSet const &pset, edm::ActivityRegistry &ar)
ssize_t m_read_vector_count_square
static bool getX509SubjectFromFile(const std::string &filename, std::string &result)
#define UPDATE_AND_OUTPUT_STATISTIC(x)