XRootD
XrdQStats.cc File Reference
#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "XrdApps/XrdMpxXml.hh"
#include "XrdCl/XrdClBuffer.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClURL.hh"
#include "XrdCl/XrdClXRootDResponses.hh"
+ Include dependency graph for XrdQStats.cc:

Go to the source code of this file.

Functions

void Fatal (const XrdCl::XRootDStatus &Status)
 
int main (int argc, char *argv[])
 
void Usage (int rc)
 

Function Documentation

◆ Fatal()

void Fatal ( const XrdCl::XRootDStatus Status)

Definition at line 48 of file XrdQStats.cc.

49 {
50  std::string eText;
51 
52 // If this is an xrootd error then get the xrootd generated error
53 //
54  eText = (Status.code == XrdCl::errErrorResponse ?
55  eText = Status.GetErrorMessage() : Status.ToStr());
56 
57 // Blither and exit
58 //
59  std::cerr <<"xrdqstats: Unable to obtain statistic - " <<eText <<std::endl;
60  exit(3);
61 }
const std::string & GetErrorMessage() const
Get error message.
std::string ToStr() const
Convert to string.
const uint16_t errErrorResponse
Definition: XrdClStatus.hh:105
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:147

References XrdCl::Status::code, XrdCl::errErrorResponse, XrdCl::XRootDStatus::GetErrorMessage(), and XrdCl::XRootDStatus::ToStr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 87 of file XrdQStats.cc.

