Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef STATISTICLOGGER_H_
00020 #define STATISTICLOGGER_H_
00021
00022 #include "Component.h"
00023 #include "core/EventReceiver.h"
00024 #include "core/Node.h"
00025 #include "core/BundleCore.h"
00026 #include <ibrcommon/data/File.h>
00027 #include <ibrcommon/thread/Timer.h>
00028 #include <list>
00029 #include <string>
00030 #include <fstream>
00031 #include <iostream>
00032 #include <ibrcommon/net/UnicastSocket.h>
00033
00034 namespace dtn
00035 {
00036 namespace daemon
00037 {
00038 class StatisticLogger : public IntegratedComponent, public ibrcommon::SimpleTimerCallback, public dtn::core::EventReceiver
00039 {
00040 public:
00041 enum LoggerType
00042 {
00043 LOGGER_STDOUT = 0,
00044 LOGGER_SYSLOG = 1,
00045 LOGGER_UDP = 2,
00046 LOGGER_FILE_PLAIN = 10,
00047 LOGGER_FILE_CSV = 11,
00048 LOGGER_FILE_STAT = 12
00049 };
00050
00051 StatisticLogger(LoggerType type, unsigned int interval, std::string address = "127.0.0.1", unsigned int port = 1234);
00052 StatisticLogger(LoggerType type, unsigned int interval, ibrcommon::File file);
00053 virtual ~StatisticLogger();
00054
00055 void componentUp();
00056 void componentDown();
00057
00058 size_t timeout(size_t identifier);
00059 void raiseEvent(const dtn::core::Event *evt);
00060
00064 virtual const std::string getName() const;
00065
00066 private:
00067 void writeStdLog(std::ostream &stream);
00068 void writeSyslog(std::ostream &stream);
00069 void writePlainLog(std::ostream &stream);
00070 void writeCsvLog(std::ostream &stream);
00071 void writeStatLog();
00072
00073 void writeUDPLog(ibrcommon::UnicastSocket &socket);
00074
00075 ibrcommon::SimpleTimer _timer;
00076 ibrcommon::File _file;
00077 std::ofstream _fileout;
00078 LoggerType _type;
00079 size_t _interval;
00080
00081 size_t _sentbundles;
00082 size_t _recvbundles;
00083
00084 dtn::core::BundleCore &_core;
00085
00086 ibrcommon::UnicastSocket *_sock;
00087 std::string _address;
00088 unsigned int _port;
00089 };
00090 }
00091 }
00092
00093 #endif