54 std::vector<RangeServerConnectionPtr> servers;
55 std::vector<RangeServerStatistics> results;
59 String monitoring_dir, graphviz_str;
63 HT_INFOF(
"Entering GatherStatistics-%lld state=%s",
69 m_context->rsc_manager->get_servers(servers);
70 if (servers.empty()) {
74 results.resize(servers.size());
75 for (
size_t i=0; i<servers.size(); i++) {
76 results[i].addr = servers[i]->local_addr();
77 results[i].location = servers[i]->location();
78 locations.insert(results[i].location);
81 dispatch_handler.DispatchHandlerOperation::start(locations);
84 m_context->op->graphviz_output(graphviz_str);
85 data_dir =
Path(
m_context->props->get_str(
"Hypertable.DataDirectory"));
86 monitoring_dir = (data_dir /=
"/run/monitoring").
string();
87 filename = monitoring_dir +
"/mop.dot";
88 filename_tmp = monitoring_dir +
"/mop.tmp.dot";
91 dot_cmd =
format(
"dot -Tjpg -Gcharset=latin1 -o%s/mop.tmp.jpg %s/mop.dot",
92 monitoring_dir.c_str(), monitoring_dir.c_str());
93 if (system(dot_cmd.c_str()) != -1) {
94 filename = monitoring_dir +
"/mop.jpg";
95 filename_tmp = monitoring_dir +
"/mop.tmp.jpg";
102 double numerator, denominator;
103 double numerator_total = 0.0, denominator_total = 0.0;
104 std::vector<RangeServerState> rs_states;
106 for (
auto &rs_stats : results) {
108 numerator = denominator = 0.0;
109 for (
size_t i=0; i<rs_stats.stats->system.fs_stat.size(); i++) {
110 numerator += rs_stats.stats->system.fs_stat[i].total
111 - rs_stats.stats->system.fs_stat[i].avail;
112 denominator += rs_stats.stats->system.fs_stat[i].total;
114 rs_state.
location = rs_stats.location;
115 if (denominator > 0.0)
116 rs_state.
disk_usage = (numerator / denominator) * 100.0;
123 rs_states.push_back(rs_state);
124 numerator_total += numerator;
125 denominator_total += denominator;
128 m_context->rsc_manager->set_range_server_state(rs_states);
130 HT_INFOF(
"Aggregate disk usage = %0.2f",
131 denominator_total == 0.0 ? 0.0 : ((numerator_total / denominator_total)*100.0));
133 int32_t aggregate_disk_usage = 0;
134 if (denominator_total >= 0.0)
135 aggregate_disk_usage = (int32_t)((numerator_total / denominator_total)*100.0);
136 String message =
format(
"because aggreggate disk usage is %d%%",
137 aggregate_disk_usage);
138 bool readonly_mode = aggregate_disk_usage >=
m_context->disk_threshold;
141 readonly_mode, message))
145 std::vector<NotificationMessage> notifications;
146 if (
m_context->system_state->get_notifications(notifications)) {
147 for (
auto &msg : notifications)
148 m_context->notification_hook(msg.subject, msg.body);
154 m_context->balancer->transfer_monitoring_data(results);
159 HT_FATALF(
"Unrecognized state %d", state);
166 return "OperationGatherStatistics";
170 return "GatherStatistics";
std::set< String > StringSet
STL Set managing Strings.
virtual const String label()
Human readable label for operation.
ContextPtr m_context
Pointer to Master context.
Abstract base class for ephemeral operations.
std::string String
A String is simply a typedef to std::string.
Compatibility class for boost::filesystem::path.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Declarations for OperationProcessor.
static ssize_t write(const String &fname, const std::string &contents)
Writes a String buffer to a file; the file is overwritten if it already exists.
void initialize(std::vector< RangeServerStatistics > &results)
const char * get_text(int32_t state)
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Compatibility class for boost::filesystem::path.
Compatibility Macros for C/C++.
bool wait_for_completion()
Waits for requests to complete.
#define HT_FATALF(msg,...)
long long int Lld
Shortcut for printf formats.
DependencySet m_dependencies
Set of dependencies.
#define HT_INFOF(msg,...)
Declarations for OperationSetState.
Declarations for OperationGatherStatistics.
OperationGatherStatistics(ContextPtr &context)
Constructor.
virtual void execute()
Carries out "gather statistics operation.
void complete_ok(std::vector< MetaLog::EntityPtr > &additional)
static bool rename(const String &oldpath, const String &newpath)
Renames a file or directory.
String extensions and helpers: sets, maps, append operators etc.
virtual const String name()
Name of operation used for exclusivity.