0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DispatchHandlerOperationGetStatistics.cc
Go to the documentation of this file.
1 /*
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; version 3 of the
9  * 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 #include <Common/Compat.h>
22 
24 
27 
28 #include <Common/Error.h>
29 #include <Common/Logger.h>
30 #include <Common/Time.h>
31 
32 using namespace Hypertable;
33 using namespace std;
34 
36  DispatchHandlerOperation(context), m_timer(context->props->get_i32("Hypertable.Monitoring.Interval")) {
37 }
38 
39 void DispatchHandlerOperationGetStatistics::initialize(std::vector<RangeServerStatistics> &results) {
40  int64_t now = get_ts64();
41  for (size_t i = 0; i<results.size(); i++) {
42  m_index[results[i].addr] = &results[i];
43  results[i].fetch_error = Error::NO_RESPONSE;
44  results[i].fetch_timestamp = now;
45  results[i].stats = make_shared<StatsRangeServer>();
46  }
47  m_context->system_state->get(m_specs, &m_generation);
48  m_timer.start();
49 }
50 
51 
53  CommAddress addr;
54  addr.set_proxy(location);
56 }
57 
58 
60  int error;
61  int64_t now = get_ts64();
63  if (iter != m_index.end()) {
64  RangeServerStatistics *stats = iter->second;
65  stats->fetch_duration = now - stats->fetch_timestamp;
66  if (event->type == Event::MESSAGE) {
67  if ((error = Protocol::response_code(event)) != Error::OK) {
68  stats->fetch_error = error;
70  }
71  else {
72  stats->fetch_error = 0;
73  stats->fetch_error_msg = "";
74  try {
75  size_t remaining = event->payload_len - 4;
76  const uint8_t *ptr = event->payload + 4;
78  params.decode(&ptr, &remaining);
79  *stats->stats.get() = params.stats();
80  stats->stats_timestamp = stats->fetch_timestamp;
81  }
82  catch (Exception &e) {
83  stats->fetch_error = e.code();
84  stats->fetch_error_msg = e.what();
85  }
86  }
87  }
88  else {
89  stats->fetch_error = event->error;
90  stats->fetch_error_msg = "";
91  }
92  }
93  else
94  HT_ERROR_OUT << "Received 'get_statistics' response from unexpected connection "
95  << event->addr.format() << HT_END;
96 }
virtual void result_callback(const EventPtr &event)
Post-request hook method.
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
static String string_format_message(const Event *event)
Returns error message decoded standard error MESSAGE generated in response to a request message...
Definition: Protocol.cc:51
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
void initialize(std::vector< RangeServerStatistics > &results)
virtual void start(const String &location)
Method overridden in derived class for issuing requests.
const StatsRangeServer & stats()
Gets range server statistics.
Definition: GetStatistics.h:65
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
DispatchHandler class for managing async RangeServer requests.
Unordered map specialization for InetAddr keys.
Definition: SockAddrMap.h:57
Logging routines and macros.
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Definition: CommAddress.h:76
Compatibility Macros for C/C++.
RangeServer::Client m_rsclient
Range server client object
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
Time related declarations.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Hypertable definitions
void get_statistics(const CommAddress &addr, std::vector< SystemVariable::Spec > &specs, int64_t generation, StatsRangeServer &stats)
Issues an synchronous "get_statistics" request.
Definition: Client.cc:587
void start()
Starts the timer.
Definition: Timer.h:64
Request/response message event.
Definition: Event.h:63
This is a generic exception class for Hypertable.
Definition: Error.h:314
Declarations for GetStatistics response parameters.
Error codes, Exception handling, error logging.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
Response parameters for get statistics function.
Definition: GetStatistics.h:50
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
Definition: Time.cc:40
int code() const
Returns the error code.
Definition: Error.h:391