11 changed files with 276 additions and 40 deletions
-
4Projects/la_mojo/build
-
4Projects/la_serva/build
-
3lib/App/common/dataBinder_structures.h
-
7lib/App/common/hardwareManager.cpp
-
29lib/App/common/serverDataBinder.h
-
103lib/App/common/serverMySQL_dataBinder.cpp
-
10lib/App/common/serverMySQL_dataBinder.h
-
2lib/App/mojo/mojoBackend.cpp
-
15lib/App/serva/servaKernel.cpp
-
3lib/App/serva/servaKernel.h
-
136lib/App/serva/servaKernelToolKit.cpp
@ -1,7 +1,141 @@ |
|||
#include "servaKernel.h"
|
|||
|
|||
#include <sys/types.h>
|
|||
#include <sys/sysinfo.h>
|
|||
#include <sys/statvfs.h>
|
|||
|
|||
|
|||
bool servaKernel::registerMojo(){ |
|||
#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X )
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG234[256];\ |
|||
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
|
|||
bool servaKernel::registerServA(){ |
|||
m_pDBC->setServerStatValue( SERVER_VERSION, _BUILD_STRING_ ); |
|||
#ifndef NO_EXEC_EXTERNALS
|
|||
char OS_INFO[120]; |
|||
FILE *fd = popen("/bin/uname -s -r -v -m","r"); |
|||
if( fd!= NULL ) { |
|||
fgets( OS_INFO, 127, fd); |
|||
OS_INFO[127] = (char)0; |
|||
trim( OS_INFO ); |
|||
fclose( fd ); |
|||
fd = NULL; |
|||
m_pDBC->setServerStatValue( SERVER_OS, OS_INFO ); |
|||
} else m_pDBC->setServerStatValue( SERVER_OS, "Linux" ); |
|||
#else
|
|||
FILE *fd = NULL; |
|||
m_pDBC->setServerStatValue( SERVER_OS, "Linux" ); |
|||
#endif
|
|||
char HW_INFO[128]; |
|||
fd = fopen("/proc/cpuinfo","r"); |
|||
if ( fd!= NULL ) { |
|||
char tBB[1024]; |
|||
bool bARM = false; |
|||
while( !feof( fd ) ) { |
|||
fgets( tBB, 1024, fd ); |
|||
trim( tBB ); |
|||
if( strcasestr(tBB, "model") != NULL ) { |
|||
if( strcasestr(tBB, "model name") != NULL ) { |
|||
if ( !bARM ) { |
|||
if( strcasestr( tBB, "ARM" ) != NULL){ |
|||
bARM = true; |
|||
} else { |
|||
CArray *tA = explode(':', tBB ); |
|||
if ( tA ) { |
|||
strncpy( HW_INFO, tA->at(1), 127 ); |
|||
delete tA; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
} else { |
|||
if( bARM ) { |
|||
CArray *tA = explode(':', tBB); |
|||
if ( tA ) { |
|||
strncpy( HW_INFO, tA->at(1), 127 ); |
|||
delete tA; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
HW_INFO[127] = (char)0; |
|||
trim( HW_INFO ); |
|||
fclose( fd ); |
|||
fd = NULL; |
|||
}; |
|||
m_pDBC->setServerStatValue( SERVER_HW, HW_INFO ); |
|||
m_pDBC->setServerStatValue( SERVER_START_TS, (uint32_t) time(NULL) ); |
|||
return true; |
|||
}; |
|||
|
|||
bool servaKernel::updateStatus(){ |
|||
struct sysinfo SI; |
|||
struct statvfs DI; |
|||
DBC_SYS_LOAD_INFO info = { 0 }; |
|||
|
|||
info.CPU_CORES = get_nprocs(); |
|||
info.C_TS = (uint32_t) time(NULL); |
|||
|
|||
if( sysinfo( &SI ) == 0 ){ |
|||
float f_load = 100.f / (float)( info.CPU_CORES * ( 1 << SI_LOAD_SHIFT ) ); |
|||
info.cpu1 = SI.loads[0] * f_load; |
|||
info.cpu5 = SI.loads[1] * f_load; |
|||
info.cpu15 = SI.loads[2] * f_load; |
|||
info.T_MEM = SI.totalram; |
|||
info.C_MEM = SI.totalram - SI.freeram; |
|||
info.mem = 100.0f * (float)info.C_MEM / (float)info.T_MEM; |
|||
} else { |
|||
LOG_ERROR("Error while getting System Info!"); |
|||
}; |
|||
//const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
|
|||
|
|||
if( statvfs("/", &DI) == 0 ){ |
|||
info.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;
|
|||
info.C_DISK = info.T_DISK - ( ( DI.f_bfree * (unsigned long long) DI.f_bsize ) >> 10 ); |
|||
info.disk = 100.0f * (float)info.C_DISK / (float)info.T_DISK; |
|||
} else { |
|||
LOG_ERROR("Error while getting Disk Info!"); |
|||
}; |
|||
//Temperature reading
|
|||
info.temperature = -1; |
|||
if( fileExist( "/sys/class/thermal" ) ) { |
|||
char tB[128]; |
|||
// Check first 8 zones to find CPU one
|
|||
for ( uint8_t i = 0; i < 8; i++ ) { |
|||
sprintf( tB, "/sys/class/thermal/thermal_zone%d", i ); |
|||
if ( fileExist( tB ) ) { |
|||
sprintf( tB, "/sys/class/thermal/thermal_zone%d/type", i ); |
|||
if ( fileExist( tB ) ) { |
|||
FILE *fd = fopen( tB, "r" ); |
|||
readLine( fd, tB, 128 ); |
|||
fclose(fd); |
|||
if ( strcasestr(tB,"cpu")!=NULL || strcasestr(tB,"x86_pkg")!=NULL) { |
|||
sprintf( tB, "/sys/class/thermal/thermal_zone%d/temp", i ); |
|||
FILE *fd = fopen( tB, "r" ); |
|||
readLine( fd, tB, 128 ); |
|||
fclose(fd); |
|||
info.temperature = ((float) atoll( tB )) / 1000.0f; |
|||
break; |
|||
}; |
|||
} else continue; |
|||
} else break; |
|||
}; |
|||
}; |
|||
return m_pDBC->updateServerUtilisation( &info ); |
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue