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 <core/threading/thread.h>
27 #include <aspect/logging.h>
28 #include <aspect/configurable.h>
29 #include <aspect/clock.h>
30 #include <plugins/rrd/aspect/rrd.h>
31 #include <config/change_handler.h>
32 
33 namespace fawkes {
34  class TimeWait;
35 }
36 
38 : public fawkes::Thread,
39  public fawkes::LoggingAspect,
41  public fawkes::ClockAspect,
42  public fawkes::RRDAspect,
44 {
45  public:
46  ProcRRDThread();
47  virtual ~ProcRRDThread();
48 
49  virtual void init();
50  virtual void loop();
51  virtual void finalize();
52 
53  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
54  protected: virtual void run() { Thread::run(); }
55 
56  private:
57  void add_process(const char *path, std::string pid, std::string name);
58  void remove_process(const char *path);
59  std::string get_process_id(const char *process);
60  void get_cpu(unsigned long int* cpus);
61 
62  virtual void config_tag_changed(const char *new_tag);
63  virtual void config_value_changed(const fawkes::Configuration::ValueIterator *v);
64  virtual void config_comment_changed(const fawkes::Configuration::ValueIterator *v);
65  virtual void config_value_erased(const char *path);
66 
67  private:
68  fawkes::TimeWait *__timewait;
69  int __samplerate;
70  std::string __netinterface;
71  unsigned long int *__lastcpu;
72 
73  fawkes::RRDGraphDefinition *__net_recv_graph;
74  fawkes::RRDGraphDefinition *__net_trans_graph;
75  fawkes::RRDDefinition *__net_rrd;
76 
77  /// @cond INTERNALS
78  typedef struct {
79  std::string pid;
80  std::string name;
81  std::string rrd_name;
82  unsigned long int *last_cpu;
84  fawkes::RRDGraphDefinition *cpu_graph;
85  fawkes::RRDGraphDefinition *mem_graph;
86  fawkes::RRDGraphDefinition *io_read_graph;
87  fawkes::RRDGraphDefinition *io_write_graph;
88  } ProcessInfo;
89  /// @endcond
90 
91  typedef std::map<std::string, ProcessInfo> ProcessMap;
92  ProcessMap __processes;
93 };
94 
95 #endif
Proc RRD Thread.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
Interface for configuration change handling.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread aspect create, update, and graph round-robin databases (RRD).
Definition: rrd.h:36
Class representing a graph definition.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35
Iterator interface to iterate over config values.
Definition: config.h:72
Time wait utility.
Definition: wait.h:32