|
xrootd
|
00001 #ifndef __XRDXROOTDMONITOR__ 00002 #define __XRDXROOTDMONITOR__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d X r o o t d M o n i t o r . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 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 "XrdNet/XrdNetPeer.hh" 00040 #include "XrdSys/XrdSysPthread.hh" 00041 #include "XrdXrootd/XrdXrootdMonData.hh" 00042 #include "XProtocol/XPtypes.hh" 00043 00044 /******************************************************************************/ 00045 /* X r d M o n i t o r */ 00046 /******************************************************************************/ 00047 00048 #define XROOTD_MON_ALL 1 00049 #define XROOTD_MON_FILE 2 00050 #define XROOTD_MON_IO 4 00051 #define XROOTD_MON_INFO 8 00052 #define XROOTD_MON_USER 16 00053 #define XROOTD_MON_AUTH 32 00054 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE) 00055 #define XROOTD_MON_REDR 64 00056 #define XROOTD_MON_IOV 128 00057 #define XROOTD_MON_FSTA 256 00058 00059 #define XROOTD_MON_FSLFN 1 00060 #define XROOTD_MON_FSOPS 2 00061 #define XROOTD_MON_FSSSQ 4 00062 #define XROOTD_MON_FSXFR 8 00063 00064 class XrdScheduler; 00065 class XrdXrootdMonFile; 00066 00067 /******************************************************************************/ 00068 /* C l a s s X r d X r o o t d M o n i t o r */ 00069 /******************************************************************************/ 00070 00071 class XrdXrootdMonitor 00072 { 00073 public: 00074 class User; 00075 friend class User; 00076 friend class XrdXrootdMonFile; 00077 00078 // All values for Add_xx() must be passed in network byte order 00079 // 00080 inline void Add_rd(kXR_unt32 dictid, 00081 kXR_int32 rlen, 00082 kXR_int64 offset) 00083 {Add_io(dictid, rlen, offset);} 00084 00085 inline void Add_rv(kXR_unt32 dictid, 00086 kXR_int32 rlen, 00087 kXR_int16 vcnt, 00088 kXR_char vseq, 00089 kXR_char vtype) 00090 {if (lastWindow != currWindow) Mark(); 00091 else if (nextEnt == lastEnt) Flush(); 00092 monBuff->info[nextEnt].arg0.id[0] = vtype; 00093 monBuff->info[nextEnt].arg0.id[1] = vseq; 00094 monBuff->info[nextEnt].arg0.sVal[1] = vcnt; 00095 monBuff->info[nextEnt].arg0.rTot[1] = 0; 00096 monBuff->info[nextEnt].arg1.buflen = rlen; 00097 monBuff->info[nextEnt++].arg2.dictid = dictid; 00098 } 00099 00100 inline void Add_wr(kXR_unt32 dictid, 00101 kXR_int32 wlen, 00102 kXR_int64 offset) 00103 {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);} 00104 00105 void appID(char *id); 00106 00107 void Close(kXR_unt32 dictid, long long rTot, long long wTot); 00108 00109 void Disc(kXR_unt32 dictid, int csec, char Flags=0); 00110 00111 static void Defaults(char *dest1, int m1, char *dest2, int m2); 00112 static void Defaults(int msz, int rsz, int wsz, 00113 int flush, int flash, int iDent, int rnm, 00114 int fsint=0, int fsopt=0, int fsion=0); 00115 00116 static void Ident() {Send(-1, idRec, idLen);} 00117 00118 static int Init(XrdScheduler *sp, XrdSysError *errp, 00119 const char *iHost, const char *iProg, 00120 const char *iName, int Port); 00121 00122 void Open(kXR_unt32 dictid, off_t fsize); 00123 00124 static int Redirect() {return monREDR;} 00125 00126 static int Redirect(kXR_unt32 mID, const char *hName, int Port, 00127 const char opC, const char *Path); 00128 00129 static time_t Tick(); 00130 00131 class User 00132 { 00133 public: 00134 00135 XrdXrootdMonitor *Agent; 00136 kXR_unt32 Did; 00137 char Iops; 00138 char Fops; 00139 short Len; 00140 char *Name; 00141 00142 inline int Auths() {return XrdXrootdMonitor::monAUTH;} 00143 00144 void Clear() {if (Name) {free(Name); Name = 0; Len = 0;} 00145 if (Agent) {Agent->unAlloc(Agent); Agent = 0;} 00146 Did = 0; Iops = Fops = 0; 00147 } 00148 00149 void Enable(); 00150 00151 void Disable(); 00152 00153 inline int Files() {return (Agent ? Fops : 0);} 00154 00155 inline int Fstat() {return monFSTAT;} 00156 00157 inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);} 00158 00159 inline int InOut() {return (Agent ? Iops : 0);} 00160 00161 inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);} 00162 00163 inline kXR_unt32 MapInfo(const char *Info) 00164 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPINFO, 00165 *this, Info); 00166 } 00167 00168 inline kXR_unt32 MapPath(const char *Path) 00169 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPPATH, 00170 *this, Path); 00171 } 00172 00173 void Register(const char *Uname, const char *Hname); 00174 00175 void Report(const char *Info) 00176 {Did=XrdXrootdMonitor::Map(XROOTD_MON_MAPUSER,*this,Info);} 00177 00178 inline int Ready() {return XrdXrootdMonitor::monACTIVE;} 00179 00180 User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {} 00181 ~User() {Clear();} 00182 }; 00183 00184 static XrdXrootdMonitor *altMon; 00185 00186 XrdXrootdMonitor(); 00187 00188 static const int rdrMax = 8; 00189 00190 private: 00191 ~XrdXrootdMonitor(); 00192 00193 static 00194 struct MonRdrBuff 00195 {MonRdrBuff *Next; 00196 XrdXrootdMonBurr *Buff; 00197 int nextEnt; 00198 int flushIt; 00199 kXR_int32 lastTOD; 00200 XrdSysMutex Mutex; 00201 } rdrMon[rdrMax]; 00202 static MonRdrBuff *rdrMP; 00203 static XrdSysMutex rdrMutex; 00204 00205 inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs) 00206 {if (lastWindow != currWindow) Mark(); 00207 else if (nextEnt == lastEnt) Flush(); 00208 monBuff->info[nextEnt].arg0.val = offs; 00209 monBuff->info[nextEnt].arg1.buflen = blen; 00210 monBuff->info[nextEnt++].arg2.dictid = duid; 00211 } 00212 static XrdXrootdMonitor *Alloc(int force=0); 00213 unsigned char do_Shift(long long xTot, unsigned int &xVal); 00214 void Dup(XrdXrootdMonTrace *mrec); 00215 static void fillHeader(XrdXrootdMonHeader *hdr, 00216 const char id, int size); 00217 static MonRdrBuff *Fetch(); 00218 void Flush(); 00219 static void Flush(MonRdrBuff *mP); 00220 static kXR_unt32 GetDictID(); 00221 static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo, 00222 const char *path); 00223 void Mark(); 00224 static int Send(int mmode, void *buff, int size); 00225 static void startClock(); 00226 static void unAlloc(XrdXrootdMonitor *monp); 00227 00228 static XrdScheduler *Sched; 00229 static XrdSysError *eDest; 00230 static XrdSysMutex windowMutex; 00231 static char *idRec; 00232 static int idLen; 00233 static int monFD; 00234 static char *Dest1; 00235 static int monMode1; 00236 static struct sockaddr InetAddr1; 00237 static char *Dest2; 00238 static int monMode2; 00239 static struct sockaddr InetAddr2; 00240 XrdXrootdMonBuff *monBuff; 00241 static int monBlen; 00242 int nextEnt; 00243 static int lastEnt; 00244 static int lastRnt; 00245 static int autoFlash; 00246 static int autoFlush; 00247 static int FlushTime; 00248 static kXR_int32 startTime; 00249 kXR_int32 lastWindow; 00250 static kXR_int32 currWindow; 00251 static int rdrTOD; 00252 static int rdrWin; 00253 static int rdrNum; 00254 static kXR_int32 sizeWindow; 00255 static int isEnabled; 00256 static int numMonitor; 00257 static int monIdent; 00258 static int monRlen; 00259 static long long mySID; 00260 static char sidName[16]; 00261 static short sidSize; 00262 static char monIO; 00263 static char monINFO; 00264 static char monFILE; 00265 static char monREDR; 00266 static char monUSER; 00267 static char monAUTH; 00268 static char monACTIVE; 00269 static char monFSTAT; 00270 static char monCLOCK; 00271 }; 00272 #endif
1.7.6.1