You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.0 KiB

​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "servaKernel.h"
  2. #include <sys/types.h>
  3. #include <sys/sysinfo.h>
  4. #include <sys/statvfs.h>
  5. #define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X )
  6. #ifdef DEBUG
  7. #define LOG_ERROR( X ) {\
  8. char _tBfrErrMSG234[256];\
  9. sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  10. kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\
  11. }
  12. #else
  13. #define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
  14. #endif
  15. bool servaKernel::registerServA(){
  16. m_pDBC->setServerStatValue( SERVER_VERSION, _BUILD_STRING_ );
  17. #ifndef NO_EXEC_EXTERNALS
  18. char OS_INFO[120];
  19. FILE *fd = popen("/bin/uname -s -r -v -m","r");
  20. if( fd!= NULL ) {
  21. fgets( OS_INFO, 127, fd);
  22. OS_INFO[127] = (char)0;
  23. trim( OS_INFO );
  24. fclose( fd );
  25. fd = NULL;
  26. m_pDBC->setServerStatValue( SERVER_OS, OS_INFO );
  27. } else m_pDBC->setServerStatValue( SERVER_OS, "Linux" );
  28. #else
  29. FILE *fd = NULL;
  30. m_pDBC->setServerStatValue( SERVER_OS, "Linux" );
  31. #endif
  32. char HW_INFO[128];
  33. fd = fopen("/proc/cpuinfo","r");
  34. if ( fd!= NULL ) {
  35. char tBB[1024];
  36. bool bARM = false;
  37. while( !feof( fd ) ) {
  38. fgets( tBB, 1024, fd );
  39. trim( tBB );
  40. if( strcasestr(tBB, "model") != NULL ) {
  41. if( strcasestr(tBB, "model name") != NULL ) {
  42. if ( !bARM ) {
  43. if( strcasestr( tBB, "ARM" ) != NULL){
  44. bARM = true;
  45. } else {
  46. CArray *tA = explode(':', tBB );
  47. if ( tA ) {
  48. strncpy( HW_INFO, tA->at(1), 127 );
  49. delete tA;
  50. };
  51. break;
  52. };
  53. };
  54. } else {
  55. if( bARM ) {
  56. CArray *tA = explode(':', tBB);
  57. if ( tA ) {
  58. strncpy( HW_INFO, tA->at(1), 127 );
  59. delete tA;
  60. };
  61. break;
  62. };
  63. };
  64. };
  65. };
  66. HW_INFO[127] = (char)0;
  67. trim( HW_INFO );
  68. fclose( fd );
  69. fd = NULL;
  70. };
  71. m_pDBC->setServerStatValue( SERVER_HW, HW_INFO );
  72. m_pDBC->setServerStatValue( SERVER_START_TS, (uint32_t) time(NULL) );
  73. return true;
  74. };
  75. bool servaKernel::updateStatus(){
  76. struct sysinfo SI;
  77. struct statvfs DI;
  78. DBC_SYS_LOAD_INFO info = { 0 };
  79. info.CPU_CORES = get_nprocs();
  80. info.C_TS = (uint32_t) time(NULL);
  81. if( sysinfo( &SI ) == 0 ){
  82. float f_load = 100.f / (float)( info.CPU_CORES * ( 1 << SI_LOAD_SHIFT ) );
  83. info.cpu1 = SI.loads[0] * f_load;
  84. info.cpu5 = SI.loads[1] * f_load;
  85. info.cpu15 = SI.loads[2] * f_load;
  86. info.T_MEM = SI.totalram;
  87. info.C_MEM = SI.totalram - SI.freeram;
  88. info.mem = 100.0f * (float)info.C_MEM / (float)info.T_MEM;
  89. } else {
  90. LOG_ERROR("Error while getting System Info!");
  91. };
  92. //const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
  93. if( statvfs("/", &DI) == 0 ){
  94. info.T_DISK = ( DI.f_blocks * (unsigned long long) DI.f_frsize ) >> 10;// / MB;
  95. //cDISK = ( DI.f_bavail * (unsigned long long) DI.f_bsize ) >> 10;// / MB;
  96. info.C_DISK = info.T_DISK - ( ( DI.f_bfree * (unsigned long long) DI.f_bsize ) >> 10 );
  97. info.disk = 100.0f * (float)info.C_DISK / (float)info.T_DISK;
  98. } else {
  99. LOG_ERROR("Error while getting Disk Info!");
  100. };
  101. //Temperature reading
  102. info.temperature = -1;
  103. if( fileExist( "/sys/class/thermal" ) ) {
  104. char tB[128];
  105. // Check first 8 zones to find CPU one
  106. for ( uint8_t i = 0; i < 8; i++ ) {
  107. sprintf( tB, "/sys/class/thermal/thermal_zone%d", i );
  108. if ( fileExist( tB ) ) {
  109. sprintf( tB, "/sys/class/thermal/thermal_zone%d/type", i );
  110. if ( fileExist( tB ) ) {
  111. FILE *fd = fopen( tB, "r" );
  112. readLine( fd, tB, 128 );
  113. fclose(fd);
  114. if ( strcasestr(tB,"cpu")!=NULL || strcasestr(tB,"x86_pkg")!=NULL) {
  115. sprintf( tB, "/sys/class/thermal/thermal_zone%d/temp", i );
  116. FILE *fd = fopen( tB, "r" );
  117. readLine( fd, tB, 128 );
  118. fclose(fd);
  119. info.temperature = ((float) atoll( tB )) / 1000.0f;
  120. break;
  121. };
  122. } else continue;
  123. } else break;
  124. };
  125. };
  126. return m_pDBC->updateServerUtilisation( &info );
  127. };
  128. #undef LOG
  129. #undef LOG_ERROR