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-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <inttypes.h>
14 #include <stdlib.h>
15 #include <time.h>
16 #include <netinet/in.h>
17 #include <sys/types.h>
18 
19 #include "XrdNet/XrdNetPeer.hh"
20 #include "XrdSys/XrdSysPthread.hh"
22 #include "XProtocol/XPtypes.hh"
23 
24 /******************************************************************************/
25 /* X r d M o n i t o r */
26 /******************************************************************************/
27 
28 #define XROOTD_MON_ALL 1
29 #define XROOTD_MON_FILE 2
30 #define XROOTD_MON_IO 4
31 #define XROOTD_MON_INFO 8
32 #define XROOTD_MON_USER 16
33 #define XROOTD_MON_AUTH 32
34 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE)
35 #define XROOTD_MON_REDR 64
36 #define XROOTD_MON_IOV 128
37 
38 class XrdScheduler;
39 
40 /******************************************************************************/
41 /* C l a s s X r d X r o o t d M o n i t o r */
42 /******************************************************************************/
43 
45 {
46 public:
47  class User;
48 friend class User;
49 
50 // All values for Add_xx() must be passed in network byte order
51 //
52 inline void Add_rd(kXR_unt32 dictid,
53  kXR_int32 rlen,
54  kXR_int64 offset)
55  {Add_io(dictid, rlen, offset);}
56 
57 inline void Add_rv(kXR_unt32 dictid,
58  kXR_int32 rlen,
59  kXR_int16 vcnt,
60  kXR_char vseq)
61  {if (lastWindow != currWindow) Mark();
62  else if (nextEnt == lastEnt) Flush();
64  monBuff->info[nextEnt].arg0.id[1] = vseq;
65  monBuff->info[nextEnt].arg0.sVal[1] = vcnt;
66  monBuff->info[nextEnt].arg0.rTot[1] = 0;
67  monBuff->info[nextEnt].arg1.buflen = rlen;
68  monBuff->info[nextEnt++].arg2.dictid = dictid;
69  }
70 
71 inline void Add_wr(kXR_unt32 dictid,
72  kXR_int32 wlen,
73  kXR_int64 offset)
74  {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);}
75 
76  void appID(char *id);
77 
78  void Close(kXR_unt32 dictid, long long rTot, long long wTot);
79 
80  void Disc(kXR_unt32 dictid, int csec, char Flags=0);
81 
82 static void Defaults(char *dest1, int m1, char *dest2, int m2);
83 static void Defaults(int msz, int rsz, int wsz,
84  int flush, int flash, int iDent, int rnm);
85 
86 static void Ident() {Send(-1, idRec, idLen);}
87 
88 static int Init(XrdScheduler *sp, XrdSysError *errp,
89  const char *iHost, const char *iProg,
90  const char *iName, int Port);
91 
92  void Open(kXR_unt32 dictid, off_t fsize);
93 
94 static int Redirect() {return monREDR;}
95 
96 static int Redirect(kXR_unt32 mID, const char *hName, int Port,
97  const char opC, const char *Path);
98 
99 static time_t Tick();
100 
101 class User
102 {
103 public:
104 
107 char Iops;
108 char Fops;
109 short Len;
110 char *Name;
111 
112 inline int Auths() {return XrdXrootdMonitor::monAUTH;}
113 
114 void Clear() {if (Name) {free(Name); Name = 0; Len = 0;}
115  if (Agent) {Agent->unAlloc(Agent); Agent = 0;}
116  Did = 0; Iops = Fops = 0;
117  }
118 
119  void Enable();
120 
121  void Disable();
122 
123 inline int Files() {return (Agent ? Fops : 0);}
124 
125 inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);}
126 
127 inline int InOut() {return (Agent ? Iops : 0);}
128 
129 inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);}
130 
131 inline kXR_unt32 MapInfo(const char *Info)
133  *this, Info);
134  }
135 
136 inline kXR_unt32 MapPath(const char *Path)
138  *this, Path);
139  }
140 
141  void Register(const char *Uname, const char *Hname);
142 
143  void Report(const char *Info)
145 
146 inline int Ready() {return XrdXrootdMonitor::monACTIVE;}
147 
148  User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {}
149  ~User() {Clear();}
150 };
151 
153 
155 
156 static const int rdrMax = 8;
157 
158 private:
160 
161 static
165  int nextEnt;
166  int flushIt;
169  } rdrMon[rdrMax];
172 
173 inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs)
174  {if (lastWindow != currWindow) Mark();
175  else if (nextEnt == lastEnt) Flush();
176  monBuff->info[nextEnt].arg0.val = offs;
177  monBuff->info[nextEnt].arg1.buflen = blen;
178  monBuff->info[nextEnt++].arg2.dictid = duid;
179  }
180 static XrdXrootdMonitor *Alloc(int force=0);
181  unsigned char do_Shift(long long xTot, unsigned int &xVal);
182  void Dup(XrdXrootdMonTrace *mrec);
183 static void fillHeader(XrdXrootdMonHeader *hdr,
184  const char id, int size);
185 static MonRdrBuff *Fetch();
186  void Flush();
187 static void Flush(MonRdrBuff *mP);
188 static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo,
189  const char *path);
190  void Mark();
191 static int Send(int mmode, void *buff, int size);
192 static void startClock();
193 static void unAlloc(XrdXrootdMonitor *monp);
194 
198 static char *idRec;
199 static int idLen;
200 static int monFD;
201 static char *Dest1;
202 static int monMode1;
203 static struct sockaddr InetAddr1;
204 static char *Dest2;
205 static int monMode2;
206 static struct sockaddr InetAddr2;
208 static int monBlen;
209  int nextEnt;
210 static int lastEnt;
211 static int lastRnt;
212 static int autoFlash;
213 static int autoFlush;
214 static int FlushTime;
218 static int rdrTOD;
219 static int rdrWin;
220 static int rdrNum;
222 static int isEnabled;
223 static int numMonitor;
224 static int monIdent;
225 static int monRlen;
226 static long long mySID;
227 static char sidName[16];
228 static short sidSize;
229 static char monIO;
230 static char monINFO;
231 static char monFILE;
232 static char monREDR;
233 static char monUSER;
234 static char monAUTH;
235 static char monACTIVE;
236 };
237 #endif