88 {
89  extern char *optarg;
90  extern int optind, opterr, optopt;
92  XrdMpxXml *xP = 0;
93  const char *Stats = "bldpsu", *pgm = "xrdqstats: ";
94  const char *valOpts = "df:i:n:s:z";
95  int WTime = 0, Count = 0;
96  char obuff[65536];
97  char *sP, c;
98  bool Debug = false, nozed = false;
99 
100 // Process the options
101 //
102  opterr = 0;
103  if (argc > 1 && '-' == *argv[1])
104  while ((c = getopt(argc,argv,valOpts)) && ((unsigned char)c != 0xff))
105  { switch(c)
106  {
107  case 'd': Debug = true;
108  break;
109  case 'f': if (!strcmp(optarg, "cgi" )) fType = XrdMpxXml::fmtCGI;
110  else if (!strcmp(optarg, "flat")) fType = XrdMpxXml::fmtFlat;
111  else if (!strcmp(optarg, "xml" )) fType = XrdMpxXml::fmtXML;
112  else {std::cerr <<pgm <<"Invalid format - " <<optarg <<std::endl;
113  Usage(1);
114  }
115  break;
116  case 'h': Usage(0);
117  break;
118  case 'i': if ((WTime = atoi(optarg)) <= 0)
119  {std::cerr <<pgm <<"Invalid interval - " <<optarg <<std::endl;
120  Usage(1);
121  }
122  break;
123  case 'n': if ((Count = atoi(optarg)) <= 0)
124  {std::cerr <<pgm <<"Invalid count - " <<optarg <<std::endl;
125  Usage(1);
126  }
127  break;
128  case 's': sP = optarg;
129  while(*sP)
130  {if (!index("abcdipsuz", *sP))
131  {std::cerr <<pgm<<"Invalid statistic letter - "<<*sP<<std::endl;
132  Usage(1);
133  } else if (*sP == 'c') *sP = 'l';
134  sP++;
135  }
136  Stats = optarg;
137  break;
138  case 'z': nozed = true;
139  break;
140  default: std::cerr <<pgm <<'-' <<char(optopt);
141  if (c == ':') std::cerr <<" value not specified." <<std::endl;
142  else std::cerr <<" option is invalid" <<std::endl;
143  Usage(1);
144  break;
145  }
146  }
147 
148 // Make sure host has been specified
149 //
150  if (optind >= argc)
151  {std::cerr <<pgm <<"Host has not been specified." <<std::endl; Usage(1);}
152 
153 // Construct the URL to get to the server
154 //
155  std::string sURL("root://");
156  sURL += argv[optind];
157  XrdCl::URL fsURL(sURL);
158  if (!fsURL.IsValid())
159  {std::cerr <<pgm <<"Invalid host specification - " <<argv[optind] <<std::endl;
160  Usage(1);
161  }
162 
163 // Establish what we wiil be asking for
164 //
165  XrdCl::Buffer wantStats;
166  wantStats.FromString(std::string(Stats));
167 
168 // Establish count and interval
169 //
170  if (!WTime && Count) WTime = 10;
171  else if (WTime && !Count) Count = -1;
172  else if (!WTime && !Count) Count = 1;
173 
174 // Establish format
175 //
176  if (fType != XrdMpxXml::fmtXML) xP = new XrdMpxXml(fType, nozed, Debug);
177 
178 // Create the file system to query the stats
179 //
180  XrdCl::FileSystem theFS(fsURL);
181 
182 // Perform statistics gathering and display
183 //
184  XrdCl::Buffer *theStats;
185  XrdCl::XRootDStatus xStatus;
186  while(Count--)
187  {xStatus = theFS.Query(XrdCl::QueryCode::Stats, wantStats, theStats);
188  if (!xStatus.IsOK()) Fatal(xStatus);
189  if (!xP) std::cout <<theStats->GetBuffer() <<std::endl;
190  else {int rc, wLen = xP->Format(0, theStats->GetBuffer(), obuff);
191  char *bP = obuff;
192  while(wLen > 0)
193  {do {rc = write(STDOUT_FILENO, bP, wLen);}
194  while(rc < 0 && errno == EINTR);
195  wLen -= rc; bP += rc;
196  }
197  }
198  delete theStats;
199  if (WTime) sleep(WTime);
200  if (Count) std::cout <<"\n";
201  }
202 
203 // All done
204 //
205  return 0;
206 }
int optopt
int optind
ssize_t write(int fildes, const void *buf, size_t nbyte)
void Usage(int rc)
Definition: XrdQStats.cc:67
void Fatal(const XrdCl::XRootDStatus &Status)
Definition: XrdQStats.cc:48
Binary blob representation.
Definition: XrdClBuffer.hh:34
void FromString(const std::string str)
Fill the buffer from a string.
Definition: XrdClBuffer.hh:205
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
Send file/filesystem queries to an XRootD cluster.
URL representation.
Definition: XrdClURL.hh:31
int Format(const char *Host, char *ibuff, char *obuff)
Definition: XrdMpxXml.cc:242
XrdPosixStats Stats
Definition: XrdPosixFile.cc:64
XrdSfsFileSystem * theFS
Definition: XrdSsiFile.cc:54
@ Stats
Query server stats.
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References Macaroons::Debug, Fatal(), XrdMpxXml::fmtCGI, XrdMpxXml::fmtFlat, XrdMpxXml::fmtText, XrdMpxXml::fmtXML, XrdMpxXml::Format(), XrdCl::Buffer::FromString(), XrdCl::Buffer::GetBuffer(), XrdCl::Status::IsOK(), XrdCl::URL::IsValid(), optind, optopt, XrdCl::QueryCode::Stats, XrdPosixGlobals::Stats, XrdSsi::theFS, Usage(), and write().

+ Here is the call graph for this function:

◆ Usage()

void Usage ( int  rc)

Definition at line 67 of file XrdQStats.cc.

68 {
69  std::cerr <<"\nUsage: xrdqstats [opts] <host>[:<port>]\n"
70  "\nopts: -f {cgi|flat|xml} -h -i <sec> -n <cnt> -s what -z\n"
71  "\n-f specify display format (default is wordy text format)."
72  "\n-i number of seconds to wait before between redisplays, default 10."
73  "\n-n number of redisplays; if -s > 0 and -n unspecified goes forever."
74  "\n-z does not display items with a zero value (wordy text only).\n"
75  "\nwhat: one or more of the following letters to select statistics:"
76  "\na - All (default) b - Buffer usage d - Device polling"
77  "\ni - Identification c - Connections p - Protocols"
78  "\ns - Scheduling u - Usage data z - Synchronized info"
79  <<std::endl;
80  exit(rc);
81 }

Referenced by main().

+ Here is the caller graph for this function: