0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StatsRangeServer.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.
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 
23 #include "StatsRangeServer.h"
24 
25 #include <Hypertable/Lib/KeySpec.h>
26 
27 #include <Common/Logger.h>
28 #include <Common/Serialization.h>
29 
30 #include <string>
31 
32 using namespace Hypertable;
33 using namespace std;
34 
35 namespace {
36  enum Group {
37  PRIMARY_GROUP = 0
38  };
39 }
40 
42  group_ids[0] = PRIMARY_GROUP;
43 }
44 
45 
47  const char *base, *ptr;
48  string datadirs = props->get_str("Hypertable.RangeServer.Monitoring.DataDirectories");
49  string dir;
50  std::vector<String> dirs;
51 
52  boost::trim_if(datadirs, boost::is_any_of(" \t\"'"));
53 
54  base = datadirs.c_str();
55  while ((ptr = strchr(base, ',')) != 0) {
56  dir = String(base, ptr-base);
57  boost::trim(dir);
58  dirs.push_back(dir);
59  base = ptr+1;
60  }
61  dir = String(base);
62  boost::trim(dir);
63  dirs.push_back(dir);
64 
68  group_ids[0] = PRIMARY_GROUP;
69 }
70 
71 StatsRangeServer::StatsRangeServer(const StatsRangeServer &other) : StatsSerializable(other.id, other.group_count) {
72  memcpy(group_ids, other.group_ids, group_count);
73  location = other.location;
74  version = other.version;
75  timestamp = other.timestamp;
76  range_count = other.range_count;
78  file_count = other.file_count;
79  scan_count = other.scan_count;
82  update_count = other.update_count;
85  sync_count = other.sync_count;
95  cpu_user = other.cpu_user;
96  cpu_sys = other.cpu_sys;
97  live = other.live;
98  system = other.system;
99  tables = other.tables;
100 }
101 
103  if (location != other.location ||
104  version != other.version ||
105  timestamp != other.timestamp ||
106  range_count != other.range_count ||
107  scanner_count != other.scanner_count ||
108  file_count != other.file_count ||
109  scan_count != other.scan_count ||
110  scanned_cells != other.scanned_cells ||
111  scanned_bytes != other.scanned_bytes ||
112  update_count != other.update_count ||
113  updated_cells != other.updated_cells ||
114  updated_bytes != other.updated_bytes ||
115  sync_count != other.sync_count ||
124  tracked_memory != other.tracked_memory ||
127  live != other.live ||
128  system != other.system)
129  return false;
130  if (tables.size() != other.tables.size())
131  return false;
132  for (size_t i=0; i<tables.size(); i++) {
133  if (tables[i] != other.tables[i])
134  return false;
135  }
136  return true;
137 }
138 
139 
140 
141 size_t StatsRangeServer::encoded_length_group(int group) const {
142  if (group == PRIMARY_GROUP) {
144  Serialization::encoded_length_vstr(version) + 4*2 + 8*18 + 1 + \
148  for (size_t i=0; i<tables.size(); i++)
149  len += tables[i].encoded_length();
150  return len;
151  }
152  else
153  HT_FATALF("Invalid group number (%d)", group);
154  return 0;
155 }
156 
157 void StatsRangeServer::encode_group(int group, uint8_t **bufp) const {
158  if (group == PRIMARY_GROUP) {
184  system.encode(bufp);
185  Serialization::encode_vi32(bufp, tables.size());
186  for (size_t i=0; i<tables.size(); i++)
187  tables[i].encode(bufp);
188  }
189  else
190  HT_FATALF("Invalid group number (%d)", group);
191 }
192 
193 void StatsRangeServer::decode_group(int group, uint16_t len, const uint8_t **bufp, size_t *remainp) {
194  if (group == PRIMARY_GROUP) {
195  location = Serialization::decode_vstr(bufp, remainp);
196  version = Serialization::decode_vstr(bufp, remainp);
197  timestamp = Serialization::decode_i64(bufp, remainp);
198  range_count = Serialization::decode_i32(bufp, remainp);
199  scanner_count = Serialization::decode_i32(bufp, remainp);
200  file_count = Serialization::decode_i64(bufp, remainp);
201  scan_count = Serialization::decode_i64(bufp, remainp);
202  scanned_cells = Serialization::decode_i64(bufp, remainp);
203  scanned_bytes = Serialization::decode_i64(bufp, remainp);
204  update_count = Serialization::decode_i64(bufp, remainp);
205  updated_cells = Serialization::decode_i64(bufp, remainp);
206  updated_bytes = Serialization::decode_i64(bufp, remainp);
207  sync_count = Serialization::decode_i64(bufp, remainp);
216  tracked_memory = Serialization::decode_i64(bufp, remainp);
217  cpu_user = Serialization::decode_double(bufp, remainp);
218  cpu_sys = Serialization::decode_double(bufp, remainp);
219  live = Serialization::decode_bool(bufp, remainp);
220  system.decode(bufp, remainp);
221  size_t table_count = Serialization::decode_vi32(bufp, remainp);
222  tables.clear();
223  for (size_t i=0; i<table_count; i++) {
224  StatsTable table;
225  table.decode(bufp, remainp);
226  tables.push_back(table);
227  }
228  }
229  else {
230  HT_WARNF("Unrecognized StatsRangeServer group %d, skipping...", group);
231  (*bufp) += len;
232  (*remainp) -= len;
233  }
234 }
Abstract base class for managing serialized statistics.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
int encoded_length_double()
Length of an encoded double (16 bytes)
#define HT_WARNF(msg,...)
Definition: Logger.h:290
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
virtual void decode_group(int group, uint16_t len, const uint8_t **bufp, size_t *remainp)
Abstruct function to deserialize a group from a memory buffer.
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
std::vector< StatsTable > tables
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
static const int64_t TIMESTAMP_MIN
Definition: KeySpec.h:34
uint8_t group_count
Number of groups in group_ids.
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
int encoded_length_vi32(uint32_t val)
Length of a variable length encoded 32-bit integer (up to 5 bytes)
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
Group
Definition: StatsSystem.cc:38
size_t encoded_length() const
Returns the encoded length of this object.
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
virtual void encode_group(int group, uint8_t **bufp) const
Abstruct function to serialize a group into a memory buffer.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
void decode(const uint8_t **bufp, size_t *remainp)
Deserializes this object from a buffer.
virtual size_t encoded_length_group(int group) const
Abstruct function returning the serialized length of a group.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
#define HT_FATALF(msg,...)
Definition: Logger.h:343
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
Definition: Serialization.h:84
double decode_double(const uint8_t **bufp, size_t *remainp)
Decodes a double as 64-bit left-of-decimal, followed by 64-bit right-of-decimal, both in little-endia...
bool equal(double a, double b)
Compare doubles that may have been serialized and unserialized.
void add_categories(int32_t categories)
Adds more categories to the already existing categories.
Definition: StatsSystem.cc:69
uint8_t group_ids[32]
The actual group IDs.
void encode(uint8_t **bufp) const
Encodes the statistics to a serialized buffer.
bool operator==(const StatsRangeServer &other) const
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
void encode_double(uint8_t **bufp, double val)
Encodes a double with 18 decimal digits of precision as 64-bit left-of-decimal, followed by 64-bit ri...