xrootd
XrdMonCtrWriter.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonCtrWriter.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
13 #ifndef XRDMONCTRWRITER_HH
14 #define XRDMONCTRWRITER_HH
15 
16 #include "XrdMon/XrdMonTypes.hh"
17 #include <fstream>
18 #include <string>
19 using std::fstream;
20 using std::ostream;
21 using std::string;
22 
23 class XrdMonHeader;
24 
25 // Class writes data to a log file.
26 // One instance per one xrootd instance.
27 // It buffers data in memory to avoid
28 // overloading disks
29 
31 public:
32  XrdMonCtrWriter(senderid_t senderId, kXR_int32 stod);
34  void operator()(const char* packet,
35  const XrdMonHeader& header,
36  long currentTime);
37 
38  kXR_int32 prevStod() const { return _prevStod; }
39 
40  void forceClose();
41  long lastActivity() const { return _lastActivity; }
42 
43  static void setBaseDir(const char* dir) { _baseDir = dir; }
44  static void setMaxLogSize(kXR_int64 size) { _maxLogSize = size;}
45  static void setBufferSize(int size) { _bufferSize = size;}
46 
47 private:
49 
50  bool logIsOpen() { return _file.is_open(); }
51  bool logIsFull() { return (kXR_int64) _file.tellp() >= _maxLogSize; }
52  bool bufferIsFull(packetlen_t x) { return _bPos + x > _bufferSize; }
53 
54  string logName(LogType t) const;
55  void mkActiveLogNameDirs() const;
56 
57  void flushBuffer();
58  void openLog();
59  void closeLog();
60  void publish();
61 
62 private:
63  static string _baseDir;
65  static int _bufferSize;
66  static long _totalArchived;
67 
68  kXR_int32 _prevStod; // for checking if xrootd restarted
69 
70  string _timestamp;
71  hp_t _sender; // { hostName, portNr }
72  char* _buffer;
73  kXR_int32 _bPos; // position where to write to buffer
74  fstream _file; // non-published log file
75 
76  long _lastActivity; // approx time of last activity
77 
78  friend ostream& operator<<(ostream& o, const XrdMonCtrWriter& w);
79 };
80 
81 #endif /* XRDMONCTRWRITER_HH */