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
00061 private:
00062 void writeStdLog(std::ostream &stream);
00063 void writeSyslog(std::ostream &stream);
00064 void writePlainLog(std::ostream &stream);
00065 void writeCsvLog(std::ostream &stream);
00066 void writeStatLog();
00067
00068 void writeUDPLog(ibrcommon::UnicastSocket &socket);
00069
00070 ibrcommon::SimpleTimer _timer;
00071 ibrcommon::File _file;
00072 std::ofstream _fileout;
00073 LoggerType _type;
00074 size_t _interval;
00075
00076 size_t _sentbundles;
00077 size_t _recvbundles;
00078
00079 dtn::core::BundleCore &_core;
00080
00081 ibrcommon::UnicastSocket *_sock;
00082 std::string _address;
00083 unsigned int _port;
00084 };
00085 }
00086 }
00087
00088 #endif