Skip to content

Commit

Permalink
Overload CPU reading metric (#240)
Browse files Browse the repository at this point in the history
* Overload CPU reading metric

* fix

* fix
  • Loading branch information
jbohac-sc authored and GitHub Enterprise committed Nov 27, 2023
1 parent c889505 commit 8a5857d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/modules/keydb_modstatsd/modmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ std::unordered_map<std::string, StatsRecord> g_mapInfoFields = {
{ "cluster_size", { StatsD_Type::STATSD_GAUGE_LONGLONG }},
{ "storage_flash_available_bytes", { StatsD_Type::STATSD_GAUGE_BYTES }},
{ "storage_flash_total_bytes", { StatsD_Type::STATSD_GAUGE_BYTES }},
{ "last_overload_cpu_reading", { StatsD_Type::STATSD_GAUGE_FLOAT }},
};

/* Globals */
Expand Down
7 changes: 5 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
perc /= cserver.cthreads;
perc *= 100.0;
serverLog(LL_WARNING, "CPU Used: %.2f", perc);
g_pserver->last_overload_cpu_reading = static_cast<float>(perc);
if (perc > g_pserver->overload_protect_threshold) {
serverLog(LL_WARNING, "\tWARNING: CPU overload detected.");
g_pserver->is_overloaded = true;
Expand Down Expand Up @@ -6271,13 +6272,15 @@ sds genRedisInfoString(const char *section) {
"used_cpu_sys_children:%ld.%06ld\r\n"
"used_cpu_user_children:%ld.%06ld\r\n"
"server_threads:%d\r\n"
"long_lock_waits:%" PRIu64 "\r\n",
"long_lock_waits:%" PRIu64 "\r\n"
"last_overload_cpu_reading:%.2f\r\n",
(long)self_ru.ru_stime.tv_sec, (long)self_ru.ru_stime.tv_usec,
(long)self_ru.ru_utime.tv_sec, (long)self_ru.ru_utime.tv_usec,
(long)c_ru.ru_stime.tv_sec, (long)c_ru.ru_stime.tv_usec,
(long)c_ru.ru_utime.tv_sec, (long)c_ru.ru_utime.tv_usec,
cserver.cthreads,
fastlock_getlongwaitcount());
fastlock_getlongwaitcount(),
g_pserver->last_overload_cpu_reading);
#ifdef RUSAGE_THREAD
struct rusage m_ru;
getrusage(RUSAGE_THREAD, &m_ru);
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,7 @@ struct redisServer {

sds sdsAvailabilityZone;
int overload_protect_threshold = 0;
float last_overload_cpu_reading = 0.0f;
int is_overloaded = 0;
int overload_closed_clients = 0;

Expand Down

0 comments on commit 8a5857d

Please sign in to comment.