0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetricsHandler.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef ThriftBroker_MetricsHandler_h
28 #define ThriftBroker_MetricsHandler_h
29 
30 #include <AsyncComm/Comm.h>
32 
33 #include <Common/Cronolog.h>
35 #include <Common/MetricsProcess.h>
36 #include <Common/Properties.h>
37 #include <Common/metrics>
38 
39 #include <atomic>
40 #include <memory>
41 #include <mutex>
42 
43 namespace Hypertable {
44 
45  using namespace std;
46 
49 
53  class MetricsHandler : public DispatchHandler {
54  public:
55 
66  MetricsHandler(PropertiesPtr &props, Cronolog *slow_query_log);
67 
70  virtual ~MetricsHandler() {};
71 
73  void start_collecting();
74 
76  void stop_collecting();
77 
85  virtual void handle(EventPtr &event);
86 
90  m_requests.current++;
91  }
92 
95  void error_increment() {
96  m_errors.current++;
97  }
98 
102  m_active_connections++;
103  }
104 
108  m_active_connections--;
109  }
110 
111  private:
112 
114  Comm *m_comm {};
115 
117  MetricsCollectorGangliaPtr m_ganglia_collector;
118 
120  MetricsProcess m_metrics_process;
121 
123  Cronolog *m_slow_query_log {};
124 
126  int64_t m_last_timestamp;
127 
129  int32_t m_collection_interval {};
130 
132  interval_metric<int64_t> m_requests {};
133 
135  interval_metric<int64_t> m_errors {};
136 
138  atomic<int32_t> m_active_connections {0};
139  };
140 
142  typedef std::shared_ptr<MetricsHandler> MetricsHandlerPtr;
143 
145 }
146 
147 #endif // ThriftBroker_MetricsHandler_h
std::shared_ptr< MetricsHandler > MetricsHandlerPtr
Smart pointer to MetricsHandler.
Declarations for MetricsCollectorGanglia.
Program options handling.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
void request_increment()
Increments request count.
Declarations for Cronolog.
void connection_increment()
Increments connection count.
void connection_decrement()
Decrements connection count.
Declarations for DispatchHandler.
Declarations for MetricsProcess.
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
Time based rotating log.
Definition: Cronolog.h:59
std::shared_ptr< MetricsCollectorGanglia > MetricsCollectorGangliaPtr
Smart pointer to MetricsCollectorGanglia.
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Comm.
virtual ~MetricsHandler()
Destructor.
void error_increment()
Increments error count.