|
12 | 12 | #include <sys/time.h> |
13 | 13 | #include <regex> |
14 | 14 | #include <sstream> |
| 15 | +#include <iostream> |
| 16 | +#include <fstream> |
15 | 17 |
|
16 | 18 | using namespace Statsd; |
17 | 19 |
|
@@ -529,6 +531,18 @@ void handle_client_list_response(struct RedisModuleCtx *ctx, const char *szReply |
529 | 531 | g_stats->gauge("total_replica_client_output_buffer", totalReplicaClientOutputBuffer); |
530 | 532 | } |
531 | 533 |
|
| 534 | +void emit_system_free_memory() { |
| 535 | + std::ifstream meminfo("/proc/meminfo"); |
| 536 | + std::string line; |
| 537 | + while (std::getline(meminfo, line)) { |
| 538 | + if (line.find("MemFree:") != std::string::npos) { |
| 539 | + unsigned long memFreeInKB; |
| 540 | + std::sscanf(line.c_str(), "MemFree: %lu kB", &memFreeInKB); |
| 541 | + g_stats->gauge("systemFreeMemory_MB", memFreeInKB / 1024); |
| 542 | + return; |
| 543 | + } |
| 544 | + } |
| 545 | +} |
532 | 546 |
|
533 | 547 | void event_cron_handler(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64_t subevent, void *data) { |
534 | 548 | static time_t lastTime = 0; |
@@ -600,6 +614,10 @@ void event_cron_handler(struct RedisModuleCtx *ctx, RedisModuleEvent eid, uint64 |
600 | 614 | // g_stats->timing("handle_client_info_time_taken_us", ustime() - commandStartTime); |
601 | 615 | // RedisModule_FreeCallReply(reply); |
602 | 616 |
|
| 617 | + commandStartTime = ustime(); |
| 618 | + emit_system_free_memory(); |
| 619 | + g_stats->timing("emit_free_system_memory_time_taken_us", ustime() - commandStartTime); |
| 620 | + |
603 | 621 | /* Log Keys */ |
604 | 622 | reply = RedisModule_Call(ctx, "dbsize", ""); |
605 | 623 | long long keys = RedisModule_CallReplyInteger(reply); |
|
0 commit comments