XRootD
XrdXrootdMonitor.hh
Go to the documentation of this file.
1 #ifndef __XRDXROOTDMONITOR__
2 #define __XRDXROOTDMONITOR__
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d M o n i t o r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cinttypes>
34 #include <cstdlib>
35 #include <ctime>
36 #include <netinet/in.h>
37 #include <sys/types.h>
38 
39 #include "XrdSec/XrdSecMonitor.hh"
40 #include "XrdSys/XrdSysPthread.hh"
42 #include "XProtocol/XPtypes.hh"
43 
44 /******************************************************************************/
45 /* X r d M o n i t o r */
46 /******************************************************************************/
47 
48 #define XROOTD_MON_ALL 0x00000001
49 #define XROOTD_MON_FILE 0x00000002
50 #define XROOTD_MON_IO 0x00000004
51 #define XROOTD_MON_INFO 0x00000008
52 #define XROOTD_MON_USER 0x00000010
53 #define XROOTD_MON_AUTH 0x00000020
54 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE)
55 #define XROOTD_MON_REDR 0x00000040
56 #define XROOTD_MON_IOV 0x00000080
57 #define XROOTD_MON_FSTA 0x00000100
58 #define XROOTD_MON_CCM 0x00000200
59 #define XROOTD_MON_PFC 0x00000400
60 #define XROOTD_MON_TCPMO 0x00000800
61 #define XROOTD_MON_TPC 0x00001000
62 #define XROOTD_MON_THROT 0x00002000
63 #define XROOTD_MON_GSTRM (XROOTD_MON_CCM | XROOTD_MON_PFC | XROOTD_MON_TCPMO | XROOTD_MON_THROT)
64 
65 #define XROOTD_MON_FSLFN 1
66 #define XROOTD_MON_FSOPS 2
67 #define XROOTD_MON_FSSSQ 4
68 #define XROOTD_MON_FSXFR 8
69 
70 class XrdScheduler;
71 class XrdNetMsg;
72 class XrdXrootdMonFile;
73 
74 /******************************************************************************/
75 /* C l a s s X r d X r o o t d M o n i t o r */
76 /******************************************************************************/
77 
79 {
80 public:
81  class User;
82 friend class User;
83 friend class XrdXrootdMonFile;
84 
85 // All values for Add_xx() must be passed in network byte order
86 //
87 inline void Add_rd(kXR_unt32 dictid,
88  kXR_int32 rlen,
89  kXR_int64 offset)
90  {Add_io(dictid, rlen, offset);}
91 
92 inline void Add_rv(kXR_unt32 dictid,
93  kXR_int32 rlen,
94  kXR_int16 vcnt,
95  kXR_char vseq,
96  kXR_char vtype)
97  {if (lastWindow != currWindow) Mark();
98  else if (nextEnt == lastEnt) Flush();
99  monBuff->info[nextEnt].arg0.id[0] = vtype;
100  monBuff->info[nextEnt].arg0.id[1] = vseq;
101  monBuff->info[nextEnt].arg0.sVal[1] = vcnt;
102  monBuff->info[nextEnt].arg0.rTot[1] = 0;
103  monBuff->info[nextEnt].arg1.buflen = rlen;
104  monBuff->info[nextEnt++].arg2.dictid = dictid;
105  }
106 
107 inline void Add_wr(kXR_unt32 dictid,
108  kXR_int32 wlen,
109  kXR_int64 offset)
110  {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);}
111 
112  void appID(char *id);
113 
114  void Close(kXR_unt32 dictid, long long rTot, long long wTot);
115 
116  void Disc(kXR_unt32 dictid, int csec, char Flags=0);
117 
118 static void Defaults(char *dest1, int m1, char *dest2, int m2);
119 static void Defaults(int msz, int rsz, int wsz,
120  int flush, int flash, int iDent, int rnm,
121  int fbsz, int fsint=0, int fsopt=0, int fsion=0);
122 
123 static int Flushing() {return autoFlush;}
124 
125 static kXR_unt32 GetDictID(bool hbo=false);
126 
127 static void Ident() {Send(-1, idRec, idLen);}
128 
129 static void Init(XrdScheduler *sp, XrdSysError *errp,
130  const char *iHost, const char *iProg,
131  const char *iName, int Port);
132 
133 static int Init();
134 
135 static bool ModeEnabled(int mode)
136  {return ((monMode1|monMode2) & mode) != 0;}
137 
138  void Open(kXR_unt32 dictid, off_t fsize);
139 
140 static int Redirect() {return monREDR;}
141 
142 static int Redirect(kXR_unt32 mID, const char *hName, int Port,
143  const char opC, const char *Path);
144 
145 static int Send(int mmode, void *buff, int size, bool setseq=true);
146 
147 static time_t Tick();
148 
149 /******************************************************************************/
150 
151 class Hello
152 {
153 public:
154 
155 static bool Hail();
156 
157 virtual void Ident() {};
158 
159  Hello(const char *dest, char mode);
160 
161 virtual ~Hello() {if (theDest) free(theDest);}
162 
163 private:
164 static Hello *First;
165  Hello *Next;
166  char *theDest;
167  char theMode;
168 };
169 
170 /******************************************************************************/
171 
172 class User : public XrdSecMonitor
173 {
174 public:
175 
178 char Iops;
179 char Fops;
180 short Len;
181 char *Name;
182 
183 inline int Auths() {return XrdXrootdMonitor::monAUTH;}
184 
185 void Clear() {if (Name) {free(Name); Name = 0; Len = 0;}
186  if (Agent) {Agent->unAlloc(Agent); Agent = 0;}
187  Did = 0; Iops = Fops = 0;
188  }
189 
190  void Enable();
191 
192  void Disable();
193 
194 inline int Files() {return (Agent ? Fops : 0);}
195 
196 inline int Fstat() {return monFSTAT;}
197 
198 inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);}
199 
200 inline int InOut() {return (Agent ? Iops : 0);}
201 
202 inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);}
203 
204 inline kXR_unt32 MapInfo(const char *Info)
205  {return XrdXrootdMonitor::Map(XROOTD_MON_MAPINFO,
206  *this, Info);
207  }
208 
209 inline kXR_unt32 MapPath(const char *Path)
210  {return XrdXrootdMonitor::Map(XROOTD_MON_MAPPATH,
211  *this, Path);
212  }
213 
214  void Register(const char *Uname, const char *Hname,
215  const char *Pname, unsigned int xSID=0);
216 
217  void Report(const char *Info)
218  {Did=XrdXrootdMonitor::Map(XROOTD_MON_MAPUSER,*this,Info);}
219 
220  void Report(int eCode, int aCode);
221 
222  bool Report(WhatInfo infoT, const char *info) override;
223 
224 inline int Ready() {return XrdXrootdMonitor::monACTIVE;}
225 
226  User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {}
227  ~User() {Clear();}
228 };
229 
230 /******************************************************************************/
231 
233 
235 
236 static const int rdrMax = 8;
237 
238 private:
239  ~XrdXrootdMonitor();
240 
241 static
242 struct MonRdrBuff
243  {MonRdrBuff *Next;
244  XrdXrootdMonBurr *Buff;
245  int nextEnt;
246  int flushIt;
247  kXR_int32 lastTOD;
248  XrdSysMutex Mutex;
249  } rdrMon[rdrMax];
250 static MonRdrBuff *rdrMP;
251 static XrdSysMutex rdrMutex;
252 
253 inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs)
254  {if (lastWindow != currWindow) Mark();
255  else if (nextEnt == lastEnt) Flush();
256  monBuff->info[nextEnt].arg0.val = offs;
257  monBuff->info[nextEnt].arg1.buflen = blen;
258  monBuff->info[nextEnt++].arg2.dictid = duid;
259  }
260 static XrdXrootdMonitor *Alloc(int force=0);
261  unsigned char do_Shift(long long xTot, unsigned int &xVal);
262  void Dup(XrdXrootdMonTrace *mrec);
263 static void fillHeader(XrdXrootdMonHeader *hdr,
264  const char id, int size);
265 static MonRdrBuff *Fetch();
266  void Flush();
267 static void Flush(MonRdrBuff *mP);
268 static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo,
269  const char *path);
270  void Mark();
271 static void startClock();
272 static void unAlloc(XrdXrootdMonitor *monp);
273 
274 static XrdSysMutex windowMutex;
275 static char *idRec;
276 static int idLen;
277 static char *Dest1;
278 static int monMode1;
279 static XrdNetMsg *InetDest1;
280 static char *Dest2;
281 static int monMode2;
282 static XrdNetMsg *InetDest2;
283  XrdXrootdMonBuff *monBuff;
284 static int monBlen;
285  int nextEnt;
286 static int lastEnt;
287 static int lastRnt;
288 static int autoFlash;
289 static int autoFlush;
290 static int FlushTime;
291  kXR_int32 lastWindow;
292 static kXR_int32 currWindow;
293 static int rdrTOD;
294 static int rdrWin;
295 static int rdrNum;
296 static kXR_int32 sizeWindow;
297 static int isEnabled;
298 static int numMonitor;
299 static int monIdent;
300 static int monRlen;
301 static char monIO;
302 static char monINFO;
303 static char monFILE;
304 static char monREDR;
305 static char monUSER;
306 static char monAUTH;
307 static char monACTIVE;
308 static char monFSTAT;
309 static char monCLOCK;
310 };
311 #endif
long long kXR_int64
Definition: XPtypes.hh:98
int kXR_int32
Definition: XPtypes.hh:89
unsigned int kXR_unt32
Definition: XPtypes.hh:90
short kXR_int16
Definition: XPtypes.hh:66
unsigned char kXR_char
Definition: XPtypes.hh:65
XrdOucString Path
union XrdXrootdMonTrace::@172 arg1
union XrdXrootdMonTrace::@171 arg0
XrdXrootdMonTrace info[sizeof(XrdXrootdMonTrace)]
const kXR_char XROOTD_MON_MAPUSER
const kXR_char XROOTD_MON_MAPINFO
union XrdXrootdMonTrace::@173 arg2
const kXR_char XROOTD_MON_MAPPATH
Hello(const char *dest, char mode)
kXR_unt32 MapInfo(const char *Info)
kXR_unt32 MapPath(const char *Path)
void Register(const char *Uname, const char *Hname, const char *Pname, unsigned int xSID=0)
void Report(const char *Info)
XrdXrootdMonitor * Agent
static const int rdrMax
static XrdXrootdMonitor * altMon
static void Ident()
static void Defaults(char *dest1, int m1, char *dest2, int m2)
void appID(char *id)
static time_t Tick()
static int Flushing()
void Add_rv(kXR_unt32 dictid, kXR_int32 rlen, kXR_int16 vcnt, kXR_char vseq, kXR_char vtype)
void Disc(kXR_unt32 dictid, int csec, char Flags=0)
void Close(kXR_unt32 dictid, long long rTot, long long wTot)
static int Send(int mmode, void *buff, int size, bool setseq=true)
void Add_rd(kXR_unt32 dictid, kXR_int32 rlen, kXR_int64 offset)
static int Redirect()
static bool ModeEnabled(int mode)
void Add_wr(kXR_unt32 dictid, kXR_int32 wlen, kXR_int64 offset)
void Open(kXR_unt32 dictid, off_t fsize)
static kXR_unt32 GetDictID(bool hbo=false)