IBR-DTNSuite  0.8
daemon/src/StatisticLogger.h
Go to the documentation of this file.
00001 /*
00002  * StatisticLogger.h
00003  *
00004  *  Created on: 05.05.2010
00005  *      Author: morgenro
00006  *
00007  *
00008  * The Statistic Logger generate a statistic about:
00009  *  - Current Neighbors
00010  *  - Recv Bundles
00011  *  - Sent Bundles
00012  *  - Bundles in Storage
00013  *
00014  * This data is logged into a file. The format for this file
00015  * can specified with the "format"-variable.
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::TimerCallback, public dtn::core::EventReceiver
00039                 {
00040                 public:
00041                         enum LoggerType
00042                         {
00043                                 LOGGER_STDOUT = 0,              // All output is human readable and directed into stdout.
00044                                 LOGGER_SYSLOG = 1,              // All output is human readable and directed into the syslog.
00045                                 LOGGER_UDP = 2,                 // Statistically datagrams are sent to a specified address and port. Each interval or if the values are changing.
00046                                 LOGGER_FILE_PLAIN = 10, // All output is machine readable only and appended into a file.
00047                                 LOGGER_FILE_CSV = 11,   // All output is machine readable only and appended into a csv file.
00048                                 LOGGER_FILE_STAT = 12   // All output is machine readable only and directed into a stat file. This file contains only one dataset.
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(ibrcommon::Timer*);
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::Timer _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 /* STATISTICLOGGER_H_ */