Fawkes API  Fawkes Development Version
procrrd_thread.h
1 
2 /***************************************************************************
3  * systemrrd_thread.h - Fawkes Proc RRD Thread
4  *
5  * Created: Mon Dec 17 12:54:00 2012
6  * Copyright 2012 Bastian Klingen
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _PLUGINS_PROCRRD_PROCRRD_THREAD_H_
24 #define _PLUGINS_PROCRRD_PROCRRD_THREAD_H_
25 
26 #include <aspect/clock.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <config/change_handler.h>
30 #include <core/threading/thread.h>
31 #include <plugins/rrd/aspect/rrd.h>
32 
33 namespace fawkes {
34 class TimeWait;
35 }
36 
38  public fawkes::LoggingAspect,
40  public fawkes::ClockAspect,
41  public fawkes::RRDAspect,
43 {
44 public:
45  ProcRRDThread();
46  virtual ~ProcRRDThread();
47 
48  virtual void init();
49  virtual void loop();
50  virtual void finalize();
51 
52  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
53 protected:
54  virtual void
55  run()
56  {
57  Thread::run();
58  }
59 
60 private:
61  void add_process(const char *path, const std::string &pid, const std::string &name);
62  void remove_process(const char *path);
63  std::string get_process_id(const char *process);
64  void get_cpu(unsigned long int *cpus);
65 
66  virtual void config_tag_changed(const char *new_tag);
67  virtual void config_value_changed(const fawkes::Configuration::ValueIterator *v);
68  virtual void config_comment_changed(const fawkes::Configuration::ValueIterator *v);
69  virtual void config_value_erased(const char *path);
70 
71 private:
72  fawkes::TimeWait * timewait_;
73  int samplerate_;
74  std::string netinterface_;
75  unsigned long int *lastcpu_;
76 
77  fawkes::RRDGraphDefinition *net_recv_graph_;
78  fawkes::RRDGraphDefinition *net_trans_graph_;
79  fawkes::RRDDefinition * net_rrd_;
80 
81  /// @cond INTERNALS
82  typedef struct
83  {
84  std::string pid;
85  std::string name;
86  std::string rrd_name;
87  unsigned long int * last_cpu;
89  fawkes::RRDGraphDefinition *cpu_graph;
90  fawkes::RRDGraphDefinition *mem_graph;
91  fawkes::RRDGraphDefinition *io_read_graph;
92  fawkes::RRDGraphDefinition *io_write_graph;
93  } ProcessInfo;
94  /// @endcond
95 
96  typedef std::map<std::string, ProcessInfo> ProcessMap;
97  ProcessMap processes_;
98 };
99 
100 #endif
fawkes::RRDGraphDefinition
Definition: rrd_descriptions.h:470
ProcRRDThread::init
virtual void init()
Initialize the thread.
Definition: procrrd_thread.cpp:56
fawkes::RRDAspect
Definition: rrd.h:41
fawkes::ConfigurationChangeHandler
Definition: change_handler.h:37
ProcRRDThread::ProcRRDThread
ProcRRDThread()
Constructor.
Definition: procrrd_thread.cpp:44
fawkes::Thread::name
const char * name() const
Definition: thread.h:100
ProcRRDThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: procrrd_thread.h:55
fawkes::Configuration::ValueIterator
Definition: config.h:77
ProcRRDThread::loop
virtual void loop()
Code to execute in the thread.
Definition: procrrd_thread.cpp:527
fawkes
fawkes::LoggingAspect
Definition: logging.h:38
ProcRRDThread
Definition: procrrd_thread.h:37
ProcRRDThread::finalize
virtual void finalize()
Finalize the thread.
Definition: procrrd_thread.cpp:213
fawkes::Thread
Definition: thread.h:45
fawkes::TimeWait
Definition: wait.h:38
fawkes::RRDDefinition
Definition: rrd_descriptions.h:168
ProcRRDThread::~ProcRRDThread
virtual ~ProcRRDThread()
Destructor.
Definition: procrrd_thread.cpp:51
fawkes::ConfigurableAspect
Definition: configurable.h:38
fawkes::ClockAspect
Definition: clock.h:40