XRootD
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 ()
 
void SetPort (int port)
 
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  XrdLog = eP;
88  XrdSched = sP;
89  BuffPool = bP;
90 
91  myHost = hname;
92  myName = iname;
93  myProg = pname;
94  mySite = (site ? site : "");
95  Head = Jead = 0;
96  SetPort(port);
97 
98 // Allocate a shared buffer. Buffer use is serialized via the statsMutex.
99 //
100  blen = 64*1024; // 64K which is the largest allowed UDP packet
101  if (posix_memalign((void **)&buff, getpagesize(), blen)) buff = 0;
102 
103  theMon = new XrdMonitor;
104 }
void SetPort(int port)
Definition: XrdStats.cc:110

References SetPort().

+ Here is the call graph for this function:

◆ ~XrdStats()

virtual XrdStats::~XrdStats ( )
inlinevirtual

Definition at line 97 of file XrdStats.hh.

97  {if (buff) free(buff); if (Head) free(Head);
98  if (Jead) free(Jead);
99  }

Member Function Documentation

◆ Export()

void XrdStats::Export ( XrdOucEnv &  env)

Definition at line 145 of file XrdStats.cc.

146 {
147  XrdMonRoll* monRoll = new XrdMonRoll(*theMon);
148  theEnv.PutPtr("XrdMonRoll*", monRoll);
149 }
void PutPtr(const char *varname, void *value)
Definition: XrdOucEnv.cc:316
XrdOucEnv theEnv

References XrdOucEnv::PutPtr(), and XrdCms::theEnv.

+ 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 155 of file XrdStats.cc.

156 {
157 
158 // Establish up to two destinations
159 //
160  if (Dest[0]) netDest[0] = new XrdNetMsg(XrdLog, Dest[0]);
161  if (Dest[1]) netDest[1] = new XrdNetMsg(XrdLog, Dest[1]);
162 
163 // Establish auto reporting options
164 //
165  if (!(jOpts & XRD_STATS_ALLJ) && !(xOpts & XRD_STATS_ALLX))
166  xOpts |= XRD_STATS_ALLX; // ALLX includes ALLJ
167  jsonOpts = (jOpts & XRD_STATS_ALLJ) | XRD_STATS_JSON; xmlOpts = xOpts;
168  autoSync = xOpts & XRD_STATS_SYNCA;
169 
170 // Get and schedule a new job to report
171 //
172  if (netDest[0]) new XrdStatsJob(XrdSched, this, iVal);
173  return;
174 }
#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 180 of file XrdStats.cc.

181 {
182  char udpBuff[64*1024];
183  const char *Data;
184  int theOpts, Dlen;
185 
186 // This is an entry for reporting purposes, establish the sync flag
187 //
188  if (!autoSync || XrdSched->Active() <= 30) theOpts = xmlOpts;
189  else theOpts = xmlOpts & ~XRD_STATS_SYNC;
190 
191 // Now get the statistics in xml format. Note that there is only one buufer
192 // so we lock this code path to protect it. Skip this if no specific reports
193 // in the xml category are requested.
194 //
195  if (theOpts)
196  {statsMutex.Lock();
197  if ((Data = GenStats(Dlen, theOpts)))
198  {netDest[0]->Send(Data, Dlen);
199  if (netDest[1]) netDest[1]->Send(Data, Dlen);
200  }
201  statsMutex.UnLock();
202  }
203 
204 // Check if we have additional data registered via addons and plugins that
205 // we need in JSON format. These are sent as separate udp packets.
206 //
207  theOpts = XrdMonitor::F_JSON;
208  if (jsonOpts & XRD_STATS_ADON) theOpts |= XrdMonitor::X_ADON;
209  if (jsonOpts & XRD_STATS_PLUG) theOpts |= XrdMonitor::X_PLUG;
210  if (!(theOpts & ~XrdMonitor::F_JSON) || !theMon->Registered()) return;
211 
212 // Format the header and setup for sending packets
213 //
214  int hL = sprintf(udpBuff, Jead, time(0));
215  int bL = sizeof(udpBuff) - hL - Jtln - 8;
216  char* bP = udpBuff + hL;
217 
218 // Get each item and send it off
219 //
220  struct iovec ioV[3];
221  ioV[0].iov_base = udpBuff;
222  ioV[0].iov_len = hL;
223  ioV[1].iov_base = bP;
224  ioV[2].iov_base = (void*)Jend;
225  ioV[2].iov_len = Jtln;
226  int uL, sItem = 0;
227  while((uL = theMon->Format(bP, bL, sItem, theOpts)))
228  {ioV[1].iov_len = uL;
229  netDest[0]->Send(ioV, 3);
230  if (netDest[1]) netDest[1]->Send(ioV, 3);
231  }
232 }
#define XRD_STATS_ADON
Definition: XrdStats.hh:37
#define XRD_STATS_SYNC
Definition: XrdStats.hh:49
#define XRD_STATS_PLUG
Definition: XrdStats.hh:43
int Format(char *buff, int bsize, int &item, int opts=0)
Definition: XrdMonitor.cc:104
bool Registered()
Definition: XrdMonitor.hh:53
int Send(const char *buff, int blen=0, const char *dest=0, int tmo=-1)
Definition: XrdNetMsg.cc:147

