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 FsBroker_Lib_MetricsHandler_h
28 #define FsBroker_Lib_MetricsHandler_h
29 
30 #include <AsyncComm/Comm.h>
32 
34 #include <Common/MetricsProcess.h>
35 #include <Common/Properties.h>
36 #include <Common/metrics>
37 
38 #include <memory>
39 #include <mutex>
40 
41 namespace Hypertable {
42 namespace FsBroker {
43 namespace Lib {
44 
47 
52  public:
53 
64  MetricsHandler(PropertiesPtr &props, const std::string &type);
65 
68  virtual ~MetricsHandler() {};
69 
71  void start_collecting();
72 
74  void stop_collecting();
75 
82  virtual void handle(EventPtr &event);
83 
87  void add_bytes_read(int64_t count) {
88  std::lock_guard<std::mutex> lock(m_mutex);
89  m_bytes_read += count;
90  }
91 
95  void add_bytes_written(int64_t count) {
96  std::lock_guard<std::mutex> lock(m_mutex);
97  m_bytes_written += count;
98  }
99 
104  void add_sync(int64_t latency_nsec) {
105  std::lock_guard<std::mutex> lock(m_mutex);
106  m_syncs++;
107  m_sync_latency += (int)(latency_nsec/1000000LL);
108  }
109 
113  std::lock_guard<std::mutex> lock(m_mutex);
114  m_errors++;
115  }
116 
117  private:
120 
123 
126 
129 
131  std::string m_type;
132 
135 
138 
140  int64_t m_bytes_written {};
141 
143  int64_t m_bytes_read {};
144 
146  int32_t m_sync_latency {};
147 
149  int32_t m_syncs {};
150 
152  int32_t m_errors {};
153 
154  };
155 
157  typedef std::shared_ptr<MetricsHandler> MetricsHandlerPtr;
158 
160 
161 }}}
162 
163 #endif // FsBroker_Lib_MetricsHandler_h
static std::mutex mutex
Definition: Logger.cc:43
int32_t m_syncs
Syncs since last metrics collection.
int32_t m_collection_interval
Metrics collection interval
Abstract base class for application dispatch handlers registered with AsyncComm.
Declarations for MetricsCollectorGanglia.
Program options handling.
int64_t m_bytes_read
Bytes read since last metrics collection.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
void start_collecting()
Starts metrics collection.
virtual void handle(EventPtr &event)
Collects and publishes metrics.
MetricsProcess m_metrics_process
General process metrics tracker.
Declarations for DispatchHandler.
Declarations for MetricsProcess.
void add_bytes_read(int64_t count)
Adds bytes read.
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
void add_bytes_written(int64_t count)
Adds bytes written.
int64_t m_last_timestamp
Timestamp of last metrics collection
int32_t m_errors
Error count since last metrics collection.
std::shared_ptr< MetricsCollectorGanglia > MetricsCollectorGangliaPtr
Smart pointer to MetricsCollectorGanglia.
Collects and publishes FsBroker metrics.
Hypertable definitions
void add_sync(int64_t latency_nsec)
Adds sync information.
int64_t m_bytes_written
Bytes written since last metrics collection.
Entry point to AsyncComm service.
Definition: Comm.h:61
MetricsCollectorGangliaPtr m_ganglia_collector
Ganglia metrics collector.
std::string m_type
FsBroker type (e.g. "local", "qfs", etc.)
Declarations for Comm.
Computes and publishes general process metrics.
MetricsHandler(PropertiesPtr &props, const std::string &type)
Constructor.
int32_t m_sync_latency
Cumulative sync latency since last metrics collection.
std::mutex m_mutex
Mutex for serializing access to members
std::shared_ptr< MetricsHandler > MetricsHandlerPtr
Smart pointer to MetricsHandler.
void stop_collecting()
Stops metrics collection.
void increment_error_count()
Increments error count.