00001 #ifndef __XRDXROOTDMONITOR__
00002 #define __XRDXROOTDMONITOR__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <inttypes.h>
00034 #include <stdlib.h>
00035 #include <time.h>
00036 #include <netinet/in.h>
00037 #include <sys/types.h>
00038
00039 #include "XrdSys/XrdSysPthread.hh"
00040 #include "XrdXrootd/XrdXrootdMonData.hh"
00041 #include "XProtocol/XPtypes.hh"
00042
00043
00044
00045
00046
00047 #define XROOTD_MON_ALL 0x00000001
00048 #define XROOTD_MON_FILE 0x00000002
00049 #define XROOTD_MON_IO 0x00000004
00050 #define XROOTD_MON_INFO 0x00000008
00051 #define XROOTD_MON_USER 0x00000010
00052 #define XROOTD_MON_AUTH 0x00000020
00053 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE)
00054 #define XROOTD_MON_REDR 0x00000040
00055 #define XROOTD_MON_IOV 0x00000080
00056 #define XROOTD_MON_FSTA 0x00000100
00057 #define XROOTD_MON_CCM 0x00000200
00058 #define XROOTD_MON_PFC 0x00000400
00059 #define XROOTD_MON_TCPMO 0x00000800
00060
00061 #define XROOTD_MON_FSLFN 1
00062 #define XROOTD_MON_FSOPS 2
00063 #define XROOTD_MON_FSSSQ 4
00064 #define XROOTD_MON_FSXFR 8
00065
00066 class XrdScheduler;
00067 class XrdNetMsg;
00068 class XrdXrootdMonFile;
00069
00070
00071
00072
00073
00074 class XrdXrootdMonitor
00075 {
00076 public:
00077 class User;
00078 friend class User;
00079 friend class XrdXrootdMonFile;
00080
00081
00082
00083 inline void Add_rd(kXR_unt32 dictid,
00084 kXR_int32 rlen,
00085 kXR_int64 offset)
00086 {Add_io(dictid, rlen, offset);}
00087
00088 inline void Add_rv(kXR_unt32 dictid,
00089 kXR_int32 rlen,
00090 kXR_int16 vcnt,
00091 kXR_char vseq,
00092 kXR_char vtype)
00093 {if (lastWindow != currWindow) Mark();
00094 else if (nextEnt == lastEnt) Flush();
00095 monBuff->info[nextEnt].arg0.id[0] = vtype;
00096 monBuff->info[nextEnt].arg0.id[1] = vseq;
00097 monBuff->info[nextEnt].arg0.sVal[1] = vcnt;
00098 monBuff->info[nextEnt].arg0.rTot[1] = 0;
00099 monBuff->info[nextEnt].arg1.buflen = rlen;
00100 monBuff->info[nextEnt++].arg2.dictid = dictid;
00101 }
00102
00103 inline void Add_wr(kXR_unt32 dictid,
00104 kXR_int32 wlen,
00105 kXR_int64 offset)
00106 {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);}
00107
00108 void appID(char *id);
00109
00110 void Close(kXR_unt32 dictid, long long rTot, long long wTot);
00111
00112 void Disc(kXR_unt32 dictid, int csec, char Flags=0);
00113
00114 static void Defaults(char *dest1, int m1, char *dest2, int m2);
00115 static void Defaults(int msz, int rsz, int wsz,
00116 int flush, int flash, int iDent, int rnm,
00117 int fsint=0, int fsopt=0, int fsion=0);
00118
00119 static int Flushing() {return autoFlush;}
00120
00121 static void Ident() {Send(-1, idRec, idLen);}
00122
00123 static int Init(XrdScheduler *sp, XrdSysError *errp,
00124 const char *iHost, const char *iProg,
00125 const char *iName, int Port);
00126
00127 static bool ModeEnabled(int mode)
00128 {return ((monMode1|monMode2) & mode) != 0;}
00129
00130 void Open(kXR_unt32 dictid, off_t fsize);
00131
00132 static int Redirect() {return monREDR;}
00133
00134 static int Redirect(kXR_unt32 mID, const char *hName, int Port,
00135 const char opC, const char *Path);
00136
00137 static int Send(int mmode, void *buff, int size);
00138
00139 static time_t Tick();
00140
00141 class User
00142 {
00143 public:
00144
00145 XrdXrootdMonitor *Agent;
00146 kXR_unt32 Did;
00147 char Iops;
00148 char Fops;
00149 short Len;
00150 char *Name;
00151
00152 inline int Auths() {return XrdXrootdMonitor::monAUTH;}
00153
00154 void Clear() {if (Name) {free(Name); Name = 0; Len = 0;}
00155 if (Agent) {Agent->unAlloc(Agent); Agent = 0;}
00156 Did = 0; Iops = Fops = 0;
00157 }
00158
00159 void Enable();
00160
00161 void Disable();
00162
00163 inline int Files() {return (Agent ? Fops : 0);}
00164
00165 inline int Fstat() {return monFSTAT;}
00166
00167 inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);}
00168
00169 inline int InOut() {return (Agent ? Iops : 0);}
00170
00171 inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);}
00172
00173 inline kXR_unt32 MapInfo(const char *Info)
00174 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPINFO,
00175 *this, Info);
00176 }
00177
00178 inline kXR_unt32 MapPath(const char *Path)
00179 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPPATH,
00180 *this, Path);
00181 }
00182
00183 void Register(const char *Uname, const char *Hname,
00184 const char *Pname);
00185
00186 void Report(const char *Info)
00187 {Did=XrdXrootdMonitor::Map(XROOTD_MON_MAPUSER,*this,Info);}
00188
00189 inline int Ready() {return XrdXrootdMonitor::monACTIVE;}
00190
00191 User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {}
00192 ~User() {Clear();}
00193 };
00194
00195 static XrdXrootdMonitor *altMon;
00196
00197 XrdXrootdMonitor();
00198
00199 static const int rdrMax = 8;
00200
00201 private:
00202 ~XrdXrootdMonitor();
00203
00204 static
00205 struct MonRdrBuff
00206 {MonRdrBuff *Next;
00207 XrdXrootdMonBurr *Buff;
00208 int nextEnt;
00209 int flushIt;
00210 kXR_int32 lastTOD;
00211 XrdSysMutex Mutex;
00212 } rdrMon[rdrMax];
00213 static MonRdrBuff *rdrMP;
00214 static XrdSysMutex rdrMutex;
00215
00216 inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs)
00217 {if (lastWindow != currWindow) Mark();
00218 else if (nextEnt == lastEnt) Flush();
00219 monBuff->info[nextEnt].arg0.val = offs;
00220 monBuff->info[nextEnt].arg1.buflen = blen;
00221 monBuff->info[nextEnt++].arg2.dictid = duid;
00222 }
00223 static XrdXrootdMonitor *Alloc(int force=0);
00224 unsigned char do_Shift(long long xTot, unsigned int &xVal);
00225 void Dup(XrdXrootdMonTrace *mrec);
00226 static void fillHeader(XrdXrootdMonHeader *hdr,
00227 const char id, int size);
00228 static MonRdrBuff *Fetch();
00229 void Flush();
00230 static void Flush(MonRdrBuff *mP);
00231 static kXR_unt32 GetDictID();
00232 static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo,
00233 const char *path);
00234 void Mark();
00235 static void startClock();
00236 static void unAlloc(XrdXrootdMonitor *monp);
00237
00238 static XrdSysMutex windowMutex;
00239 static char *idRec;
00240 static int idLen;
00241 static char *Dest1;
00242 static int monMode1;
00243 static XrdNetMsg *InetDest1;
00244 static char *Dest2;
00245 static int monMode2;
00246 static XrdNetMsg *InetDest2;
00247 XrdXrootdMonBuff *monBuff;
00248 static int monBlen;
00249 int nextEnt;
00250 static int lastEnt;
00251 static int lastRnt;
00252 static int autoFlash;
00253 static int autoFlush;
00254 static int FlushTime;
00255 kXR_int32 lastWindow;
00256 static kXR_int32 currWindow;
00257 static int rdrTOD;
00258 static int rdrWin;
00259 static int rdrNum;
00260 static kXR_int32 sizeWindow;
00261 static int isEnabled;
00262 static int numMonitor;
00263 static int monIdent;
00264 static int monRlen;
00265 static char sidName[16];
00266 static short sidSize;
00267 static char monIO;
00268 static char monINFO;
00269 static char monFILE;
00270 static char monREDR;
00271 static char monUSER;
00272 static char monAUTH;
00273 static char monACTIVE;
00274 static char monFSTAT;
00275 static char monCLOCK;
00276 };
00277 #endif