XRootD
Loading...
Searching...
No Matches
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
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_OSS 0x00004000
64#define XROOTD_MON_GSTRM (XROOTD_MON_CCM | XROOTD_MON_PFC | XROOTD_MON_TCPMO | XROOTD_MON_THROT | XROOTD_MON_OSS)
65
66#define XROOTD_MON_FSLFN 1
67#define XROOTD_MON_FSOPS 2
68#define XROOTD_MON_FSSSQ 4
69#define XROOTD_MON_FSXFR 8
70
71class XrdScheduler;
72class XrdNetMsg;
74
75/******************************************************************************/
76/* C l a s s X r d X r o o t d M o n i t o r */
77/******************************************************************************/
78
80{
81public:
82 class User;
83friend class User;
84friend class XrdXrootdMonFile;
85
86// All values for Add_xx() must be passed in network byte order
87//
88inline void Add_rd(kXR_unt32 dictid,
89 kXR_int32 rlen,
90 kXR_int64 offset)
91 {Add_io(dictid, rlen, offset);}
92
93inline void Add_rv(kXR_unt32 dictid,
94 kXR_int32 rlen,
95 kXR_int16 vcnt,
96 kXR_char vseq,
97 kXR_char vtype)
98 {if (lastWindow != currWindow) Mark();
99 else if (nextEnt == lastEnt) Flush();
100 monBuff->info[nextEnt].arg0.id[0] = vtype;
101 monBuff->info[nextEnt].arg0.id[1] = vseq;
102 monBuff->info[nextEnt].arg0.sVal[1] = vcnt;
103 monBuff->info[nextEnt].arg0.rTot[1] = 0;
104 monBuff->info[nextEnt].arg1.buflen = rlen;
105 monBuff->info[nextEnt++].arg2.dictid = dictid;
106 }
107
108inline void Add_wr(kXR_unt32 dictid,
109 kXR_int32 wlen,
110 kXR_int64 offset)
111 {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);}
112
113 void appID(char *id);
114
115 void Close(kXR_unt32 dictid, long long rTot, long long wTot);
116
117 void Disc(kXR_unt32 dictid, int csec, char Flags=0);
118
119static void Defaults(char *dest1, int m1, char *dest2, int m2);
120static void Defaults(int msz, int rsz, int wsz,
121 int flush, int flash, int iDent, int rnm,
122 int fbsz, int fsint=0, int fsopt=0, int fsion=0);
123
124static int Flushing() {return autoFlush;}
125
126static kXR_unt32 GetDictID(bool hbo=false);
127
128static void Ident() {Send(-1, idRec, idLen);}
129
130static void Init(XrdScheduler *sp, XrdSysError *errp,
131 const char *iHost, const char *iProg,
132 const char *iName, int Port);
133
134static int Init();
135
136static bool ModeEnabled(int mode)
137 {return ((monMode1|monMode2) & mode) != 0;}
138
139 void Open(kXR_unt32 dictid, off_t fsize);
140
141static int Redirect() {return monREDR;}
142
143static int Redirect(kXR_unt32 mID, const char *hName, int Port,
144 const char opC, const char *Path);
145
146static int Send(int mmode, void *buff, int size, bool setseq=true);
147
148static time_t Tick();
149
150/******************************************************************************/
151
152class Hello
153{
154public:
155
156static bool Hail();
157
158virtual void Ident() {};
159
160 Hello(const char *dest, char mode);
161
162virtual ~Hello() {if (theDest) free(theDest);}
163
164private:
165static Hello *First;
166 Hello *Next;
167 char *theDest;
168 char theMode;
169};
170
171/******************************************************************************/
172
173class User : public XrdSecMonitor
174{
175public:
176
179char Iops;
180char Fops;
181short Len;
182char *Name;
183
184inline int Auths() {return XrdXrootdMonitor::monAUTH;}
185
186void Clear() {if (Name) {free(Name); Name = 0; Len = 0;}
187 if (Agent) {Agent->unAlloc(Agent); Agent = 0;}
188 Did = 0; Iops = Fops = 0;
189 }
190
191 void Enable();
192
193 void Disable();
194
195inline int Files() {return (Agent ? Fops : 0);}
196
197inline int Fstat() {return monFSTAT;}
198
199inline int Info() {return (Agent ? XrdXrootdMonitor::monINFO : 0);}
200
201inline int InOut() {return (Agent ? Iops : 0);}
202
203inline int Logins() {return (Agent ? XrdXrootdMonitor::monUSER : 0);}
204
205inline kXR_unt32 MapInfo(const char *Info)
206 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPINFO,
207 *this, Info);
208 }
209
210inline kXR_unt32 MapPath(const char *Path)
211 {return XrdXrootdMonitor::Map(XROOTD_MON_MAPPATH,
212 *this, Path);
213 }
214
215 void Register(const char *Uname, const char *Hname,
216 const char *Pname, unsigned int xSID=0);
217
218 void Report(const char *Info)
219 {Did=XrdXrootdMonitor::Map(XROOTD_MON_MAPUSER,*this,Info);}
220
221 void Report(int eCode, int aCode);
222
223 bool Report(WhatInfo infoT, const char *info) override;
224
225inline int Ready() {return XrdXrootdMonitor::monACTIVE;}
226
227 User() : Agent(0), Did(0), Iops(0), Fops(0), Len(0), Name(0) {}
229};
230
231/******************************************************************************/
232
234
236
237static const int rdrMax = 8;
238
239private:
241
242static
243struct MonRdrBuff
244 {MonRdrBuff *Next;
245 XrdXrootdMonBurr *Buff;
246 int nextEnt;
247 int flushIt;
248 kXR_int32 lastTOD;
249 XrdSysMutex Mutex;
250 } rdrMon[rdrMax];
251static MonRdrBuff *rdrMP;
252static XrdSysMutex rdrMutex;
253
254inline void Add_io(kXR_unt32 duid, kXR_int32 blen, kXR_int64 offs)
255 {if (lastWindow != currWindow) Mark();
256 else if (nextEnt == lastEnt) Flush();
257 monBuff->info[nextEnt].arg0.val = offs;
258 monBuff->info[nextEnt].arg1.buflen = blen;
259 monBuff->info[nextEnt++].arg2.dictid = duid;
260 }
261static XrdXrootdMonitor *Alloc(int force=0);
262 unsigned char do_Shift(long long xTot, unsigned int &xVal);
263 void Dup(XrdXrootdMonTrace *mrec);
264static void fillHeader(XrdXrootdMonHeader *hdr,
265 const char id, int size);
266static MonRdrBuff *Fetch();
267 void Flush();
268static void Flush(MonRdrBuff *mP);
269static kXR_unt32 Map(char code, XrdXrootdMonitor::User &uInfo,
270 const char *path);
271 void Mark();
272static void startClock();
273static void unAlloc(XrdXrootdMonitor *monp);
274
275static XrdSysMutex windowMutex;
276static char *idRec;
277static int idLen;
278static char *Dest1;
279static int monMode1;
280static XrdNetMsg *InetDest1;
281static char *Dest2;
282static int monMode2;
283static XrdNetMsg *InetDest2;
284 XrdXrootdMonBuff *monBuff;
285static int monBlen;
286 int nextEnt;
287static int lastEnt;
288static int lastRnt;
289static int autoFlash;
290static int autoFlush;
291static int FlushTime;
292 kXR_int32 lastWindow;
293static kXR_int32 currWindow;
294static int rdrTOD;
295static int rdrWin;
296static int rdrNum;
297static kXR_int32 sizeWindow;
298static int isEnabled;
299static int numMonitor;
300static int monIdent;
301static int monRlen;
302static char monIO;
303static char monINFO;
304static char monFILE;
305static char monREDR;
306static char monUSER;
307static char monAUTH;
308static char monACTIVE;
309static char monFSTAT;
310static char monCLOCK;
311};
312#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
XrdXrootdMonTrace info[sizeof(XrdXrootdMonTrace)]
union XrdXrootdMonTrace::@172 arg2
const kXR_char XROOTD_MON_MAPUSER
const kXR_char XROOTD_MON_MAPINFO
const kXR_char XROOTD_MON_MAPPATH
union XrdXrootdMonTrace::@171 arg1
union XrdXrootdMonTrace::@170 arg0
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 Defaults(char *dest1, int m1, char *dest2, int m2)
void appID(char *id)
static time_t Tick()
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 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)