XRootD
Loading...
Searching...
No Matches
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
44xstats = sp;
45fsP = 0;
46
47Count = 0; // Stats: Number of matches
48errorCnt = 0; // Stats: Number of errors returned
49redirCnt = 0; // Stats: Number of redirects
50stallCnt = 0; // Stats: Number of stalls
51getfCnt = 0; // Stats: Number of getfiles
52putfCnt = 0; // Stats: Number of putfiles
53openCnt = 0; // Stats: Number of opens
54readCnt = 0; // Stats: Number of reads
55prerCnt = 0; // Stats: Number of reads
56rvecCnt = 0; // Stats: Number of readv
57rsegCnt = 0; // Stats: Number of readv segments
58wvecCnt = 0; // Stats: Number of writev
59wsegCnt = 0; // Stats: Number of writev segments
60writeCnt = 0; // Stats: Number of writes
61syncCnt = 0; // Stats: Number of sync
62miscCnt = 0; // Stats: Number of miscellaneous
63AsyncNum = 0; // Stats: Number of async ops
64AsyncMax = 0; // Stats: Number of async max
65AsyncRej = 0; // Stats: Number of async rejected
66AsyncNow = 0; // Stats: Number of async now (not locked)
67Refresh = 0; // Stats: Number of refresh requests
68LoginAT = 0; // Stats: Number of attempted logins
69LoginAU = 0; // Stats: Number of authenticated logins
70LoginUA = 0; // Stats: Number of unauthenticated logins
71AuthBad = 0; // Stats: Number of authentication failures
72aokSCnt = 0; // Stats: Number of signature successes
73badSCnt = 0; // Stats: Number of signature failures
74ignSCnt = 0; // Stats: Number of signature ignored
75}
76
77/******************************************************************************/
78/* S t a t s */
79/******************************************************************************/
80
81int 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//
114 len = snprintf(buff, blen, statfmt,
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}
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
virtual int getStats(char *buff, int blen)=0
virtual void Stats(CallBack *InfoBack, int opts)
Definition XrdStats.cc:150
XrdXrootdStats(XrdStats *sp)
int Stats(char *buff, int blen, int do_sync=0)