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.

259 lines
9.3 KiB

​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
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::cleanUpMess(){
  16. LOG("Cleanup");
  17. //Get Not transfered Items
  18. DBC_UINT64_LIST *tList = m_pDBC->listMediaQueueItems( 0 );
  19. if ( tList ) {
  20. LOG("1");
  21. for ( DBC_UINT64_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
  22. LOG("*");
  23. DBC_RPC_MEDIA_INFO_EX *tData = m_pDBC->getRemoteMediaInfoEx( *idx );
  24. if ( tData ) {
  25. LOG("2");
  26. CSTR tRB = m_pSM->getReportDir( m_pDBC->getSessionTrackId( tData->session_id ), tData->ts );
  27. if ( tRB ) {
  28. LOG("3");
  29. char tName[MAX_PATH];
  30. sprintf( tName, "%s/%s.%s", tRB, tData->uuid, tData->fmt );
  31. LOG( tName );
  32. free( tRB );
  33. unlink( tName );
  34. };
  35. LOG("f");
  36. free( tData );
  37. };
  38. m_pDBC->removeRemoteMediaInfo( *idx );
  39. };
  40. LOG("-");
  41. tList->clear();
  42. delete( tList );
  43. };
  44. //Get Not Converted Items
  45. tList = m_pDBC->listMediaQueueItems( 2 );
  46. if ( tList ) {
  47. LOG("1");
  48. for ( DBC_UINT64_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
  49. LOG("*");
  50. DBC_RPC_MEDIA_INFO_EX *tData = m_pDBC->getRemoteMediaInfoEx( *idx );
  51. if ( tData ) {
  52. LOG("2");
  53. CSTR tRB = m_pSM->getReportDir( m_pDBC->getSessionTrackId( tData->session_id ), tData->ts );
  54. LOG("2a");
  55. if ( tRB ) {
  56. LOG("3");
  57. char tName[MAX_PATH];
  58. sprintf( tName, "%s/%s.%s", tRB, tData->uuid, "mp4" );
  59. free( tRB );
  60. LOG( tName );
  61. unlink( tName );
  62. };
  63. LOG("f");
  64. free( tData );
  65. };
  66. m_pDBC->updateEncodeStatus( *idx, 1, 0 );
  67. };
  68. tList->clear();
  69. delete( tList );
  70. };
  71. return true;
  72. };
  73. bool servaKernel::registerServA(){
  74. DBC_SERVA_CONFIG *tData = m_pDBC->getServaConfig();
  75. if ( tData ) {
  76. memcpy(&m_sServaConfig, tData, sizeof(DBC_SERVA_CONFIG));
  77. } else {
  78. memset(&m_sServaConfig, 0, sizeof(DBC_SERVA_CONFIG));
  79. m_sServaConfig.encoderLimit = 1;
  80. };
  81. m_pDBC->setServerStatValue( SERVER_VERSION, _BUILD_STRING_ );
  82. m_pDBC->setSystemProp("version_string", _BUILD_STRING_ );
  83. #ifndef NO_EXEC_EXTERNALS
  84. char OS_INFO[120];
  85. FILE *fd = popen("/bin/uname -s -r -v -m","r");
  86. if( fd!= NULL ) {
  87. fgets( OS_INFO, 127, fd);
  88. OS_INFO[127] = (char)0;
  89. trim( OS_INFO );
  90. fclose( fd );
  91. fd = NULL;
  92. m_pDBC->setServerStatValue( SERVER_OS, OS_INFO );
  93. m_pDBC->setSystemProp("os_info", (CSTR) OS_INFO );
  94. } else {
  95. m_pDBC->setServerStatValue( SERVER_OS, "Linux" );
  96. m_pDBC->setSystemProp("os_info", "Linux" );
  97. };
  98. #else
  99. FILE *fd = NULL;
  100. m_pDBC->setServerStatValue( SERVER_OS, "Linux" );
  101. m_pDBC->setSystemProp("os_info", "Linux" );
  102. #endif
  103. char HW_INFO[128];
  104. fd = fopen("/proc/cpuinfo","r");
  105. if ( fd!= NULL ) {
  106. char tBB[1024];
  107. bool bARM = false;
  108. while( !feof( fd ) ) {
  109. fgets( tBB, 1024, fd );
  110. trim( tBB );
  111. if( strcasestr(tBB, "model") != NULL ) {
  112. if( strcasestr(tBB, "model name") != NULL ) {
  113. if ( !bARM ) {
  114. if( strcasestr( tBB, "ARM" ) != NULL){
  115. bARM = true;
  116. } else {
  117. CArray *tA = explode(':', tBB );
  118. if ( tA ) {
  119. strncpy( HW_INFO, tA->at(1), 127 );
  120. delete tA;
  121. };
  122. break;
  123. };
  124. };
  125. } else {
  126. if( bARM ) {
  127. CArray *tA = explode(':', tBB);
  128. if ( tA ) {
  129. strncpy( HW_INFO, tA->at(1), 127 );
  130. delete tA;
  131. };
  132. break;
  133. };
  134. };
  135. };
  136. };
  137. HW_INFO[127] = (char)0;
  138. trim( HW_INFO );
  139. fclose( fd );
  140. fd = NULL;
  141. };
  142. m_pDBC->setSystemProp("hw_info", (CSTR) HW_INFO );
  143. m_pDBC->setServerStatValue( SERVER_HW, (CSTR) HW_INFO );
  144. m_pDBC->setServerStatValue( SERVER_START_TS, (uint32_t) time(NULL) );
  145. return true;
  146. };
  147. bool servaKernel::updateStatus(){
  148. struct sysinfo SI;
  149. struct statvfs DI;
  150. DBC_SYS_LOAD_INFO info = { 0 };
  151. info.CPU_CORES = get_nprocs();
  152. info.C_TS = (uint32_t) time(NULL);
  153. if( sysinfo( &SI ) == 0 ){
  154. float f_load = 100.f / (float)( info.CPU_CORES * ( 1 << SI_LOAD_SHIFT ) );
  155. info.cpu1 = SI.loads[0] * f_load;
  156. info.cpu5 = SI.loads[1] * f_load;
  157. info.cpu15 = SI.loads[2] * f_load;
  158. info.T_MEM = SI.totalram;
  159. info.C_MEM = SI.totalram - SI.freeram;
  160. info.mem = 100.0f * (float)info.C_MEM / (float)info.T_MEM;
  161. } else {
  162. LOG_ERROR("Error while getting System Info!");
  163. };
  164. //const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
  165. if( statvfs("/", &DI) == 0 ){
  166. info.T_DISK = ( DI.f_blocks * (unsigned long long) DI.f_frsize ) >> 10;// / MB;
  167. //cDISK = ( DI.f_bavail * (unsigned long long) DI.f_bsize ) >> 10;// / MB;
  168. info.C_DISK = info.T_DISK - ( ( DI.f_bfree * (unsigned long long) DI.f_bsize ) >> 10 );
  169. info.disk = 100.0f * (float)info.C_DISK / (float)info.T_DISK;
  170. } else {
  171. LOG_ERROR("Error while getting Disk Info!");
  172. };
  173. //Check if need to erase some reports
  174. if ( m_sServaConfig.historyAutoDeleteLimit ) {
  175. #ifdef DEBUG_EXTRA
  176. LOG("History Auto Delete is set!");
  177. #endif
  178. if (m_sServaConfig.historyPreserveFreeSpacePerc || m_sServaConfig.historyPreserveFreeSpaceMB) {
  179. #ifdef DEBUG_EXTRA
  180. LOG("History Size is set!");
  181. #endif
  182. uint64_t tid = 0;
  183. if ( m_sServaConfig.historyPreserveFreeSpacePerc > ( 100.0f - info.disk ) ) {
  184. tid = m_pDBC->getSessionOldest( m_sServaConfig.historyAutoDeleteLimit );
  185. } else if ( m_sServaConfig.historyPreserveFreeSpaceMB > ( info.T_DISK - info.C_DISK ) ) {
  186. tid = m_pDBC->getSessionOldest( m_sServaConfig.historyAutoDeleteLimit );
  187. };
  188. if ( tid ) {
  189. LOG("Need to Delete some Sessions!");
  190. m_pSM->eraseSession( tid );
  191. };
  192. #ifdef DEBUG_EXTRA
  193. } else {
  194. LOG("No History Size is set!");
  195. #endif
  196. };
  197. if ( m_sServaConfig.historyDaysLimit ) {
  198. #ifdef DEBUG_EXTRA
  199. LOG("History Time is set!");
  200. #endif
  201. uint32_t cts = time( NULL ) - (m_sServaConfig.historyDaysLimit * 86400);
  202. uint64_t tid = m_pDBC->getSessionOlderThan( cts, m_sServaConfig.historyAutoDeleteLimit );
  203. if ( tid ) {
  204. LOG("Need to Delete some Sessions!");
  205. m_pSM->eraseSession( tid );
  206. };
  207. #ifdef DEBUG_EXTRA
  208. } else {
  209. LOG("No History Time Limit is set!");
  210. #endif
  211. };
  212. #ifdef DEBUG
  213. } else {
  214. LOG("No History Auto Delete!");
  215. #endif
  216. };
  217. //Temperature reading
  218. info.temperature = -1;
  219. if( fileExist( "/sys/class/thermal" ) ) {
  220. char tB[128];
  221. // Check first 8 zones to find CPU one
  222. for ( uint8_t i = 0; i < 8; i++ ) {
  223. sprintf( tB, "/sys/class/thermal/thermal_zone%d", i );
  224. if ( fileExist( tB ) ) {
  225. sprintf( tB, "/sys/class/thermal/thermal_zone%d/type", i );
  226. if ( fileExist( tB ) ) {
  227. FILE *fd = fopen( tB, "r" );
  228. readLine( fd, tB, 128 );
  229. fclose(fd);
  230. if ( strcasestr(tB,"cpu")!=NULL || strcasestr(tB,"x86_pkg")!=NULL || strcasestr(tB,"acpitz")!=NULL ) {
  231. sprintf( tB, "/sys/class/thermal/thermal_zone%d/temp", i );
  232. FILE *fd = fopen( tB, "r" );
  233. readLine( fd, tB, 128 );
  234. fclose(fd);
  235. info.temperature = ((float) atoll( tB )) / 1000.0f;
  236. break;
  237. };
  238. } else continue;
  239. } else break;
  240. };
  241. };
  242. return m_pDBC->updateServerUtilisation( &info );
  243. };
  244. #undef LOG
  245. #undef LOG_ERROR