XRootD
Loading...
Searching...
No Matches
XrdStats Class Reference

#include <XrdStats.hh>

Collaboration diagram for XrdStats:

Classes

class  CallBack

Public Member Functions

 XrdStats (XrdSysError *eP, XrdScheduler *sP, XrdBuffManager *bP, const char *hn, int port, const char *in, const char *pn, const char *sn)
virtual ~XrdStats ()
void Export (XrdOucEnv &env)
void Init (char **Dest, int iVal=600, int xOpts=0, int jOpts=0)
void Report ()
virtual void Stats (XrdStats::CallBack *InfoBack, int xOpts, int jOpts=0)

Detailed Description

Definition at line 62 of file XrdStats.hh.

Constructor & Destructor Documentation

◆ XrdStats()

XrdStats::XrdStats ( XrdSysError * eP,
XrdScheduler * sP,
XrdBuffManager * bP,
const char * hn,
int port,
const char * in,
const char * pn,
const char * sn )

Definition at line 83 of file XrdStats.cc.

86{
87 const char *head =
88 "<statistics tod=\"%%ld\" ver=\"" XrdVERSION "\" src=\"%s:%d\" "
89 "tos=\"%ld\" pgm=\"%s\" ins=\"%s\" pid=\"%d\" "
90 "site=\"%s\">";
91 Hend = "</statistics>";
92 Htln = strlen(Hend);
93
94 const char *jead =
95 "{\"statistics\":{\"tod\":%%ld,\"ver\":\"" XrdVERSION "\",\"src\":\"%s:%d\","
96 "\"tos\":%ld,\"pgm\":\"%s\",\"ins\":\"%s\",\"pid\":%d,"
97 "\"site\":\"%s\",";
98 Jend = "}}";
99 Jtln = 2;
100
101 char myBuff[1024];
102
103 XrdLog = eP;
104 XrdSched = sP;
105 BuffPool = bP;
106
107 sprintf(myBuff, head, hname, port, tBoot, pname, iname,
108 static_cast<int>(getpid()), (site ? site : ""));
109 Head = strdup(myBuff);
110
111 sprintf(myBuff, jead, hname, port, tBoot, pname, iname,
112 static_cast<int>(getpid()), (site ? site : ""));
113 Jead = strdup(myBuff);
114
115// Allocate a shared buffer. Buffer use is serialized via the statsMutex.
116//
117 blen = 64*1024; // 64K which is the largest allowed UDP packet
118 if (posix_memalign((void **)&buff, getpagesize(), blen)) buff = 0;
119
120 myHost = hname;
121 myName = iname;
122 myPort = port;
123
124 theMon = new XrdMonitor;
125}

◆ ~XrdStats()

virtual XrdStats::~XrdStats ( )
inlinevirtual

Definition at line 92 of file XrdStats.hh.

92{if (buff) free(buff);}

Member Function Documentation

◆ Export()

void XrdStats::Export ( XrdOucEnv & env)

Definition at line 131 of file XrdStats.cc.

132{
133 XrdMonRoll* monRoll = new XrdMonRoll(*theMon);
134 theEnv.PutPtr("XrdMonRoll*", monRoll);
135}
void PutPtr(const char *varname, void *value)
Definition XrdOucEnv.cc:298
XrdOucEnv theEnv

References XrdOucEnv::PutPtr().

Here is the call graph for this function:

◆ Init()

void XrdStats::Init ( char ** Dest,
int iVal = 600,
int xOpts = 0,
int jOpts = 0 )

Definition at line 141 of file XrdStats.cc.

142{
143
144// Establish up to two destinations
145//
146 if (Dest[0]) netDest[0] = new XrdNetMsg(XrdLog, Dest[0]);
147 if (Dest[1]) netDest[1] = new XrdNetMsg(XrdLog, Dest[1]);
148
149// Establish auto reporting options
150//
151 if (!(jOpts & XRD_STATS_ALLJ) && !(xOpts & XRD_STATS_ALLX))
152 xOpts |= XRD_STATS_ALLX; // ALLX includes ALLJ
153 jsonOpts = (jOpts & XRD_STATS_ALLJ) | XRD_STATS_JSON; xmlOpts = xOpts;
154 autoSync = xOpts & XRD_STATS_SYNCA;
155
156// Get and schedule a new job to report
157//
158 if (netDest[0]) new XrdStatsJob(XrdSched, this, iVal);
159 return;
160}
#define XRD_STATS_JSON
Definition XrdStats.hh:52
#define XRD_STATS_SYNCA
Definition XrdStats.hh:50
#define XRD_STATS_ALLX
Definition XrdStats.hh:39
#define XRD_STATS_ALLJ
Definition XrdStats.hh:38

