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