0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeMetrics.cc
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2013 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 #include <Common/Compat.h>
28 
29 #include "RangeMetrics.h"
30 
31 #include <Hypertable/Lib/Key.h>
33 
34 #include <Common/Error.h>
35 #include <Common/Logger.h>
36 #include <Common/StringExt.h>
37 
38 #include <boost/algorithm/string.hpp>
39 
40 using namespace Hypertable;
41 using namespace Hypertable::Lib::RS_METRICS;
42 using namespace std;
43 
44 RangeMeasurement::RangeMeasurement(const char *measurement, size_t len) {
45  memset(this, 0, sizeof(RangeMeasurement));
46  parse_measurement(measurement, len);
47 }
48 
49 void RangeMeasurement::parse_measurement(const char *measurement, size_t len) {
50  vector<String> splits;
51  String str(measurement, len);
52  boost::split(splits, str, boost::is_any_of(":,"));
53  version = atoi(splits[0].c_str());
54 
55  if (version == 2) {
56  if (splits.size() != 11)
58  format("Measurement string '%s' has %d components, expected 11.",
59  str.c_str(), (int)splits.size()));
60  }
61  else if (version == 3) {
62  if (splits.size() != 12)
64  format("Measurement string '%s' has %d components, expected 12.",
65  str.c_str(), (int)splits.size()));
66  }
67  else
69  format("ServerMetrics version=%d expected 2", (int)version));
70 
71 
72  size_t i=1;
73  timestamp = strtoll(splits[i++].c_str(), 0, 0);
74  disk_used = strtoll(splits[i++].c_str(), 0, 0);
75  memory_used = strtoll(splits[i++].c_str(), 0, 0);
76  if (version == 3)
77  compression_ratio = strtod(splits[i++].c_str(), 0);
78  disk_byte_read_rate = strtod(splits[i++].c_str(), 0);
79  byte_write_rate = strtod(splits[i++].c_str(), 0);
80  byte_read_rate = strtod(splits[i++].c_str(), 0);
81  update_rate = strtod(splits[i++].c_str(), 0);
82  scan_rate = strtod(splits[i++].c_str(), 0);
83  cell_write_rate = strtod(splits[i++].c_str(), 0);
84  cell_read_rate = strtod(splits[i++].c_str(), 0);
85 }
86 
87 RangeMetrics::RangeMetrics(const char *server_id, const char *table_id,
88  const char *end_row)
89  : m_server_id(server_id), m_table_id(table_id), m_end_row(end_row), m_start_row_set(false),
90  m_last_move_set(false) {
91 }
92 
93 void RangeMetrics::add_measurement(const char *measurement, size_t len) {
94  try {
95  RangeMeasurement rm(measurement, len);
96  m_measurements.push_back(rm);
97  }
98  catch (Exception &e) {
99  if (e.code() == Error::NOT_IMPLEMENTED) {
100  HT_WARN_OUT << e << HT_END;
101  }
102  else
103  HT_THROW(e.code(), e.what());
104  }
105 }
106 
107 void RangeMetrics::set_last_move(const char *move, size_t len) {
108  String str(move, len);
109  m_last_move = strtoll(str.c_str(), 0, 0);
110  m_last_move_set = true;
111 }
112 
114  if (!m_start_row_set)
115  return false;
116  // don't move ROOT range
118  return false;
119  // TODO: don't move a range that was moved recently
120  return true;
121 }
static const char * METADATA_ID
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
Facilities for reading and writing sys/RS_METRICS table.
Declarations for TableIdentifier and TableIdentifierManaged.
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
STL namespace.
Declarations for RangeMetrics.
Logging routines and macros.
Compatibility Macros for C/C++.
void parse_measurement(const char *measurement, size_t len)
Definition: RangeMetrics.cc:49
#define HT_END
Definition: Logger.h:220
RangeMetrics(const char *server, const char *table_id, const char *end_row)
Definition: RangeMetrics.cc:87
#define HT_WARN_OUT
Definition: Logger.h:291
void add_measurement(const char *measurement, size_t len)
Definition: RangeMetrics.cc:93
Hypertable definitions
Single range metrics measurement.
Definition: RangeMetrics.h:43
bool split(int flags)
Tests the SPLIT bit of flags
This is a generic exception class for Hypertable.
Definition: Error.h:314
static const char * END_ROOT_ROW
Definition: Key.h:50
void set_last_move(const char *move, size_t len)
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
std::vector< RangeMeasurement > m_measurements
Definition: RangeMetrics.h:94
int code() const
Returns the error code.
Definition: Error.h:391