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.

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