MXS-1992 Expose qc stats in threads info

In principle it would be better if the qc information were
obtained via a specific query_classifier resource. However,
there are multiple problems with that (e.g. the qc has no way
of safely accessing information of another thread) and hence
the worker specific qc cache statistics is reported as part of
the worker statistics.
This commit is contained in:
Johan Wikman 2018-08-03 13:12:29 +03:00
parent fbd3b08c1e
commit 90569e3a28
3 changed files with 39 additions and 1 deletions

View File

@ -14,6 +14,7 @@
#include <maxscale/cdefs.h>
#include <maxscale/buffer.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS
@ -871,4 +872,11 @@ uint64_t qc_get_server_version();
*/
bool qc_get_cache_stats(QC_CACHE_STATS* stats);
/**
* Get cache statistics for the calling thread.
*
* @return An object if caching is enabled, NULL otherwise.
*/
json_t* qc_get_cache_stats_as_json();
MXS_END_DECLS

View File

@ -1208,3 +1208,26 @@ bool qc_get_cache_stats(QC_CACHE_STATS* pStats)
return rv;
}
json_t* qc_get_cache_stats_as_json()
{
json_t* pStats;
QC_CACHE_STATS stats;
if (qc_get_cache_stats(&stats))
{
pStats = json_object();
if (pStats)
{
json_object_set_new(pStats, "size", json_integer(stats.size));
json_object_set_new(pStats, "inserts", json_integer(stats.inserts));
json_object_set_new(pStats, "hits", json_integer(stats.hits));
json_object_set_new(pStats, "misses", json_integer(stats.misses));
json_object_set_new(pStats, "evictions", json_integer(stats.evictions));
}
}
return pStats;
}

View File

@ -973,7 +973,7 @@ std::unique_ptr<json_t> RoutingWorker::get_qc_stats_as_json(const char* zHost, i
stringstream self;
self << MXS_JSON_API_QC_STATS << id;
sStats = std::unique_ptr<json_t>(mxs_json_resource(zHost, self.str().c_str(), pJson));
sStats.reset(mxs_json_resource(zHost, self.str().c_str(), pJson));
}
return sStats;
@ -1088,6 +1088,13 @@ public:
json_object_set_new(load, "last_hour", json_integer(rworker.load(Worker::Load::ONE_HOUR)));
json_object_set_new(pStats, "load", load);
json_t* qc = qc_get_cache_stats_as_json();
if (qc)
{
json_object_set_new(pStats, "query_classifier_cache", qc);
}
json_t* pAttr = json_object();
json_object_set_new(pAttr, "stats", pStats);