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 ()
 
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(), 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 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. Skip this if no specific reports
179 // in the xml category are requested.
180 //
181  if (theOpts)
182  {statsMutex.Lock();
183  if ((Data = GenStats(Dlen, theOpts)))
184  {netDest[0]->Send(Data, Dlen);
185  if (netDest[1]) netDest[1]->Send(Data, Dlen);
186  }
187  statsMutex.UnLock();
188  }
189 
190 // Check if we have additional data registered via addons and plugins that
191 // we need in JSON format. These are sent as separate udp packets.
192 //
193  theOpts = XrdMonitor::F_JSON;
194  if (jsonOpts & XRD_STATS_ADON) theOpts |= XrdMonitor::X_ADON;
195  if (jsonOpts & XRD_STATS_PLUG) theOpts |= XrdMonitor::X_PLUG;
196  if (!(theOpts & ~XrdMonitor::F_JSON) || !theMon->Registered()) return;
197 
198 // Format the header and setup for sending packets
199 //
200  int hL = sprintf(udpBuff, Jead, time(0));
201  int bL = sizeof(udpBuff) - hL - Jtln - 8;
202  char* bP = udpBuff + hL;
203 
204 // Get each item and send it off
205 //
206  struct iovec ioV[3];
207  ioV[0].iov_base = udpBuff;
208  ioV[0].iov_len = hL;
209  ioV[1].iov_base = bP;
210  ioV[2].iov_base = (void*)Jend;
211  ioV[2].iov_len = Jtln;
212  int uL, sItem = 0;
213  while((uL = theMon->Format(bP, bL, sItem, theOpts)))
214  {ioV[1].iov_len = uL;
215  netDest[0]->Send(ioV, 3);
216  if (netDest[1]) netDest[1]->Send(ioV, 3);
217  }
218 }
#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:64
bool Registered()
Definition: XrdMonitor.hh:54
int Send(const char *buff, int blen=0, const char *dest=0, int tmo=-1)
Definition: XrdNetMsg.cc:127

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:

◆ Stats()

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

Definition at line 224 of file XrdStats.cc.

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