[Enhancement] Add be jvm memory metrics (#62210)
Signed-off-by: wenbinlin <wenbinlin@tencent.com>
This commit is contained in:
parent
179d4720e3
commit
d93cbaf2c5
|
|
@ -583,6 +583,8 @@ CONF_mBool(enable_token_check, "true");
|
|||
// to open/close system metrics
|
||||
CONF_Bool(enable_system_metrics, "true");
|
||||
|
||||
CONF_Bool(enable_jvm_metrics, "false");
|
||||
|
||||
CONF_mBool(enable_prefetch, "true");
|
||||
|
||||
// Number of cores StarRocks will used, this will effect only when it's greater than 0.
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ void jemalloc_tracker_daemon(void* arg_this) {
|
|||
|
||||
static void init_starrocks_metrics(const std::vector<StorePath>& store_paths) {
|
||||
bool init_system_metrics = config::enable_system_metrics;
|
||||
bool init_jvm_metrics = config::enable_jvm_metrics;
|
||||
std::set<std::string> disk_devices;
|
||||
std::vector<std::string> network_interfaces;
|
||||
std::vector<std::string> paths;
|
||||
|
|
@ -229,7 +230,8 @@ static void init_starrocks_metrics(const std::vector<StorePath>& store_paths) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
StarRocksMetrics::instance()->initialize(paths, init_system_metrics, disk_devices, network_interfaces);
|
||||
StarRocksMetrics::instance()->initialize(paths, init_system_metrics, init_jvm_metrics, disk_devices,
|
||||
network_interfaces);
|
||||
}
|
||||
|
||||
void sigterm_handler(int signo, siginfo_t* info, void* context) {
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ set(UTIL_FILES
|
|||
lake_service_recoverable_stub.cpp
|
||||
byte_buffer.cpp
|
||||
variant_util.cpp
|
||||
jvm_metrics.cpp
|
||||
)
|
||||
|
||||
add_library(Util STATIC
|
||||
${UTIL_FILES}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,258 @@
|
|||
// Copyright 2021-present StarRocks, Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "util/jvm_metrics.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "common/status.h"
|
||||
#include "common/statusor.h"
|
||||
#include "jni.h"
|
||||
#include "udf/java/java_udf.h"
|
||||
#include "util/defer_op.h"
|
||||
|
||||
#define CHECK_JNI_EXCEPTION(env, message) \
|
||||
if (jthrowable thr = env->ExceptionOccurred(); thr) { \
|
||||
std::string jni_error_message = JVMFunctionHelper::getInstance().dumpExceptionString(thr); \
|
||||
env->ExceptionDescribe(); \
|
||||
env->ExceptionClear(); \
|
||||
env->DeleteLocalRef(thr); \
|
||||
return Status::InternalError(fmt::format("{}, error: {}", message, jni_error_message)); \
|
||||
}
|
||||
|
||||
namespace starrocks {
|
||||
|
||||
Status JVMMetrics::init() {
|
||||
RETURN_IF_ERROR(detect_java_runtime());
|
||||
|
||||
// check JNIEnv before calling JVMFunctionHelper::getInstance() to avoid crash
|
||||
if (getJNIEnv() == nullptr) {
|
||||
return Status::InternalError("get JNIEnv failed");
|
||||
}
|
||||
|
||||
JNIEnv* env = JVMFunctionHelper::getInstance().getEnv();
|
||||
|
||||
jclass management_factory_cls = env->FindClass("java/lang/management/ManagementFactory");
|
||||
CHECK_JNI_EXCEPTION(env, "find class ManagementFactory failed")
|
||||
_management_factory_cls = std::make_unique<JVMClass>(env->NewGlobalRef(management_factory_cls));
|
||||
LOCAL_REF_GUARD_ENV(env, management_factory_cls);
|
||||
|
||||
jclass memory_mxbean_cls = env->FindClass("java/lang/management/MemoryMXBean");
|
||||
CHECK_JNI_EXCEPTION(env, "find class MemoryMXBean failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_mxbean_cls);
|
||||
|
||||
_get_memory_mxbean =
|
||||
env->GetStaticMethodID(management_factory_cls, "getMemoryMXBean", "()Ljava/lang/management/MemoryMXBean;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getMemoryMXBean failed")
|
||||
jobject memory_mxbean_obj = env->CallStaticObjectMethod(management_factory_cls, _get_memory_mxbean);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory mxbean failed")
|
||||
_memory_mxbean_obj = JavaGlobalRef(env->NewGlobalRef(memory_mxbean_obj));
|
||||
LOCAL_REF_GUARD_ENV(env, memory_mxbean_obj);
|
||||
|
||||
_get_heap_memory_usage =
|
||||
env->GetMethodID(memory_mxbean_cls, "getHeapMemoryUsage", "()Ljava/lang/management/MemoryUsage;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getHeapMemoryUsage failed")
|
||||
_get_non_heap_memory_usage =
|
||||
env->GetMethodID(memory_mxbean_cls, "getNonHeapMemoryUsage", "()Ljava/lang/management/MemoryUsage;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getNonHeapMemoryUsage failed")
|
||||
|
||||
jclass memory_usage_cls = env->FindClass("java/lang/management/MemoryUsage");
|
||||
CHECK_JNI_EXCEPTION(env, "find class MemoryUsage failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_usage_cls);
|
||||
_get_init = env->GetMethodID(memory_usage_cls, "getInit", "()J");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getInit failed")
|
||||
_get_used = env->GetMethodID(memory_usage_cls, "getUsed", "()J");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getUsed failed")
|
||||
_get_committed = env->GetMethodID(memory_usage_cls, "getCommitted", "()J");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getCommitted failed")
|
||||
_get_max = env->GetMethodID(memory_usage_cls, "getMax", "()J");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getMax failed")
|
||||
|
||||
_get_memory_pool_mxbeans =
|
||||
env->GetStaticMethodID(management_factory_cls, "getMemoryPoolMXBeans", "()Ljava/util/List;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getMemoryPoolMXBeans failed")
|
||||
|
||||
jclass memory_pool_mxbean_cls = env->FindClass("java/lang/management/MemoryPoolMXBean");
|
||||
CHECK_JNI_EXCEPTION(env, "find class MemoryPoolMXBean failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_pool_mxbean_cls);
|
||||
_get_usage = env->GetMethodID(memory_pool_mxbean_cls, "getUsage", "()Ljava/lang/management/MemoryUsage;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getUsage failed")
|
||||
_get_peak_usage = env->GetMethodID(memory_pool_mxbean_cls, "getPeakUsage", "()Ljava/lang/management/MemoryUsage;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getPeakUsage failed")
|
||||
_get_name = env->GetMethodID(memory_pool_mxbean_cls, "getName", "()Ljava/lang/String;");
|
||||
CHECK_JNI_EXCEPTION(env, "get method getName failed")
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void JVMMetrics::install(MetricRegistry* registry) {
|
||||
if (!registry->register_hook("jvm_metrics", [this] {
|
||||
auto status = update();
|
||||
if (!status.ok()) {
|
||||
LOG(WARNING) << "update jvm metrics failed: " << status.to_string();
|
||||
}
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define REGISTER_JVM_METRIC(name, type) \
|
||||
registry->register_metric("jvm_" #name "_size_bytes{type=\"" #type "\"}", &jvm_##name##_##type##_bytes)
|
||||
|
||||
REGISTER_JVM_METRIC(heap, used);
|
||||
REGISTER_JVM_METRIC(heap, committed);
|
||||
REGISTER_JVM_METRIC(heap, max);
|
||||
REGISTER_JVM_METRIC(non_heap, used);
|
||||
REGISTER_JVM_METRIC(non_heap, committed);
|
||||
REGISTER_JVM_METRIC(young, used);
|
||||
REGISTER_JVM_METRIC(young, committed);
|
||||
REGISTER_JVM_METRIC(young, max);
|
||||
REGISTER_JVM_METRIC(young, peak_used);
|
||||
REGISTER_JVM_METRIC(young, peak_max);
|
||||
REGISTER_JVM_METRIC(old, used);
|
||||
REGISTER_JVM_METRIC(old, committed);
|
||||
REGISTER_JVM_METRIC(old, max);
|
||||
REGISTER_JVM_METRIC(old, peak_used);
|
||||
REGISTER_JVM_METRIC(old, peak_max);
|
||||
REGISTER_JVM_METRIC(survivor, used);
|
||||
REGISTER_JVM_METRIC(survivor, committed);
|
||||
REGISTER_JVM_METRIC(survivor, max);
|
||||
REGISTER_JVM_METRIC(survivor, peak_used);
|
||||
REGISTER_JVM_METRIC(survivor, peak_max);
|
||||
REGISTER_JVM_METRIC(perm, used);
|
||||
REGISTER_JVM_METRIC(perm, committed);
|
||||
REGISTER_JVM_METRIC(perm, max);
|
||||
REGISTER_JVM_METRIC(perm, peak_used);
|
||||
REGISTER_JVM_METRIC(perm, peak_max);
|
||||
|
||||
#undef REGISTER_JVM_METRIC
|
||||
}
|
||||
|
||||
Status JVMMetrics::update() {
|
||||
ASSIGN_OR_RETURN(auto heap_memory_usage, get_heap_memory_usage());
|
||||
jvm_heap_used_bytes.set_value(heap_memory_usage.used);
|
||||
jvm_heap_committed_bytes.set_value(heap_memory_usage.committed);
|
||||
jvm_heap_max_bytes.set_value(heap_memory_usage.max);
|
||||
|
||||
ASSIGN_OR_RETURN(auto non_heap_memory_usage, get_non_heap_memory_usage());
|
||||
jvm_non_heap_used_bytes.set_value(non_heap_memory_usage.used);
|
||||
jvm_non_heap_committed_bytes.set_value(non_heap_memory_usage.committed);
|
||||
|
||||
ASSIGN_OR_RETURN(auto memory_pools, get_memory_pools());
|
||||
for (auto& pool : memory_pools) {
|
||||
auto& name = pool.name;
|
||||
auto& usage = pool.usage;
|
||||
auto& peak_usage = pool.peak_usage;
|
||||
|
||||
#define UPDATE_METRIC(name, used, committed, max, peak_used, peak_max) \
|
||||
jvm_##name##_used_bytes.set_value(used); \
|
||||
jvm_##name##_committed_bytes.set_value(committed); \
|
||||
jvm_##name##_max_bytes.set_value(max); \
|
||||
jvm_##name##_peak_used_bytes.set_value(peak_used); \
|
||||
jvm_##name##_peak_max_bytes.set_value(peak_max)
|
||||
|
||||
if (name == "Eden Space" || name == "PS Eden Space" || name == "Par Eden Space" || name == "G1 Eden Space") {
|
||||
UPDATE_METRIC(young, usage.used, usage.committed, usage.max, peak_usage.used, peak_usage.max);
|
||||
} else if (name == "Tenured Gen" || name == "PS Old Gen" || name == "CMS Old Gen" || name == "G1 Old Gen") {
|
||||
UPDATE_METRIC(old, usage.used, usage.committed, usage.max, peak_usage.used, peak_usage.max);
|
||||
} else if (name == "Survivor Space" || name == "PS Survivor Space" || name == "Par Survivor Space" ||
|
||||
name == "G1 Survivor Space") {
|
||||
UPDATE_METRIC(survivor, usage.used, usage.committed, usage.max, peak_usage.used, peak_usage.max);
|
||||
} else if (name == "Perm Gen" || name == "Metaspace") {
|
||||
UPDATE_METRIC(perm, usage.used, usage.committed, usage.max, peak_usage.used, peak_usage.max);
|
||||
}
|
||||
|
||||
#undef UPDATE_METRIC
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
StatusOr<MemoryUsage> JVMMetrics::get_heap_memory_usage() {
|
||||
JNIEnv* env = JVMFunctionHelper::getInstance().getEnv();
|
||||
|
||||
jobject memory_usage = env->CallObjectMethod(_memory_mxbean_obj.handle(), _get_heap_memory_usage);
|
||||
CHECK_JNI_EXCEPTION(env, "get heap memory usage failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_usage);
|
||||
|
||||
jlong init = env->CallLongMethod(memory_usage, _get_init);
|
||||
jlong used = env->CallLongMethod(memory_usage, _get_used);
|
||||
jlong committed = env->CallLongMethod(memory_usage, _get_committed);
|
||||
jlong max = env->CallLongMethod(memory_usage, _get_max);
|
||||
CHECK_JNI_EXCEPTION(env, "get heap memory usage details failed")
|
||||
|
||||
return MemoryUsage(init, used, committed, max);
|
||||
}
|
||||
|
||||
StatusOr<MemoryUsage> JVMMetrics::get_non_heap_memory_usage() {
|
||||
JNIEnv* env = JVMFunctionHelper::getInstance().getEnv();
|
||||
|
||||
jobject memory_usage = env->CallObjectMethod(_memory_mxbean_obj.handle(), _get_non_heap_memory_usage);
|
||||
CHECK_JNI_EXCEPTION(env, "get non heap memory usage failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_usage);
|
||||
|
||||
jlong init = env->CallLongMethod(memory_usage, _get_init);
|
||||
jlong used = env->CallLongMethod(memory_usage, _get_used);
|
||||
jlong committed = env->CallLongMethod(memory_usage, _get_committed);
|
||||
jlong max = env->CallLongMethod(memory_usage, _get_max);
|
||||
CHECK_JNI_EXCEPTION(env, "get non heap memory usage details failed")
|
||||
|
||||
return MemoryUsage(init, used, committed, max);
|
||||
}
|
||||
|
||||
StatusOr<std::vector<MemoryPool>> JVMMetrics::get_memory_pools() {
|
||||
JNIEnv* env = JVMFunctionHelper::getInstance().getEnv();
|
||||
|
||||
jobject memory_pools = env->CallStaticObjectMethod(_management_factory_cls->clazz(), _get_memory_pool_mxbeans);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool mxbeans failed")
|
||||
LOCAL_REF_GUARD_ENV(env, memory_pools);
|
||||
|
||||
JavaListStub list_stub(memory_pools);
|
||||
ASSIGN_OR_RETURN(auto size, list_stub.size());
|
||||
|
||||
std::vector<MemoryPool> pools;
|
||||
pools.reserve(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
ASSIGN_OR_RETURN(auto memory_pool, list_stub.get(i));
|
||||
LOCAL_REF_GUARD_ENV(env, memory_pool);
|
||||
|
||||
jstring name = (jstring)env->CallObjectMethod(memory_pool, _get_name);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool name failed")
|
||||
LOCAL_REF_GUARD_ENV(env, name);
|
||||
std::string name_str = JVMFunctionHelper::getInstance().to_cxx_string(name);
|
||||
|
||||
jobject usage = env->CallObjectMethod(memory_pool, _get_usage);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool usage failed")
|
||||
LOCAL_REF_GUARD_ENV(env, usage);
|
||||
jlong init = env->CallLongMethod(usage, _get_init);
|
||||
jlong used = env->CallLongMethod(usage, _get_used);
|
||||
jlong committed = env->CallLongMethod(usage, _get_committed);
|
||||
jlong max = env->CallLongMethod(usage, _get_max);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool usage details failed")
|
||||
MemoryUsage usage_obj(init, used, committed, max);
|
||||
|
||||
jobject peak_usage = env->CallObjectMethod(memory_pool, _get_peak_usage);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool peak usage failed")
|
||||
LOCAL_REF_GUARD_ENV(env, peak_usage);
|
||||
used = env->CallLongMethod(peak_usage, _get_used);
|
||||
max = env->CallLongMethod(peak_usage, _get_max);
|
||||
CHECK_JNI_EXCEPTION(env, "get memory pool peak usage details failed")
|
||||
MemoryUsage peak_usage_obj(0, used, 0, max);
|
||||
|
||||
pools.emplace_back(std::move(name_str), usage_obj, peak_usage_obj);
|
||||
}
|
||||
|
||||
return pools;
|
||||
}
|
||||
|
||||
} // namespace starrocks
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright 2021-present StarRocks, Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/status.h"
|
||||
#include "jni.h"
|
||||
#include "udf/java/java_udf.h"
|
||||
#include "util/metrics.h"
|
||||
|
||||
namespace starrocks {
|
||||
|
||||
struct MemoryUsage {
|
||||
MemoryUsage(int64_t init, int64_t used, int64_t committed, int64_t max)
|
||||
: init(init), used(used), committed(committed), max(max) {}
|
||||
|
||||
int64_t init;
|
||||
int64_t used;
|
||||
int64_t committed;
|
||||
int64_t max;
|
||||
};
|
||||
|
||||
struct MemoryPool {
|
||||
MemoryPool(std::string name, MemoryUsage usage, MemoryUsage peak_usage)
|
||||
: name(std::move(name)), usage(usage), peak_usage(peak_usage) {}
|
||||
|
||||
std::string name;
|
||||
MemoryUsage usage;
|
||||
MemoryUsage peak_usage;
|
||||
};
|
||||
|
||||
class JVMMetrics {
|
||||
public:
|
||||
JVMMetrics() = default;
|
||||
~JVMMetrics() = default;
|
||||
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_heap_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_heap_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_heap_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_non_heap_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_non_heap_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_young_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_young_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_young_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_young_peak_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_young_peak_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_old_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_old_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_old_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_old_peak_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_old_peak_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_survivor_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_survivor_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_survivor_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_survivor_peak_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_survivor_peak_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_perm_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_perm_committed_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_perm_max_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_perm_peak_used_bytes, MetricUnit::BYTES);
|
||||
METRIC_DEFINE_INT_GAUGE(jvm_perm_peak_max_bytes, MetricUnit::BYTES);
|
||||
|
||||
Status init();
|
||||
void install(MetricRegistry*);
|
||||
Status update();
|
||||
StatusOr<MemoryUsage> get_heap_memory_usage();
|
||||
StatusOr<MemoryUsage> get_non_heap_memory_usage();
|
||||
StatusOr<std::vector<MemoryPool>> get_memory_pools();
|
||||
|
||||
private:
|
||||
std::unique_ptr<JVMClass> _management_factory_cls = nullptr;
|
||||
JavaGlobalRef _memory_mxbean_obj = nullptr;
|
||||
|
||||
jmethodID _get_memory_mxbean = nullptr;
|
||||
jmethodID _get_heap_memory_usage = nullptr;
|
||||
jmethodID _get_non_heap_memory_usage = nullptr;
|
||||
jmethodID _get_init = nullptr;
|
||||
jmethodID _get_used = nullptr;
|
||||
jmethodID _get_committed = nullptr;
|
||||
jmethodID _get_max = nullptr;
|
||||
jmethodID _get_memory_pool_mxbeans = nullptr;
|
||||
|
||||
jmethodID _get_usage = nullptr;
|
||||
jmethodID _get_peak_usage = nullptr;
|
||||
jmethodID _get_name = nullptr;
|
||||
};
|
||||
|
||||
} // namespace starrocks
|
||||
|
|
@ -260,7 +260,7 @@ StarRocksMetrics::StarRocksMetrics() : _metrics(_s_registry_name) {
|
|||
}
|
||||
|
||||
void StarRocksMetrics::initialize(const std::vector<std::string>& paths, bool init_system_metrics,
|
||||
const std::set<std::string>& disk_devices,
|
||||
bool init_jvm_metrics, const std::set<std::string>& disk_devices,
|
||||
const std::vector<std::string>& network_interfaces) {
|
||||
// disk usage
|
||||
for (auto& path : paths) {
|
||||
|
|
@ -277,6 +277,15 @@ void StarRocksMetrics::initialize(const std::vector<std::string>& paths, bool in
|
|||
if (init_system_metrics) {
|
||||
_system_metrics.install(&_metrics, disk_devices, network_interfaces);
|
||||
}
|
||||
|
||||
if (init_jvm_metrics) {
|
||||
auto status = _jvm_metrics.init();
|
||||
if (!status.ok()) {
|
||||
LOG(WARNING) << "init jvm metrics failed: " << status.to_string();
|
||||
return;
|
||||
}
|
||||
_jvm_metrics.install(&_metrics);
|
||||
}
|
||||
}
|
||||
|
||||
void StarRocksMetrics::_update() {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "exec/pipeline/pipeline_metrics.h"
|
||||
#include "util/jvm_metrics.h"
|
||||
#include "util/metrics.h"
|
||||
#include "util/system_metrics.h"
|
||||
#include "util/table_metrics.h"
|
||||
|
|
@ -412,7 +413,7 @@ public:
|
|||
|
||||
// not thread-safe, call before calling metrics
|
||||
void initialize(const std::vector<std::string>& paths = std::vector<std::string>(),
|
||||
bool init_system_metrics = false,
|
||||
bool init_system_metrics = false, bool init_jvm_metrics = false,
|
||||
const std::set<std::string>& disk_devices = std::set<std::string>(),
|
||||
const std::vector<std::string>& network_interfaces = std::vector<std::string>());
|
||||
|
||||
|
|
@ -436,6 +437,7 @@ private:
|
|||
|
||||
MetricRegistry _metrics;
|
||||
SystemMetrics _system_metrics;
|
||||
JVMMetrics _jvm_metrics;
|
||||
TableMetricsManager _table_metrics_mgr;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -416,6 +416,7 @@ set(EXEC_FILES
|
|||
./udf/java/java_data_converter_test.cpp
|
||||
./udf/java/java_udf_test.cpp
|
||||
./util/table_metrics_mgr_test.cpp
|
||||
./util/jvm_metrics_test.cpp
|
||||
)
|
||||
|
||||
if (${USE_AVX512})
|
||||
|
|
@ -631,4 +632,3 @@ ADD_BE_TEST(fuzzy/builtin_functions_fuzzy_test)
|
|||
|
||||
add_dependencies(starrocks_dw_test engine_storage_migration_task_test compaction_task_test builtin_functions_fuzzy_test)
|
||||
add_dependencies(starrocks_dw_test engine_storage_migration_task_test compaction_task_test builtin_functions_fuzzy_test)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright 2021-present StarRocks, Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "util/jvm_metrics.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "testutil/assert.h"
|
||||
#include "udf/java/java_udf.h"
|
||||
#include "util/metrics.h"
|
||||
|
||||
namespace starrocks {
|
||||
|
||||
class JVMMetricsTest : public testing::Test {
|
||||
public:
|
||||
JVMMetricsTest() = default;
|
||||
~JVMMetricsTest() override = default;
|
||||
};
|
||||
|
||||
TEST_F(JVMMetricsTest, normal) {
|
||||
MetricRegistry registry("test");
|
||||
JVMMetrics jvm_metrics;
|
||||
|
||||
auto st = jvm_metrics.init();
|
||||
ASSERT_TRUE(st.ok());
|
||||
jvm_metrics.install(®istry);
|
||||
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_heap_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_heap_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_heap_size_bytes{type=\"max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_non_heap_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_non_heap_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_young_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_young_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_young_size_bytes{type=\"max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_young_size_bytes{type=\"peak_used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_young_size_bytes{type=\"peak_max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_old_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_old_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_old_size_bytes{type=\"max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_old_size_bytes{type=\"peak_used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_old_size_bytes{type=\"peak_max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_survivor_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_survivor_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_survivor_size_bytes{type=\"max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_survivor_size_bytes{type=\"peak_used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_survivor_size_bytes{type=\"peak_max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_perm_size_bytes{type=\"used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_perm_size_bytes{type=\"committed\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_perm_size_bytes{type=\"max\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_perm_size_bytes{type=\"peak_used\"}"));
|
||||
ASSERT_NE(nullptr, registry.get_metric("jvm_perm_size_bytes{type=\"peak_max\"}"));
|
||||
|
||||
registry.trigger_hook();
|
||||
|
||||
ASSERT_GE(jvm_metrics.jvm_heap_used_bytes.value(), 0);
|
||||
ASSERT_GE(jvm_metrics.jvm_heap_committed_bytes.value(), 0);
|
||||
ASSERT_GE(jvm_metrics.jvm_non_heap_used_bytes.value(), 0);
|
||||
ASSERT_GE(jvm_metrics.jvm_non_heap_committed_bytes.value(), 0);
|
||||
}
|
||||
|
||||
} // namespace starrocks
|
||||
Loading…
Reference in New Issue