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
Proc RRD Thread.
virtual ~ProcRRDThread()
Destructor.
ProcRRDThread()
Constructor.
virtual void init()
Initialize the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Interface for configuration change handling.
Iterator interface to iterate over config values.
Definition: config.h:75
Thread aspect to log output.
Definition: logging.h:33
Thread aspect create, update, and graph round-robin databases (RRD).
Definition: rrd.h:36
Class representing a graph definition.
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Time wait utility.
Definition: wait.h:33
Fawkes library namespace.