MXS-1632: Filter out inactive servers

The statistics are only returned for active servers.
This commit is contained in:
Markus Mäkelä 2018-09-11 07:29:04 +03:00
parent 805840dcdc
commit 37f693fc0a
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19

View File

@ -121,7 +121,10 @@ RWSplit::SrvStatMap RWSplit::all_server_stats() const
{
for (const auto& b : a)
{
stats[b.first] += b.second;
if (b.first->is_active)
{
stats[b.first] += b.second;
}
}
}
@ -383,6 +386,7 @@ void RWSplit::diagnostics(DCB* dcb)
dcb_printf(dcb, " Server Total Read Write\n");
for (const auto& s : srv_stats)
{
mxb_assert(s.second.total == s.second.read + s.second.write);
dcb_printf(dcb,
" %s %10lu %10lu %10lu\n",
s.first->name,
@ -414,25 +418,21 @@ json_t* RWSplit::diagnostics_json() const
json_object_set_new(rval, "weightby", json_string(weightby));
}
auto srv_stats = all_server_stats();
json_t* arr = json_array();
if (!srv_stats.empty())
for (const auto& a : all_server_stats())
{
json_t* arr = json_array();
for (const auto& a : srv_stats)
{
json_t* obj = json_object();
json_object_set_new(obj, "id", json_string(a.first->name));
json_object_set_new(obj, "total", json_integer(a.second.total));
json_object_set_new(obj, "read", json_integer(a.second.read));
json_object_set_new(obj, "write", json_integer(a.second.write));
json_array_append_new(arr, obj);
}
json_object_set_new(rval, "server_query_statistics", arr);
mxb_assert(a.second.total == a.second.read + a.second.write);
json_t* obj = json_object();
json_object_set_new(obj, "id", json_string(a.first->name));
json_object_set_new(obj, "total", json_integer(a.second.total));
json_object_set_new(obj, "read", json_integer(a.second.read));
json_object_set_new(obj, "write", json_integer(a.second.write));
json_array_append_new(arr, obj);
}
json_object_set_new(rval, "server_query_statistics", arr);
return rval;
}