44 const char *json_fmt =
"{\"TPC\":\"%s\",\"Client\":\"%s\","
45 "\"Xeq\":{\"Beg\":\"%s\",\"End\":\"%s\",\"RC\":%d,\"Strm\":%u,\"Type\":\"%s\","
47 "\"Src\":\"%s\",\"Dst\":\"%s\",\"Size\":%zu}";
49 const char *hostport =
"";
61 : protocol(proto), gStream(gStrm)
63 const char *colon =
":";
72 const char *host = getenv(
"XRDHOST");
if (!host) host =
"localhost";
73 const char *port = getenv(
"XRDPORT");
if (!port) {colon =
""; port =
"";}
75 snprintf(buff,
sizeof(buff),
"%s%s%s", host, colon, port);
76 hostport = strdup(buff);
83 const char *XrdXrootdTpcMon::getURL(
const char *spec,
const char *prot,
89 {snprintf(buff, bsz,
"%s://%s/%s", prot, hostport, spec);
99 const char *XrdXrootdTpcMon::getUTC(
struct timeval& tod,
100 char* utcBuff,
int utcBLen)
107 gmtime_r(&tod.tv_sec, &utcDT);
111 size_t n = strftime(utcBuff, utcBLen,
"%FT%T", &utcDT);
112 bP = utcBuff + n; utcBLen -= n;
113 snprintf(bP, utcBLen,
".%03uZ",
static_cast<unsigned int>(tod.tv_usec));
126 const char *srcURL, *dstURL;
127 char bt_buff[40], et_buff[40], sBuff[1024], dBuff[1024], buff[8192];
131 srcURL = getURL(info.
srcURL, protocol, sBuff,
sizeof(sBuff));
132 dstURL = getURL(info.
dstURL, protocol, dBuff,
sizeof(dBuff));
136 int n = snprintf(buff,
sizeof(buff), json_fmt, protocol, info.
clID,
137 getUTC(info.
begT, bt_buff,
sizeof(bt_buff)),
138 getUTC(info.
endT, et_buff,
sizeof(et_buff)),
139 info.
endRC,
static_cast<unsigned int>(info.
strm),
142 srcURL, dstURL, info.
fSize);
146 if (n >= (
int)
sizeof(buff))
147 eDest.
Emsg(
"TpcMon", protocol,
"invalid json; line truncated!");
151 if (!gStream.
Insert(buff, n+1))
152 eDest.
Emsg(
"TpcMon", protocol,
"invalid json; gStream buffer rejected!");
static XrdSysError eDest(0,"crypto_")
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
bool Insert(const char *data, int dlen)
void Report(TpcInfo &info)
XrdXrootdTpcMon(const char *proto, XrdSysLogger *logP, XrdXrootdGStream &gStrm)