References XrdScheduler::Active(), XrdMonitor::F_JSON, XrdMonitor::Format(), XrdSysMutex::Lock(), XrdMonitor::Registered(), XrdNetMsg::Send(), XrdSysMutex::UnLock(), XrdMonitor::X_ADON, XrdMonitor::X_PLUG, XRD_STATS_ADON, XRD_STATS_PLUG, and XRD_STATS_SYNC.

Referenced by XrdStatsJob::DoIt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetPort()

void XrdStats::SetPort ( int  port)

Definition at line 110 of file XrdStats.cc.

111 {
112  const char *head =
113  "<statistics tod=\"%%ld\" ver=\"" XrdVERSION "\" src=\"%s:%d\" "
114  "tos=\"%ld\" pgm=\"%s\" ins=\"%s\" pid=\"%d\" "
115  "site=\"%s\">";
116  Hend = "</statistics>";
117  Htln = strlen(Hend);
118 
119  const char *jead =
120  "{\"statistics\":{\"tod\":%%ld,\"ver\":\"" XrdVERSION "\",\"src\":\"%s:%d\","
121  "\"tos\":%ld,\"pgm\":\"%s\",\"ins\":\"%s\",\"pid\":%d,"
122  "\"site\":\"%s\",";
123  Jend = "}}";
124  Jtln = 2;
125 
126  char myBuff[1024];
127 
128  myPort = port;
129 
130  sprintf(myBuff, head, myHost, port, tBoot, myProg, myName,
131  static_cast<int>(getpid()), mySite);
132  if (Head) free(Head);
133  Head = strdup(myBuff);
134 
135  sprintf(myBuff, jead, myHost, port, tBoot, myProg, myName,
136  static_cast<int>(getpid()), mySite);
137  if (Jead) free(Jead);
138  Jead = strdup(myBuff);
139 }

Referenced by XrdStats().

+ Here is the caller graph for this function:

◆ Stats()

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

Definition at line 238 of file XrdStats.cc.

239 {
240  const char *info;
241  int sz, opts;
242 
243 // Note that currently we do not support json for client requests, so we
244 // ignore the jOpts as they should never be set.
245 //
246  opts = xOpts;
247 
248 // Lock the buffer,
249 //
250  statsMutex.Lock();
251 
252 // Obtain the stats, if we have some, do the callback. We currently do not
253 // support return of JSON format as some statistics can't provide it.
254 //
255  if ((info = GenStats(sz, opts))) cbP->Info(info, sz);
256 
257 // Unlock the buffer
258 //
259  statsMutex.UnLock();
260 }
struct myOpts opts

References XrdStats::CallBack::Info(), XrdSysMutex::Lock(), opts, and XrdSysMutex::UnLock().

Referenced by XrdXrootdStats::Stats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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