Fix #11 - Clean up existing module metrics (#14)

Signed-off-by: Joe Hu <jowhuw@amazon.com>
Co-authored-by: Joe Hu <jowhuw@amazon.com>
This commit is contained in:
Joe Hu 2024-12-04 12:21:55 -05:00 committed by GitHub
parent 373a92e5d9
commit 4e50a2d56b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 76 deletions

View File

@ -2203,58 +2203,6 @@ void Module_Info(ValkeyModuleInfoCtx *ctx, int for_crash_report) {
addULongLong("total_memory_bytes", jsonstats_get_used_mem() + keyTable->getStats().bytes);
addULongLong("num_documents", jsonstats_get_num_doc_keys());
endSection();
beginSection("ext_metrics")
addULongLong("max_path_depth_ever_seen", jsonstats_get_max_depth_ever_seen());
addULongLong("max_document_size_ever_seen", jsonstats_get_max_size_ever_seen());
addULongLong("total_malloc_bytes_used", memory_usage());
addULongLong("memory_traps_enabled", memory_traps_enabled());
addULongLong("defrag_count", jsonstats_get_defrag_count());
addULongLong("defrag_bytes", jsonstats_get_defrag_bytes());
endSection();
beginSection("document_composition")
addULongLong("boolean_count", logical_stats.boolean_count);
addULongLong("number_count", logical_stats.number_count);
addULongLong("sum_extra_numeric_chars", logical_stats.sum_extra_numeric_chars);
addULongLong("string_count", logical_stats.string_count);
addULongLong("sum_string_chars", logical_stats.sum_string_chars);
addULongLong("null_count", logical_stats.null_count);
addULongLong("array_count", logical_stats.array_count);
addULongLong("sum_array_elements", logical_stats.sum_array_elements);
addULongLong("object_count", logical_stats.object_count);
addULongLong("sum_object_members", logical_stats.sum_object_members);
addULongLong("sum_object_key_chars", logical_stats.sum_object_key_chars);
endSection();
// section: histograms
beginSection("histograms")
char name[128];
char buf[1024];
snprintf(name, sizeof(name), "doc_histogram");
jsonstats_sprint_doc_hist(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
snprintf(name, sizeof(name), "read_histogram");
jsonstats_sprint_read_hist(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
snprintf(name, sizeof(name), "insert_histogram");
jsonstats_sprint_insert_hist(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
snprintf(name, sizeof(name), "update_histogram");
jsonstats_sprint_update_hist(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
snprintf(name, sizeof(name), "delete_histogram");
jsonstats_sprint_delete_hist(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
snprintf(name, sizeof(name), "histogram_buckets");
jsonstats_sprint_hist_buckets(buf, sizeof(buf));
ValkeyModule_InfoAddFieldCString(ctx, name, buf);
endSection();
}
//

View File

@ -1,30 +1,12 @@
/**
* The STATS module's main responsibility is to produce the following metrics:
* 1. Core metrics:
* The STATS module's main responsibility is to track memory usage at the level of the custom memory allocator,
* which provides the capability of tracking memory usage per JSON write operation. When a JSON key is mutated,
* we call API jsonstats_begin_track_mem() and jsonstats_end_track_mem() at the beginning and end of the write
* operation respectively, to calculate the delta of the memory usage. Then, we update the document size meta data.
*
* The module also maintains the following global info metrics:
* json_total_memory_bytes: total memory allocated to JSON objects
* json_num_documents: number of document keys in Valkey
* 2. Histograms:
* json_doc_histogram: static histogram showing document size distribution. Value of the i_th element is
* number of documents whose size fall into bucket i.
* json_read_histogram: dynamic histogram for read operations (JSON.GET and JSON.MGET). Value of the i_th
* element is number of read operations with fetched JSON size falling into bucket i.
* json_insert_histogram: dynamic histogram for insert operations (JSON.SET and JSON.ARRINSERT) that either
* insert new documents or insert values into existing documents. Value of the i_th element is number of
* insert operations with inserted values' size falling into bucket i.
* json_update_histogram: dynamic histogram for update operations (JSON.SET, JSON.STRAPPEND and
* JSON.ARRAPPEND). Value of the i_th element is number of update operations with input JSON size falling into
* bucket i.
* json_delete_histogram: dynamic histogram for delete operations (JSON.DEL, JSON.FORGET, JSON.ARRPOP and
* JSON.ARRTRIM). Value of the i_th element is number of delete operations with deleted values' size falling
* into bucket i.
*
* Histogram buckets:
* [0,256), [256,1k), [1k,4k), [4k,16k), [16k,64k), [64k,256k), [256k,1m), [1m,4m), [4m,16m), [16m,64m), [64m,INF).
* Each bucket represents a JSON size range in bytes.
*
* To query metrics, run Valkey command:
* info modules: returns all metrics of the module
* info json_core_metrics: returns core metrics
*/
#ifndef VALKEYJSONMODULE_JSON_STATS_H_
#define VALKEYJSONMODULE_JSON_STATS_H_