XRootD
XrdXrootdStats.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d X r o o t d S t a t s . c c */
4 /* */
5 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* Produced by Andrew Hanushevsky for Stanford University under contract */
7 /* DE-AC02-76-SFO0515 with the Department of Energy */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
30 #include <cstdio>
31 
32 #include "Xrd/XrdStats.hh"
36 
37 /******************************************************************************/
38 /* C o n s t r c u t o r */
39 /******************************************************************************/
40 
42 {
43 
44 xstats = sp;
45 fsP = 0;
46 
47 Count = 0; // Stats: Number of matches
48 errorCnt = 0; // Stats: Number of errors returned
49 redirCnt = 0; // Stats: Number of redirects
50 stallCnt = 0; // Stats: Number of stalls
51 getfCnt = 0; // Stats: Number of getfiles
52 putfCnt = 0; // Stats: Number of putfiles
53 openCnt = 0; // Stats: Number of opens
54 readCnt = 0; // Stats: Number of reads
55 prerCnt = 0; // Stats: Number of reads
56 rvecCnt = 0; // Stats: Number of readv
57 rsegCnt = 0; // Stats: Number of readv segments
58 wvecCnt = 0; // Stats: Number of writev
59 wsegCnt = 0; // Stats: Number of writev segments
60 writeCnt = 0; // Stats: Number of writes
61 syncCnt = 0; // Stats: Number of sync
62 miscCnt = 0; // Stats: Number of miscellaneous
63 AsyncNum = 0; // Stats: Number of async ops
64 AsyncMax = 0; // Stats: Number of async max
65 AsyncRej = 0; // Stats: Number of async rejected
66 AsyncNow = 0; // Stats: Number of async now (not locked)
67 Refresh = 0; // Stats: Number of refresh requests
68 LoginAT = 0; // Stats: Number of attempted logins
69 LoginAU = 0; // Stats: Number of authenticated logins
70 LoginUA = 0; // Stats: Number of unauthenticated logins
71 AuthBad = 0; // Stats: Number of authentication failures
72 aokSCnt = 0; // Stats: Number of signature successes
73 badSCnt = 0; // Stats: Number of signature failures
74 ignSCnt = 0; // Stats: Number of signature ignored
75 }
76 
77 /******************************************************************************/
78 /* S t a t s */
79 /******************************************************************************/
80 
81 int XrdXrootdStats::Stats(char *buff, int blen, int do_sync)
82 {
83  static const char statfmt[] = "<stats id=\"xrootd\"><num>%d</num>"
84  "<ops><open>%d</open><rf>%d</rf><rd>%lld</rd><pr>%lld</pr>"
85  "<rv>%lld</rv><rs>%lld</rs>"
86  "<wv>%lld</wv><ws>%lld</ws><wr>%lld</wr>"
87  "<sync>%d</sync><getf>%d</getf><putf>%d</putf><misc>%d</misc></ops>"
88  "<sig><ok>%d</ok><bad>%d</bad><ign>%d</ign></sig>"
89  "<aio><num>%lld</num><max>%d</max><rej>%lld</rej></aio>"
90  "<err>%d</err><rdr>%lld</rdr><dly>%d</dly>"
91  "<lgn><num>%d</num><af>%d</af><au>%d</au><ua>%d</ua></lgn></stats>";
92 // 1 2 3 4 5 6 7 8
93  static const long long LLMax = 0x7fffffffffffffffLL;
94  static const int INMax = 0x7fffffff;
95  int len;
96 
97 // If no buffer, caller wants the maximum size we will generate
98 //
99  if (!buff)
100  {char dummy[4096]; // Almost any size will do
101  len = snprintf(dummy, sizeof(dummy), statfmt,
102  INMax, INMax, INMax, LLMax,
103  LLMax, LLMax, LLMax, LLMax, LLMax, LLMax, INMax, INMax,
104  INMax, INMax,
105  INMax, INMax, INMax,
106  LLMax, INMax, LLMax, INMax, LLMax, INMax,
107  INMax, INMax, INMax, INMax);
108  return len + (fsP ? fsP->getStats(0,0) : 0);
109  }
110 
111 // Format our statistics
112 //
113  statsMutex.Lock();
114  len = snprintf(buff, blen, statfmt,
117  syncCnt, getfCnt,
118  putfCnt, miscCnt,
122  statsMutex.UnLock();
123 
124 // Now include filesystem statistics and return
125 //
126  if (fsP) len += fsP->getStats(buff+len, blen-len);
127  return len;
128 }
129 
130 /******************************************************************************/
131 /* S t a t s */
132 /******************************************************************************/
133 
135 {
136  class statsInfo : public XrdStats::CallBack
137  {public: void Info(const char *buff, int bsz)
138  {rc = respP->Send((void *)buff, bsz+1);}
139  statsInfo(XrdXrootdResponse *rP) : respP(rP), rc(0) {}
140  ~statsInfo() {}
141  XrdXrootdResponse *respP;
142  int rc;
143  };
144  statsInfo statsResp(&resp);
145  int xopts = 0;
146 
147  while(*opts)
148  {switch(*opts)
149  {case 'a': xopts |= XRD_STATS_ALL; break;
150  case 'b': xopts |= XRD_STATS_BUFF; break; // b_uff
151  case 'i': xopts |= XRD_STATS_INFO; break; // i_nfo
152  case 'l': xopts |= XRD_STATS_LINK; break; // l_ink
153  case 'd': xopts |= XRD_STATS_POLL; break; // d_evice
154  case 'u': xopts |= XRD_STATS_PROC; break; // u_sage
155  case 'p': xopts |= XRD_STATS_PROT; break; // p_rotocol
156  case 's': xopts |= XRD_STATS_SCHD; break; // s_scheduler
157  default: break;
158  }
159  opts++;
160  }
161 
162  if (!xopts) return resp.Send();
163 
164  xstats->Stats(&statsResp, xopts);
165  return statsResp.rc;
166 }
@ Info
struct myOpts opts
#define XRD_STATS_POLL
Definition: XrdStats.hh:40
#define XRD_STATS_INFO
Definition: XrdStats.hh:37
#define XRD_STATS_LINK
Definition: XrdStats.hh:39
#define XRD_STATS_BUFF
Definition: XrdStats.hh:38
#define XRD_STATS_SCHD
Definition: XrdStats.hh:43
#define XRD_STATS_ALL
Definition: XrdStats.hh:36
#define XRD_STATS_PROT
Definition: XrdStats.hh:42
#define XRD_STATS_PROC
Definition: XrdStats.hh:41
XrdSysMutex statsMutex
Definition: XrdOucStats.hh:55
virtual int getStats(char *buff, int blen)=0
virtual void Stats(CallBack *InfoBack, int opts)
Definition: XrdStats.cc:150
XrdXrootdStats(XrdStats *sp)
long long AsyncRej
long long rsegCnt
long long wsegCnt
long long AsyncNow
long long redirCnt
long long readCnt
long long prerCnt
long long AsyncNum
long long rvecCnt
long long writeCnt
long long wvecCnt
int Stats(char *buff, int blen, int do_sync=0)