mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 05:22:17 +00:00
Simplify the code
This commit is contained in:
parent
1087c7361d
commit
1be5a20546
@ -66,10 +66,15 @@ AsynchronousMetrics::AsynchronousMetrics(
|
|||||||
openFileIfExists("/proc/uptime", uptime);
|
openFileIfExists("/proc/uptime", uptime);
|
||||||
openFileIfExists("/proc/net/dev", net_dev);
|
openFileIfExists("/proc/net/dev", net_dev);
|
||||||
|
|
||||||
openFileIfExists("/sys/fs/cgroup/memory/memory.limit_in_bytes", cgroupmem_limit_in_bytes);
|
/// CGroups v2
|
||||||
openFileIfExists("/sys/fs/cgroup/memory/memory.usage_in_bytes", cgroupmem_usage_in_bytes);
|
openFileIfExists("/sys/fs/cgroup/memory.max", cgroupmem_limit_in_bytes);
|
||||||
openFileIfExists("/sys/fs/cgroup/memory.max", cgroupmem_v2_limit_in_bytes);
|
openFileIfExists("/sys/fs/cgroup/memory.current", cgroupmem_usage_in_bytes);
|
||||||
openFileIfExists("/sys/fs/cgroup/memory.current", cgroupmem_v2_usage_in_bytes);
|
|
||||||
|
/// CGroups v1
|
||||||
|
if (!cgroupmem_limit_in_bytes)
|
||||||
|
openFileIfExists("/sys/fs/cgroup/memory/memory.limit_in_bytes", cgroupmem_limit_in_bytes);
|
||||||
|
if (!cgroupmem_usage_in_bytes)
|
||||||
|
openFileIfExists("/sys/fs/cgroup/memory/memory.usage_in_bytes", cgroupmem_usage_in_bytes);
|
||||||
|
|
||||||
openSensors();
|
openSensors();
|
||||||
openBlockDevices();
|
openBlockDevices();
|
||||||
@ -896,11 +901,6 @@ void AsynchronousMetrics::update(TimePoint update_time)
|
|||||||
updateCgroupMemoryMetrics(cgroupmem_limit_in_bytes, cgroupmem_usage_in_bytes);
|
updateCgroupMemoryMetrics(cgroupmem_limit_in_bytes, cgroupmem_usage_in_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cgroupmem_v2_limit_in_bytes && cgroupmem_v2_usage_in_bytes)
|
|
||||||
{
|
|
||||||
updateCgroupMemoryMetrics(cgroupmem_v2_limit_in_bytes, cgroupmem_v2_usage_in_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meminfo)
|
if (meminfo)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -1467,35 +1467,21 @@ void AsynchronousMetrics::update(TimePoint update_time)
|
|||||||
values = new_values;
|
values = new_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsynchronousMetrics::updateCgroupMemoryMetrics(std::optional<ReadBufferFromFilePRead> memoryLimitReadBuffer, std::optional<ReadBufferFromFilePRead> memoryUsageReadBuffer)
|
void AsynchronousMetrics::updateCgroupMemoryMetrics(std::optional<ReadBufferFromFilePRead> memory_limit_in, std::optional<ReadBufferFromFilePRead> memory_usage_in)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
memoryLimitReadBuffer->rewind();
|
memory_limit_in->rewind();
|
||||||
memoryUsageReadBuffer->rewind();
|
memory_usage_in->rewind();
|
||||||
|
|
||||||
uint64_t cgroup_mem_limit_in_bytes = 0;
|
uint64_t cgroup_mem_limit_in_bytes = 0;
|
||||||
uint64_t cgroup_mem_usage_in_bytes = 0;
|
uint64_t cgroup_mem_usage_in_bytes = 0;
|
||||||
|
|
||||||
string cgroup_mem_limit_str = "";
|
tryReadText(cgroup_mem_limit_in_bytes, *memory_limit_in);
|
||||||
readText(cgroup_mem_limit_str, *memoryLimitReadBuffer);
|
tryReadText(cgroup_mem_usage_in_bytes, *memory_usage_in);
|
||||||
if (std::isdigit(cgroup_mem_limit_str))
|
|
||||||
{
|
|
||||||
memoryLimitReadBuffer->rewind();
|
|
||||||
readText(cgroup_mem_limit_in_bytes, *memoryLimitReadBuffer);
|
|
||||||
}
|
|
||||||
readText(cgroup_mem_usage_in_bytes, *memoryUsageReadBuffer);
|
|
||||||
|
|
||||||
if (cgroup_mem_limit_in_bytes || cgroup_mem_usage_in_bytes)
|
new_values["CgroupMemoryTotal"] = { cgroup_mem_limit_in_bytes, "The total amount of memory in cgroup, in bytes. If stated zero, the limit is the same as OSMemoryTotal." };
|
||||||
{
|
new_values["CgroupMemoryUsed"] = { cgroup_mem_usage_in_bytes, "The amount of memory used in cgroup, in bytes." };
|
||||||
new_values["CgroupMemoryTotal"] = { cgroup_mem_limit_in_bytes, "The total amount of memory in cgroup, in bytes. If stated zero, CgroupMemoryTotal is the same as OSMemoryTotal." };
|
|
||||||
new_values["CgroupMemoryUsed"] = { cgroup_mem_usage_in_bytes, "The amount of memory used in cgroup, in bytes." };
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG_DEBUG(log, "Cannot read statistics about the cgroup memory total and used. Total got '{}', Used got '{}'.",
|
|
||||||
cgroup_mem_limit_in_bytes, cgroup_mem_usage_in_bytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
@ -110,8 +110,6 @@ private:
|
|||||||
|
|
||||||
std::optional<ReadBufferFromFilePRead> cgroupmem_limit_in_bytes;
|
std::optional<ReadBufferFromFilePRead> cgroupmem_limit_in_bytes;
|
||||||
std::optional<ReadBufferFromFilePRead> cgroupmem_usage_in_bytes;
|
std::optional<ReadBufferFromFilePRead> cgroupmem_usage_in_bytes;
|
||||||
std::optional<ReadBufferFromFilePRead> cgroupmem_v2_limit_in_bytes;
|
|
||||||
std::optional<ReadBufferFromFilePRead> cgroupmem_v2_usage_in_bytes;
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ReadBufferFromFilePRead>> thermal;
|
std::vector<std::unique_ptr<ReadBufferFromFilePRead>> thermal;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user