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.

148 lines
5.3 KiB

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