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 <inttypes.h>
34 #include <stdlib.h>
35 #include <time.h>
36 #include <netinet/in.h>
37 #include <sys/types.h>
38 
39 #include "XrdNet/XrdNetPeer.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 1
49 #define XROOTD_MON_FILE 2
50 #define XROOTD_MON_IO 4
51 #define XROOTD_MON_INFO 8
52 #define XROOTD_MON_USER 16
53 #define XROOTD_MON_AUTH 32
54 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE)
55 #define XROOTD_MON_REDR 64
56 #define XROOTD_MON_IOV 128
57 #define XROOTD_MON_FSTA 256
58 
59 #define XROOTD_MON_FSLFN 1
60 #define XROOTD_MON_FSOPS 2
61 #define XROOTD_MON_FSSSQ 4
62 #define XROOTD_MON_FSXFR 8
63 
64 class XrdScheduler;
65 class XrdXrootdMonFile;
66 
67 /******************************************************************************/
68 /* C l a s s X r d X r o o t d M o n i t o r */
69 /******************************************************************************/
70 
72 {
73 public:
74  class User;
75 friend class User;
76 friend class XrdXrootdMonFile;
77 
78 // All values for Add_xx() must be passed in network byte order
79 //
80 inline void Add_rd(kXR_unt32 dictid,
81  kXR_int32 rlen,
82  kXR_int64 offset)
83  {Add_io(dictid, rlen, offset);}
84 
85 inline void Add_rv(kXR_unt32 dictid,
86  kXR_int32 rlen,
87  kXR_int16 vcnt,
88  kXR_char vseq,
89  kXR_char vtype)
90  {if (lastWindow != currWindow) Mark();
91  else if (nextEnt == lastEnt) Flush();
92  monBuff->info[nextEnt].arg0.id[0] = vtype;
93  monBuff->info[nextEnt].arg0.id[1] = vseq;
94  monBuff->info[nextEnt].arg0.sVal[1] = vcnt;
95  monBuff->info[nextEnt].arg0.rTot[1] = 0;
96  monBuff->info[nextEnt].arg1.buflen = rlen;
97  monBuff->info[nextEnt++].arg2.dictid = dictid;
98  }
99 
100 inline void Add_wr(kXR_unt32 dictid,
101  kXR_int32 wlen,
102  kXR_int64 offset)
103  {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);}
104 
105  void appID(char *id);
106 
107  void Close(kXR_unt32 dictid, long long rTot, long long wTot);
108 
109  void Disc(kXR_unt32 dictid, int csec, char Flags=0);
110 
111 static void Defaults(char *dest1, int m1, char *dest2, int m2);
112 static void Defaults(int msz, int rsz, int wsz,
113  int flush, int flash, int iDent, int rnm,
114  int fsint=0, int fsopt=0, int fsion=0);
115 
116 static void Ident() {Send(-1, idRec, idLen);}
117 
118 static int Init(XrdScheduler *sp, XrdSysError *errp,
119  const char *iHost, const char *iProg,
120  const char *iName, int Port);
121 
122  void Open(kXR_unt32 dictid, off_t fsize);
123 
124 static int Redirect() {return monREDR;}
125 
126 static int Redirect(kXR_unt32 mID, const char *hName, int Port,
127  const char opC, const char *Path);
128 
129 static time_t Tick();
130 
131 class User
132 {
133 public:
134 
137 char Iops;
138 char Fops;
139 short Len;
140 char *Name;
141 
142 inline int Auths() {return XrdXrootdMonitor::monAUTH;}
143 
144 void Clear() {if (Name) {free(Name); Name = 0; Len = 0;}
145  if (Agent) {Agent->unAlloc(Agent); Agent = 0;}
146  Did = 0; Iops = Fops = 0;
147  }
148 
149  void Enable();
150 
151  void Disable();
152 
153 inline int Files() {return (Agent ? Fops : 0);}
154 
155 inline int Fstat() {return monFSTAT;}
156 
157 inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);}
158 
159 inline int InOut() {return (Agent ? Iops : 0);}
160 
161 inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);}
162 
163 inline kXR_unt32 MapInfo(const char *Info)
165  *this, Info);
166  }
167 
168 inline kXR_unt32 MapPath(const char *Path)
170  *this, Path);
171  }
172 
173  void Register(const char *Uname, const char *Hname);
174 
175  void Report(const char *Info)
177 
178 inline int Ready() {return XrdXrootdMonitor::monACTIVE;}
179 
180  User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {}
181  ~User() {Clear();}
182 };
183 
185 
187 
188 static const int rdrMax = 8;
189 
190 private:
192 
193 static
197  int nextEnt;
198  int flushIt;
201  } rdrMon[rdrMax];
204 
205 inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs)
206  {if (lastWindow != currWindow) Mark();
207  else if (nextEnt == lastEnt) Flush();
208  monBuff->info[nextEnt].arg0.val = offs;
209  monBuff->info[nextEnt].arg1.buflen = blen;
210  monBuff->info[nextEnt++].arg2.dictid = duid;
211  }
212 static XrdXrootdMonitor *Alloc(int force=0);
213  unsigned char do_Shift(long long xTot, unsigned int &xVal);
214  void Dup(XrdXrootdMonTrace *mrec);
215 static void fillHeader(XrdXrootdMonHeader *hdr,
216  const char id, int size);
217 static MonRdrBuff *Fetch();
218  void Flush();
219 static void Flush(MonRdrBuff *mP);
220 static kXR_unt32 GetDictID();
221 static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo,
222  const char *path);
223  void Mark();
224 static int Send(int mmode, void *buff, int size);
225 static void startClock();
226 static void unAlloc(XrdXrootdMonitor *monp);
227 
231 static char *idRec;
232 static int idLen;
233 static int monFD;
234 static char *Dest1;
235 static int monMode1;
236 static struct sockaddr InetAddr1;
237 static char *Dest2;
238 static int monMode2;
239 static struct sockaddr InetAddr2;
241 static int monBlen;
242  int nextEnt;
243 static int lastEnt;
244 static int lastRnt;
245 static int autoFlash;
246 static int autoFlush;
247 static int FlushTime;
251 static int rdrTOD;
252 static int rdrWin;
253 static int rdrNum;
255 static int isEnabled;
256 static int numMonitor;
257 static int monIdent;
258 static int monRlen;
259 static long long mySID;
260 static char sidName[16];
261 static short sidSize;
262 static char monIO;
263 static char monINFO;
264 static char monFILE;
265 static char monREDR;
266 static char monUSER;
267 static char monAUTH;
268 static char monACTIVE;
269 static char monFSTAT;
270 static char monCLOCK;
271 };
272 #endif