|
|
|
@ -1842,6 +1842,9 @@ DBC_INT_LIST * hardwareManager::requestResourcesByType(HARDWARE_PROVIDERS type) |
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sensors/sensors.h>
|
|
|
|
#include <sensors/error.h>
|
|
|
|
|
|
|
|
bool hardwareManager::updateSysInfo(DBC_SYS_LOAD_INFO * ptr) |
|
|
|
{ |
|
|
|
if (ptr == NULL) |
|
|
|
@ -1903,36 +1906,28 @@ bool hardwareManager::updateSysInfo(DBC_SYS_LOAD_INFO * ptr) |
|
|
|
}; |
|
|
|
// const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
|
|
|
|
|
|
|
|
if (statvfs("/", &DI) == 0) |
|
|
|
{ |
|
|
|
if( statvfs("/", &DI) == 0 ){ |
|
|
|
ptr->T_DISK = (DI.f_blocks * (unsigned long long) DI.f_frsize) >> 10; // / MB;
|
|
|
|
// cDISK = ( DI.f_bavail * (unsigned long long) DI.f_bsize ) >> 10;// / MB;
|
|
|
|
ptr->C_DISK = ptr->T_DISK - ((DI.f_bfree * (unsigned long long) DI.f_bsize) >> 10); |
|
|
|
ptr->disk = 100.0f * (float) ptr->C_DISK / (float) ptr->T_DISK; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
} else { |
|
|
|
LOG_ERROR("Error while getting Disk Info!"); |
|
|
|
}; |
|
|
|
// Temperature reading
|
|
|
|
ptr->temperature = -1; |
|
|
|
if (fileExist("/sys/class/thermal")) |
|
|
|
{ |
|
|
|
if (fileExist("/sys/class/thermal")){ |
|
|
|
char tB[128]; |
|
|
|
// Check first 8 zones to find CPU one
|
|
|
|
for (uint8_t i = 0; i < 8; i++) |
|
|
|
{ |
|
|
|
for (uint8_t i = 0; i < 8; i++){ |
|
|
|
sprintf(tB, "/sys/class/thermal/thermal_zone%d", i); |
|
|
|
if (fileExist(tB)) |
|
|
|
{ |
|
|
|
if (fileExist(tB)){ |
|
|
|
sprintf(tB, "/sys/class/thermal/thermal_zone%d/type", i); |
|
|
|
if (fileExist(tB)) |
|
|
|
{ |
|
|
|
if (fileExist(tB)){ |
|
|
|
FILE * fd = fopen(tB, "r"); |
|
|
|
readLine(fd, tB, 128); |
|
|
|
fclose(fd); |
|
|
|
if (strcasestr(tB, "cpu") != NULL || strcasestr(tB, "x86_pkg") != NULL || strcasestr(tB, "acpitz") != NULL) |
|
|
|
{ |
|
|
|
if (strcasestr(tB, "cpu") != NULL || strcasestr(tB, "x86_pkg") != NULL || strcasestr(tB, "acpitz") != NULL){ |
|
|
|
sprintf(tB, "/sys/class/thermal/thermal_zone%d/temp", i); |
|
|
|
FILE * fd = fopen(tB, "r"); |
|
|
|
readLine(fd, tB, 128); |
|
|
|
@ -1940,19 +1935,67 @@ bool hardwareManager::updateSysInfo(DBC_SYS_LOAD_INFO * ptr) |
|
|
|
ptr->temperature = ((float) atoll(tB)) / 1000.0f; |
|
|
|
break; |
|
|
|
}; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
} else { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
}; |
|
|
|
} else { |
|
|
|
break; |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
}; |
|
|
|
if ( ptr->temperature < 0 ) { |
|
|
|
//still have problem to read temp
|
|
|
|
// last chance -> use lm-sensors
|
|
|
|
if( sensors_init(nullptr) == 0 ) { |
|
|
|
int chip_nr = 0; |
|
|
|
const sensors_chip_name* chip; |
|
|
|
// 2. Iterate through all detected sensor chips
|
|
|
|
while ((chip = sensors_get_detected_chips(nullptr, &chip_nr)) != nullptr) { |
|
|
|
//char chip_name_buf[256];
|
|
|
|
//sensors_snprintf_chip_name(chip_name_buf, sizeof(chip_name_buf), chip);
|
|
|
|
//LOG( chip_name_buf );
|
|
|
|
//LOG( chip->prefix );
|
|
|
|
|
|
|
|
int feat_nr = 0; |
|
|
|
const sensors_feature* feature; |
|
|
|
|
|
|
|
// 3. Iterate through all features of the current chip
|
|
|
|
while ((feature = sensors_get_features(chip, &feat_nr)) != nullptr) { |
|
|
|
// Filter strictly for Temperature Features
|
|
|
|
if (feature->type == SENSORS_FEATURE_TEMP) { |
|
|
|
// Get the user-friendly label for this sensor (e.g., "Core 0", "CPU Temperature")
|
|
|
|
//char* label = sensors_get_label(chip, feature);
|
|
|
|
//LOG((label ? label : "Unknown"));
|
|
|
|
//if( label ) free( label ); // Must free the label returned by libsensors
|
|
|
|
// 4. Find the main subfeature containing the actual reading (input value)
|
|
|
|
const sensors_subfeature* subfeature = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_INPUT); |
|
|
|
if (subfeature != nullptr) { |
|
|
|
double val = 0.0; |
|
|
|
// 5. Inquiry the actual temperature reading
|
|
|
|
if ( sensors_get_value(chip, subfeature->number, &val) == 0 ) { |
|
|
|
//char tB[128];
|
|
|
|
//sprintf( tB, "T: %0.3f °C", val );
|
|
|
|
//LOG( tB );
|
|
|
|
if ( val > 0.0 ) { |
|
|
|
ptr->temperature = ( float ) val; |
|
|
|
break; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
LOG_ERROR("[Error reading value]"); |
|
|
|
}; |
|
|
|
} else { |
|
|
|
LOG_ERROR("[No input channel found]"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
if ( ptr->temperature > 0.0f ) { |
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// 6. Clean up resources allocated by the library
|
|
|
|
sensors_cleanup(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return m_pDBC->updateServerUtilisation(ptr); |
|
|
|
} |
|
|
|
|
|
|
|
|