References XRD_STATS_ALLJ, XRD_STATS_ALLX, XRD_STATS_JSON, and XRD_STATS_SYNCA.

◆ Report()

void XrdStats::Report ( )

Definition at line 166 of file XrdStats.cc.

167{
168 char udpBuff[64*1024];
169 const char *Data;
170 int theOpts, Dlen;
171
172// This is an entry for reporting purposes, establish the sync flag
173//
174 if (!autoSync || XrdSched->Active() <= 30) theOpts = xmlOpts;
175 else theOpts = xmlOpts & ~XRD_STATS_SYNC;
176
177// Now get the statistics in xml format. Note that there is only one buufer
178// so we lock this code path to protect it.
179//
180 statsMutex.Lock();
181 if ((Data = GenStats(Dlen, theOpts)))
182 {netDest[0]->Send(Data, Dlen);
183 if (netDest[1]) netDest[1]->Send(Data, Dlen);
184 }
185 statsMutex.UnLock();
186
187// Check if we have additional data registered via addons and plugins that
188// we need in JSON format. These are sent as separate udp packets.
189//
190 theOpts = XrdMonitor::F_JSON;
191 if (jsonOpts & XRD_STATS_ADON) theOpts |= XrdMonitor::X_ADON;
192 if (jsonOpts & XRD_STATS_PLUG) theOpts |= XrdMonitor::X_PLUG;
193 if (!(theOpts & ~XrdMonitor::F_JSON) || !theMon->Registered()) return;
194
195// Format the header and setup for sending packets
196//
197 int hL = sprintf(udpBuff, Jead, time(0));
198 int bL = sizeof(udpBuff) - hL - Jtln - 8;
199 char* bP = udpBuff + hL;
200
201// Get each item and send it off
202//
203 struct iovec ioV[3];
204 ioV[0].iov_base = udpBuff;
205 ioV[0].iov_len = hL;
206 ioV[1].iov_base = bP;
207 ioV[2].iov_base = (void*)Jend;
208 ioV[2].iov_len = Jtln;
209 int uL, sItem = 0;
210 while((uL = theMon->Format(bP, bL, sItem, theOpts)))
211 {ioV[1].iov_len = uL;
212 netDest[0]->Send(ioV, 3);
213 if (netDest[1]) netDest[1]->Send(ioV, 3);
214 }
215}
#define XRD_STATS_ADON
Definition XrdStats.hh:37
#define XRD_STATS_PLUG
Definition XrdStats.hh:43

References XrdMonitor::F_JSON, XrdMonitor::X_ADON, XrdMonitor::X_PLUG, XRD_STATS_ADON, XRD_STATS_PLUG, and XRD_STATS_SYNC.

◆ Stats()

void XrdStats::Stats ( XrdStats::CallBack * InfoBack,
int xOpts,
int jOpts = 0 )
virtual

Definition at line 221 of file XrdStats.cc.

222{
223 const char *info;
224 int sz, opts;
225
226// Note that currently we do not support json for client requests, so we
227// ignore the jOpts as they should never be set.
228//
229 opts = xOpts;
230
231// Lock the buffer,
232//
233 statsMutex.Lock();
234
235// Obtain the stats, if we have some, do the callback. We currently do not
236// support return of JSON format as some statistics can't provide it.
237//
238 if ((info = GenStats(sz, opts))) cbP->Info(info, sz);
239
240// Unlock the buffer
241//
242 statsMutex.UnLock();
243}
struct myOpts opts

References XrdStats::CallBack::Info(), and opts.

Here is the call graph for this function:

The documentation for this class was generated from the following files: