Fix temperatures
This commit is contained in:
+41
-18
@@ -10,6 +10,8 @@
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace metrics
|
||||
{
|
||||
|
||||
@@ -117,41 +119,62 @@ namespace metrics
|
||||
if (name != "coretemp" && name != "k10temp")
|
||||
continue;
|
||||
|
||||
// читаем все temp*_input
|
||||
for (const auto &f : std::filesystem::directory_iterator(hwmon))
|
||||
{
|
||||
std::string fname = f.path().filename();
|
||||
CpuTemperature temperature;
|
||||
if (fname.find("temp") == 0 && fname.find("_input") != std::string::npos)
|
||||
{
|
||||
std::string fname = f.path().filename().string();
|
||||
if (fname.find("temp") != 0)
|
||||
continue;
|
||||
|
||||
// определяем, какой тип файла
|
||||
std::string suffix;
|
||||
if (fname.find("_input") != std::string::npos)
|
||||
suffix = "_input";
|
||||
else if (fname.find("_max") != std::string::npos)
|
||||
suffix = "_max";
|
||||
else
|
||||
continue;
|
||||
|
||||
int millideg = 0;
|
||||
std::ifstream tempFile(f.path());
|
||||
tempFile >> millideg;
|
||||
temperature.current = millideg / 1000.0f; // °C
|
||||
}
|
||||
if (fname.find("temp") == 0 && fname.find("_max") != std::string::npos)
|
||||
float value = millideg / 1000.0f;
|
||||
|
||||
// находим индекс ядра в temps по tempN
|
||||
std::string numStr = fname.substr(4, fname.find('_') - 4);
|
||||
int n = std::stoi(numStr);
|
||||
|
||||
// если _input — создаём новый объект
|
||||
if (suffix == "_input")
|
||||
{
|
||||
int millideg = 0;
|
||||
std::ifstream tempFile(f.path());
|
||||
tempFile >> millideg;
|
||||
temperature.max = millideg / 1000.0f; // °C
|
||||
if (n >= static_cast<int>(physical.size()))
|
||||
physical.resize(n + 1);
|
||||
physical[n].current = value;
|
||||
}
|
||||
if (fname.find("temp") == 0 && fname.find("_crit") != std::string::npos)
|
||||
else
|
||||
{
|
||||
int millideg = 0;
|
||||
std::ifstream tempFile(f.path());
|
||||
tempFile >> millideg;
|
||||
temperature.critical = millideg / 1000.0f; // °C
|
||||
// _max/_crit: если temps[n] ещё нет, создаём объект
|
||||
if (n >= static_cast<int>(physical.size()))
|
||||
physical.resize(n + 1);
|
||||
if (suffix == "_max")
|
||||
physical[n].max = value;
|
||||
}
|
||||
physical.push_back(temperature);
|
||||
}
|
||||
|
||||
// Убираем пропуски: оставшиеся нули → копируем предыдущий или последующий?
|
||||
// Можно фильтровать нулевые ядра, если нужно
|
||||
physical.erase(std::remove_if(physical.begin(), physical.end(),
|
||||
[](const CpuTemperature &t)
|
||||
{ return t.current == 0 && t.max == 0; }),
|
||||
physical.end());
|
||||
|
||||
for (size_t i = 0; i < logicalToPhysical.size(); ++i)
|
||||
{
|
||||
int phys = logicalToPhysical[i];
|
||||
if (phys >= static_cast<int>(physical.size()))
|
||||
phys = physical.size() - 1; // safety
|
||||
logical[i] = physical[phys];
|
||||
|
||||
std::cout << i << " " << logical[i].current << "/" << logical[i].max << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,5 @@ namespace metrics
|
||||
{
|
||||
float current;
|
||||
float max;
|
||||
float critical;
|
||||
};
|
||||
} // namespace metrics
|
||||
@@ -43,7 +43,6 @@ namespace metrics
|
||||
{
|
||||
buf.writeFloat(f.current);
|
||||
buf.writeFloat(f.max);
|
||||
buf.writeFloat(f.critical);
|
||||
}
|
||||
|
||||
// Memory
|
||||
@@ -90,7 +89,7 @@ namespace metrics
|
||||
h.cpu.coreTemps.clear();
|
||||
h.cpu.coreTemps.reserve(numCpu);
|
||||
for (uint8_t i = 0; i < numCpu; ++i)
|
||||
h.cpu.coreTemps.push_back({buf.readFloat(), buf.readFloat(), buf.readFloat()});
|
||||
h.cpu.coreTemps.push_back({buf.readFloat(), buf.readFloat()});
|
||||
|
||||
// Memory
|
||||
h.memory.memory.used = buf.readUint64();
|
||||
|
||||
Reference in New Issue
Block a user