cpu.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. 'use strict';
  2. // @ts-check
  3. // ==================================================================================
  4. // cpu.js
  5. // ----------------------------------------------------------------------------------
  6. // Description: System Information - library
  7. // for Node.js
  8. // Copyright: (c) 2014 - 2022
  9. // Author: Sebastian Hildebrandt
  10. // ----------------------------------------------------------------------------------
  11. // License: MIT
  12. // ==================================================================================
  13. // 4. CPU
  14. // ----------------------------------------------------------------------------------
  15. const os = require('os');
  16. const exec = require('child_process').exec;
  17. const execSync = require('child_process').execSync;
  18. const fs = require('fs');
  19. const util = require('./util');
  20. let _platform = process.platform;
  21. const _linux = (_platform === 'linux' || _platform === 'android');
  22. const _darwin = (_platform === 'darwin');
  23. const _windows = (_platform === 'win32');
  24. const _freebsd = (_platform === 'freebsd');
  25. const _openbsd = (_platform === 'openbsd');
  26. const _netbsd = (_platform === 'netbsd');
  27. const _sunos = (_platform === 'sunos');
  28. let _cpu_speed = 0;
  29. let _current_cpu = {
  30. user: 0,
  31. nice: 0,
  32. system: 0,
  33. idle: 0,
  34. irq: 0,
  35. load: 0,
  36. tick: 0,
  37. ms: 0,
  38. currentLoad: 0,
  39. currentLoadUser: 0,
  40. currentLoadSystem: 0,
  41. currentLoadNice: 0,
  42. currentLoadIdle: 0,
  43. currentLoadIrq: 0,
  44. rawCurrentLoad: 0,
  45. rawCurrentLoadUser: 0,
  46. rawCurrentLoadSystem: 0,
  47. rawCurrentLoadNice: 0,
  48. rawCurrentLoadIdle: 0,
  49. rawCurrentLoadIrq: 0
  50. };
  51. let _cpus = [];
  52. let _corecount = 0;
  53. const AMDBaseFrequencies = {
  54. '8346': '1.8',
  55. '8347': '1.9',
  56. '8350': '2.0',
  57. '8354': '2.2',
  58. '8356|SE': '2.4',
  59. '8356': '2.3',
  60. '8360': '2.5',
  61. '2372': '2.1',
  62. '2373': '2.1',
  63. '2374': '2.2',
  64. '2376': '2.3',
  65. '2377': '2.3',
  66. '2378': '2.4',
  67. '2379': '2.4',
  68. '2380': '2.5',
  69. '2381': '2.5',
  70. '2382': '2.6',
  71. '2384': '2.7',
  72. '2386': '2.8',
  73. '2387': '2.8',
  74. '2389': '2.9',
  75. '2393': '3.1',
  76. '8374': '2.2',
  77. '8376': '2.3',
  78. '8378': '2.4',
  79. '8379': '2.4',
  80. '8380': '2.5',
  81. '8381': '2.5',
  82. '8382': '2.6',
  83. '8384': '2.7',
  84. '8386': '2.8',
  85. '8387': '2.8',
  86. '8389': '2.9',
  87. '8393': '3.1',
  88. '2419EE': '1.8',
  89. '2423HE': '2.0',
  90. '2425HE': '2.1',
  91. '2427': '2.2',
  92. '2431': '2.4',
  93. '2435': '2.6',
  94. '2439SE': '2.8',
  95. '8425HE': '2.1',
  96. '8431': '2.4',
  97. '8435': '2.6',
  98. '8439SE': '2.8',
  99. '4122': '2.2',
  100. '4130': '2.6',
  101. '4162EE': '1.7',
  102. '4164EE': '1.8',
  103. '4170HE': '2.1',
  104. '4174HE': '2.3',
  105. '4176HE': '2.4',
  106. '4180': '2.6',
  107. '4184': '2.8',
  108. '6124HE': '1.8',
  109. '6128HE': '2.0',
  110. '6132HE': '2.2',
  111. '6128': '2.0',
  112. '6134': '2.3',
  113. '6136': '2.4',
  114. '6140': '2.6',
  115. '6164HE': '1.7',
  116. '6166HE': '1.8',
  117. '6168': '1.9',
  118. '6172': '2.1',
  119. '6174': '2.2',
  120. '6176': '2.3',
  121. '6176SE': '2.3',
  122. '6180SE': '2.5',
  123. '3250': '2.5',
  124. '3260': '2.7',
  125. '3280': '2.4',
  126. '4226': '2.7',
  127. '4228': '2.8',
  128. '4230': '2.9',
  129. '4234': '3.1',
  130. '4238': '3.3',
  131. '4240': '3.4',
  132. '4256': '1.6',
  133. '4274': '2.5',
  134. '4276': '2.6',
  135. '4280': '2.8',
  136. '4284': '3.0',
  137. '6204': '3.3',
  138. '6212': '2.6',
  139. '6220': '3.0',
  140. '6234': '2.4',
  141. '6238': '2.6',
  142. '6262HE': '1.6',
  143. '6272': '2.1',
  144. '6274': '2.2',
  145. '6276': '2.3',
  146. '6278': '2.4',
  147. '6282SE': '2.6',
  148. '6284SE': '2.7',
  149. '6308': '3.5',
  150. '6320': '2.8',
  151. '6328': '3.2',
  152. '6338P': '2.3',
  153. '6344': '2.6',
  154. '6348': '2.8',
  155. '6366': '1.8',
  156. '6370P': '2.0',
  157. '6376': '2.3',
  158. '6378': '2.4',
  159. '6380': '2.5',
  160. '6386': '2.8',
  161. 'FX|4100': '3.6',
  162. 'FX|4120': '3.9',
  163. 'FX|4130': '3.8',
  164. 'FX|4150': '3.8',
  165. 'FX|4170': '4.2',
  166. 'FX|6100': '3.3',
  167. 'FX|6120': '3.6',
  168. 'FX|6130': '3.6',
  169. 'FX|6200': '3.8',
  170. 'FX|8100': '2.8',
  171. 'FX|8120': '3.1',
  172. 'FX|8140': '3.2',
  173. 'FX|8150': '3.6',
  174. 'FX|8170': '3.9',
  175. 'FX|4300': '3.8',
  176. 'FX|4320': '4.0',
  177. 'FX|4350': '4.2',
  178. 'FX|6300': '3.5',
  179. 'FX|6350': '3.9',
  180. 'FX|8300': '3.3',
  181. 'FX|8310': '3.4',
  182. 'FX|8320': '3.5',
  183. 'FX|8350': '4.0',
  184. 'FX|8370': '4.0',
  185. 'FX|9370': '4.4',
  186. 'FX|9590': '4.7',
  187. 'FX|8320E': '3.2',
  188. 'FX|8370E': '3.3',
  189. // ZEN Desktop CPUs
  190. '1200': '3.1',
  191. 'Pro 1200': '3.1',
  192. '1300X': '3.5',
  193. 'Pro 1300': '3.5',
  194. '1400': '3.2',
  195. '1500X': '3.5',
  196. 'Pro 1500': '3.5',
  197. '1600': '3.2',
  198. '1600X': '3.6',
  199. 'Pro 1600': '3.2',
  200. '1700': '3.0',
  201. 'Pro 1700': '3.0',
  202. '1700X': '3.4',
  203. 'Pro 1700X': '3.4',
  204. '1800X': '3.6',
  205. '1900X': '3.8',
  206. '1920': '3.2',
  207. '1920X': '3.5',
  208. '1950X': '3.4',
  209. // ZEN Desktop APUs
  210. '200GE': '3.2',
  211. 'Pro 200GE': '3.2',
  212. '220GE': '3.4',
  213. '240GE': '3.5',
  214. '3000G': '3.5',
  215. '300GE': '3.4',
  216. '3050GE': '3.4',
  217. '2200G': '3.5',
  218. 'Pro 2200G': '3.5',
  219. '2200GE': '3.2',
  220. 'Pro 2200GE': '3.2',
  221. '2400G': '3.6',
  222. 'Pro 2400G': '3.6',
  223. '2400GE': '3.2',
  224. 'Pro 2400GE': '3.2',
  225. // ZEN Mobile APUs
  226. 'Pro 200U': '2.3',
  227. '300U': '2.4',
  228. '2200U': '2.5',
  229. '3200U': '2.6',
  230. '2300U': '2.0',
  231. 'Pro 2300U': '2.0',
  232. '2500U': '2.0',
  233. 'Pro 2500U': '2.2',
  234. '2600H': '3.2',
  235. '2700U': '2.0',
  236. 'Pro 2700U': '2.2',
  237. '2800H': '3.3',
  238. // ZEN Server Processors
  239. '7351': '2.4',
  240. '7351P': '2.4',
  241. '7401': '2.0',
  242. '7401P': '2.0',
  243. '7551P': '2.0',
  244. '7551': '2.0',
  245. '7251': '2.1',
  246. '7261': '2.5',
  247. '7281': '2.1',
  248. '7301': '2.2',
  249. '7371': '3.1',
  250. '7451': '2.3',
  251. '7501': '2.0',
  252. '7571': '2.2',
  253. '7601': '2.2',
  254. // ZEN Embedded Processors
  255. 'V1500B': '2.2',
  256. 'V1780B': '3.35',
  257. 'V1202B': '2.3',
  258. 'V1404I': '2.0',
  259. 'V1605B': '2.0',
  260. 'V1756B': '3.25',
  261. 'V1807B': '3.35',
  262. '3101': '2.1',
  263. '3151': '2.7',
  264. '3201': '1.5',
  265. '3251': '2.5',
  266. '3255': '2.5',
  267. '3301': '2.0',
  268. '3351': '1.9',
  269. '3401': '1.85',
  270. '3451': '2.15',
  271. // ZEN+ Desktop
  272. '1200|AF': '3.1',
  273. '2300X': '3.5',
  274. '2500X': '3.6',
  275. '2600': '3.4',
  276. '2600E': '3.1',
  277. '1600|AF': '3.2',
  278. '2600X': '3.6',
  279. '2700': '3.2',
  280. '2700E': '2.8',
  281. 'Pro 2700': '3.2',
  282. '2700X': '3.7',
  283. 'Pro 2700X': '3.6',
  284. '2920X': '3.5',
  285. '2950X': '3.5',
  286. '2970WX': '3.0',
  287. '2990WX': '3.0',
  288. // ZEN+ Desktop APU
  289. 'Pro 300GE': '3.4',
  290. 'Pro 3125GE': '3.4',
  291. '3150G': '3.5',
  292. 'Pro 3150G': '3.5',
  293. '3150GE': '3.3',
  294. 'Pro 3150GE': '3.3',
  295. '3200G': '3.6',
  296. 'Pro 3200G': '3.6',
  297. '3200GE': '3.3',
  298. 'Pro 3200GE': '3.3',
  299. '3350G': '3.6',
  300. 'Pro 3350G': '3.6',
  301. '3350GE': '3.3',
  302. 'Pro 3350GE': '3.3',
  303. '3400G': '3.7',
  304. 'Pro 3400G': '3.7',
  305. '3400GE': '3.3',
  306. 'Pro 3400GE': '3.3',
  307. // ZEN+ Mobile
  308. '3300U': '2.1',
  309. 'PRO 3300U': '2.1',
  310. '3450U': '2.1',
  311. '3500U': '2.1',
  312. 'PRO 3500U': '2.1',
  313. '3500C': '2.1',
  314. '3550H': '2.1',
  315. '3580U': '2.1',
  316. '3700U': '2.3',
  317. 'PRO 3700U': '2.3',
  318. '3700C': '2.3',
  319. '3750H': '2.3',
  320. '3780U': '2.3',
  321. // ZEN2 Desktop CPUS
  322. '3100': '3.6',
  323. '3300X': '3.8',
  324. '3500': '3.6',
  325. '3500X': '3.6',
  326. '3600': '3.6',
  327. 'Pro 3600': '3.6',
  328. '3600X': '3.8',
  329. '3600XT': '3.8',
  330. 'Pro 3700': '3.6',
  331. '3700X': '3.6',
  332. '3800X': '3.9',
  333. '3800XT': '3.9',
  334. '3900': '3.1',
  335. 'Pro 3900': '3.1',
  336. '3900X': '3.8',
  337. '3900XT': '3.8',
  338. '3950X': '3.5',
  339. '3960X': '3.8',
  340. '3970X': '3.7',
  341. '3990X': '2.9',
  342. '3945WX': '4.0',
  343. '3955WX': '3.9',
  344. '3975WX': '3.5',
  345. '3995WX': '2.7',
  346. // ZEN2 Desktop APUs
  347. '4300GE': '3.5',
  348. 'Pro 4300GE': '3.5',
  349. '4300G': '3.8',
  350. 'Pro 4300G': '3.8',
  351. '4600GE': '3.3',
  352. 'Pro 4650GE': '3.3',
  353. '4600G': '3.7',
  354. 'Pro 4650G': '3.7',
  355. '4700GE': '3.1',
  356. 'Pro 4750GE': '3.1',
  357. '4700G': '3.6',
  358. 'Pro 4750G': '3.6',
  359. '4300U': '2.7',
  360. '4450U': '2.5',
  361. 'Pro 4450U': '2.5',
  362. '4500U': '2.3',
  363. '4600U': '2.1',
  364. 'PRO 4650U': '2.1',
  365. '4680U': '2.1',
  366. '4600HS': '3.0',
  367. '4600H': '3.0',
  368. '4700U': '2.0',
  369. 'PRO 4750U': '1.7',
  370. '4800U': '1.8',
  371. '4800HS': '2.9',
  372. '4800H': '2.9',
  373. '4900HS': '3.0',
  374. '4900H': '3.3',
  375. '5300U': '2.6',
  376. '5500U': '2.1',
  377. '5700U': '1.8',
  378. // ZEN2 - EPYC
  379. '7232P': '3.1',
  380. '7302P': '3.0',
  381. '7402P': '2.8',
  382. '7502P': '2.5',
  383. '7702P': '2.0',
  384. '7252': '3.1',
  385. '7262': '3.2',
  386. '7272': '2.9',
  387. '7282': '2.8',
  388. '7302': '3.0',
  389. '7352': '2.3',
  390. '7402': '2.8',
  391. '7452': '2.35',
  392. '7502': '2.5',
  393. '7532': '2.4',
  394. '7542': '2.9',
  395. '7552': '2.2',
  396. '7642': '2.3',
  397. '7662': '2.0',
  398. '7702': '2.0',
  399. '7742': '2.25',
  400. '7H12': '2.6',
  401. '7F32': '3.7',
  402. '7F52': '3.5',
  403. '7F72': '3.2',
  404. // Epyc (Milan)
  405. '7763': '2.45',
  406. '7713': '2.0',
  407. '7713P': '2.0',
  408. '7663': '2.0',
  409. '7643': '2.3',
  410. '75F3': '2.95',
  411. '7543': '2.8',
  412. '7543P': '2.8',
  413. '7513': '2.6',
  414. '7453': '2.75',
  415. '74F3': '3.2',
  416. '7443': '2.85',
  417. '7443P': '2.85',
  418. '7413': '2.65',
  419. '73F3': '3.5',
  420. '7343': '3.2',
  421. '7313': '3.0',
  422. '7313P': '3.0',
  423. '72F3': '3.7',
  424. // ZEN3
  425. '5600X': '3.7',
  426. '5800X': '3.8',
  427. '5900X': '3.7',
  428. '5950X': '3.4'
  429. };
  430. const socketTypes = {
  431. 1: 'Other',
  432. 2: 'Unknown',
  433. 3: 'Daughter Board',
  434. 4: 'ZIF Socket',
  435. 5: 'Replacement/Piggy Back',
  436. 6: 'None',
  437. 7: 'LIF Socket',
  438. 8: 'Slot 1',
  439. 9: 'Slot 2',
  440. 10: '370 Pin Socket',
  441. 11: 'Slot A',
  442. 12: 'Slot M',
  443. 13: '423',
  444. 14: 'A (Socket 462)',
  445. 15: '478',
  446. 16: '754',
  447. 17: '940',
  448. 18: '939',
  449. 19: 'mPGA604',
  450. 20: 'LGA771',
  451. 21: 'LGA775',
  452. 22: 'S1',
  453. 23: 'AM2',
  454. 24: 'F (1207)',
  455. 25: 'LGA1366',
  456. 26: 'G34',
  457. 27: 'AM3',
  458. 28: 'C32',
  459. 29: 'LGA1156',
  460. 30: 'LGA1567',
  461. 31: 'PGA988A',
  462. 32: 'BGA1288',
  463. 33: 'rPGA988B',
  464. 34: 'BGA1023',
  465. 35: 'BGA1224',
  466. 36: 'LGA1155',
  467. 37: 'LGA1356',
  468. 38: 'LGA2011',
  469. 39: 'FS1',
  470. 40: 'FS2',
  471. 41: 'FM1',
  472. 42: 'FM2',
  473. 43: 'LGA2011-3',
  474. 44: 'LGA1356-3',
  475. 45: 'LGA1150',
  476. 46: 'BGA1168',
  477. 47: 'BGA1234',
  478. 48: 'BGA1364',
  479. 49: 'AM4',
  480. 50: 'LGA1151',
  481. 51: 'BGA1356',
  482. 52: 'BGA1440',
  483. 53: 'BGA1515',
  484. 54: 'LGA3647-1',
  485. 55: 'SP3',
  486. 56: 'SP3r2',
  487. 57: 'LGA2066',
  488. 58: 'BGA1392',
  489. 59: 'BGA1510',
  490. 60: 'BGA1528',
  491. 61: 'LGA4189',
  492. 62: 'LGA1200',
  493. 63: 'LGA4677',
  494. };
  495. const socketTypesByName = {
  496. 'LGA1150': 'i7-5775C i3-4340 i3-4170 G3250 i3-4160T i3-4160 E3-1231 G3258 G3240 i7-4790S i7-4790K i7-4790 i5-4690K i5-4690 i5-4590T i5-4590S i5-4590 i5-4460 i3-4360 i3-4150 G1820 G3420 G3220 i7-4771 i5-4440 i3-4330 i3-4130T i3-4130 E3-1230 i7-4770S i7-4770K i7-4770 i5-4670K i5-4670 i5-4570T i5-4570S i5-4570 i5-4430',
  497. 'LGA1151': 'i9-9900KS E-2288G E-2224 G5420 i9-9900T i9-9900 i7-9700T i7-9700F i7-9700E i7-9700 i5-9600 i5-9500T i5-9500F i5-9500 i5-9400T i3-9350K i3-9300 i3-9100T i3-9100F i3-9100 G4930 i9-9900KF i7-9700KF i5-9600KF i5-9400F i5-9400 i3-9350KF i9-9900K i7-9700K i5-9600K G5500 G5400 i7-8700T i7-8086K i5-8600 i5-8500T i5-8500 i5-8400T i3-8300 i3-8100T G4900 i7-8700K i7-8700 i5-8600K i5-8400 i3-8350K i3-8100 E3-1270 G4600 G4560 i7-7700T i7-7700K i7-7700 i5-7600K i5-7600 i5-7500T i5-7500 i5-7400 i3-7350K i3-7300 i3-7100T i3-7100 G3930 G3900 G4400 i7-6700T i7-6700K i7-6700 i5-6600K i5-6600 i5-6500T i5-6500 i5-6400T i5-6400 i3-6300 i3-6100T i3-6100 E3-1270 E3-1270 T4500 T4400',
  498. '1155': 'G440 G460 G465 G470 G530T G540T G550T G1610T G1620T G530 G540 G1610 G550 G1620 G555 G1630 i3-2100T i3-2120T i3-3220T i3-3240T i3-3250T i3-2100 i3-2105 i3-2102 i3-3210 i3-3220 i3-2125 i3-2120 i3-3225 i3-2130 i3-3245 i3-3240 i3-3250 i5-3570T i5-2500T i5-2400S i5-2405S i5-2390T i5-3330S i5-2500S i5-3335S i5-2300 i5-3450S i5-3340S i5-3470S i5-3475S i5-3470T i5-2310 i5-3550S i5-2320 i5-3330 i5-3350P i5-3450 i5-2400 i5-3340 i5-3570S i5-2380P i5-2450P i5-3470 i5-2500K i5-3550 i5-2500 i5-3570 i5-3570K i5-2550K i7-3770T i7-2600S i7-3770S i7-2600K i7-2600 i7-3770 i7-3770K i7-2700K G620T G630T G640T G2020T G645T G2100T G2030T G622 G860T G620 G632 G2120T G630 G640 G2010 G840 G2020 G850 G645 G2030 G860 G2120 G870 G2130 G2140 E3-1220L E3-1220L E3-1260L E3-1265L E3-1220 E3-1225 E3-1220 E3-1235 E3-1225 E3-1230 E3-1230 E3-1240 E3-1245 E3-1270 E3-1275 E3-1240 E3-1245 E3-1270 E3-1280 E3-1275 E3-1290 E3-1280 E3-1290'
  499. };
  500. function getSocketTypesByName(str) {
  501. let result = '';
  502. for (const key in socketTypesByName) {
  503. const names = socketTypesByName[key].split(' ');
  504. for (let i = 0; i < names.length; i++) {
  505. if (str.indexOf(names[i]) >= 0) {
  506. result = key;
  507. }
  508. }
  509. }
  510. return result;
  511. }
  512. function cpuManufacturer(str) {
  513. let result = str;
  514. str = str.toLowerCase();
  515. if (str.indexOf('intel') >= 0) { result = 'Intel'; }
  516. if (str.indexOf('amd') >= 0) { result = 'AMD'; }
  517. if (str.indexOf('qemu') >= 0) { result = 'QEMU'; }
  518. if (str.indexOf('hygon') >= 0) { result = 'Hygon'; }
  519. if (str.indexOf('centaur') >= 0) { result = 'WinChip/Via'; }
  520. if (str.indexOf('vmware') >= 0) { result = 'VMware'; }
  521. if (str.indexOf('Xen') >= 0) { result = 'Xen Hypervisor'; }
  522. if (str.indexOf('tcg') >= 0) { result = 'QEMU'; }
  523. if (str.indexOf('apple') >= 0) { result = 'Apple'; }
  524. return result;
  525. }
  526. function cpuBrandManufacturer(res) {
  527. res.brand = res.brand.replace(/\(R\)+/g, '®').replace(/\s+/g, ' ').trim();
  528. res.brand = res.brand.replace(/\(TM\)+/g, '™').replace(/\s+/g, ' ').trim();
  529. res.brand = res.brand.replace(/\(C\)+/g, '©').replace(/\s+/g, ' ').trim();
  530. res.brand = res.brand.replace(/CPU+/g, '').replace(/\s+/g, ' ').trim();
  531. res.manufacturer = cpuManufacturer(res.brand);
  532. let parts = res.brand.split(' ');
  533. parts.shift();
  534. res.brand = parts.join(' ');
  535. return res;
  536. }
  537. function getAMDSpeed(brand) {
  538. let result = '0';
  539. for (let key in AMDBaseFrequencies) {
  540. if ({}.hasOwnProperty.call(AMDBaseFrequencies, key)) {
  541. let parts = key.split('|');
  542. let found = 0;
  543. parts.forEach(item => {
  544. if (brand.indexOf(item) > -1) {
  545. found++;
  546. }
  547. });
  548. if (found === parts.length) {
  549. result = AMDBaseFrequencies[key];
  550. }
  551. }
  552. }
  553. return parseFloat(result);
  554. }
  555. // --------------------------
  556. // CPU - brand, speed
  557. function getCpu() {
  558. return new Promise((resolve) => {
  559. process.nextTick(() => {
  560. const UNKNOWN = 'unknown';
  561. let result = {
  562. manufacturer: UNKNOWN,
  563. brand: UNKNOWN,
  564. vendor: '',
  565. family: '',
  566. model: '',
  567. stepping: '',
  568. revision: '',
  569. voltage: '',
  570. speed: 0,
  571. speedMin: 0,
  572. speedMax: 0,
  573. governor: '',
  574. cores: util.cores(),
  575. physicalCores: util.cores(),
  576. processors: 1,
  577. socket: '',
  578. flags: '',
  579. virtualization: false,
  580. cache: {}
  581. };
  582. cpuFlags().then(flags => {
  583. result.flags = flags;
  584. result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1;
  585. // if (_windows) {
  586. // try {
  587. // const systeminfo = execSync('systeminfo', util.execOptsWin).toString();
  588. // result.virtualization = result.virtualization || (systeminfo.indexOf('Virtualization Enabled In Firmware: Yes') !== -1) || (systeminfo.indexOf('Virtualisierung in Firmware aktiviert: Ja') !== -1) || (systeminfo.indexOf('Virtualisation activée dans le microprogramme : Qiu') !== -1);
  589. // } catch (e) {
  590. // util.noop();
  591. // }
  592. // }
  593. if (_darwin) {
  594. exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', function (error, stdout) {
  595. let lines = stdout.toString().split('\n');
  596. const modelline = util.getValue(lines, 'machdep.cpu.brand_string');
  597. const modellineParts = modelline.split('@');
  598. result.brand = modellineParts[0].trim();
  599. const speed = modellineParts[1] ? modellineParts[1].trim() : '0';
  600. result.speed = parseFloat(speed.replace(/GHz+/g, ''));
  601. let tbFrequency = util.getValue(lines, 'hw.tbfrequency') / 1000000000.0;
  602. tbFrequency = tbFrequency < 0.1 ? tbFrequency * 100 : tbFrequency;
  603. result.speed = result.speed === 0 ? tbFrequency : result.speed;
  604. _cpu_speed = result.speed;
  605. result = cpuBrandManufacturer(result);
  606. result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0) : result.speed;
  607. result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0) : result.speed;
  608. result.vendor = util.getValue(lines, 'machdep.cpu.vendor') || 'Apple';
  609. result.family = util.getValue(lines, 'machdep.cpu.family') || util.getValue(lines, 'hw.cpufamily');
  610. result.model = util.getValue(lines, 'machdep.cpu.model');
  611. result.stepping = util.getValue(lines, 'machdep.cpu.stepping') || util.getValue(lines, 'hw.cpusubfamily');
  612. const countProcessors = util.getValue(lines, 'hw.packages');
  613. const countCores = util.getValue(lines, 'hw.physicalcpu_max');
  614. const countThreads = util.getValue(lines, 'hw.ncpu');
  615. if (os.arch() === 'arm64') {
  616. const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
  617. const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length;
  618. const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length;
  619. result.socket = 'SOC';
  620. result.efficiencyCores = efficiencyCores;
  621. result.performanceCores = performanceCores;
  622. }
  623. if (countProcessors) {
  624. result.processors = parseInt(countProcessors) || 1;
  625. }
  626. if (countCores && countThreads) {
  627. result.cores = parseInt(countThreads) || util.cores();
  628. result.physicalCores = parseInt(countCores) || util.cores();
  629. }
  630. cpuCache().then(res => {
  631. result.cache = res;
  632. resolve(result);
  633. });
  634. });
  635. }
  636. if (_linux) {
  637. let modelline = '';
  638. let lines = [];
  639. if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
  640. exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) {
  641. if (!error) {
  642. lines = stdout.toString().split('\n');
  643. }
  644. modelline = util.getValue(lines, 'model name') || modelline;
  645. const modellineParts = modelline.split('@');
  646. result.brand = modellineParts[0].trim();
  647. result.speed = modellineParts[1] ? parseFloat(modellineParts[1].trim()) : 0;
  648. if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
  649. result.speed = getAMDSpeed(result.brand);
  650. }
  651. if (result.speed === 0) {
  652. const current = getCpuCurrentSpeedSync();
  653. if (current.avg !== 0) { result.speed = current.avg; }
  654. }
  655. _cpu_speed = result.speed;
  656. result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
  657. result.speedMax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
  658. result = cpuBrandManufacturer(result);
  659. result.vendor = cpuManufacturer(util.getValue(lines, 'vendor id'));
  660. // if (!result.vendor) { result.vendor = util.getValue(lines, 'anbieterkennung'); }
  661. result.family = util.getValue(lines, 'cpu family');
  662. // if (!result.family) { result.family = util.getValue(lines, 'prozessorfamilie'); }
  663. result.model = util.getValue(lines, 'model:');
  664. // if (!result.model) { result.model = util.getValue(lines, 'modell:'); }
  665. result.stepping = util.getValue(lines, 'stepping');
  666. result.revision = util.getValue(lines, 'cpu revision');
  667. result.cache.l1d = util.getValue(lines, 'l1d cache');
  668. if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1)); }
  669. result.cache.l1i = util.getValue(lines, 'l1i cache');
  670. if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1)); }
  671. result.cache.l2 = util.getValue(lines, 'l2 cache');
  672. if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1)); }
  673. result.cache.l3 = util.getValue(lines, 'l3 cache');
  674. if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1)); }
  675. const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
  676. // const coresPerSocketInt = parseInt(util.getValue(lines, 'cores(s) per socket') || '1', 10);
  677. const processors = util.getValue(lines, 'socket(s)') || '1';
  678. let threadsPerCoreInt = parseInt(threadsPerCore, 10);
  679. let processorsInt = parseInt(processors, 10);
  680. result.physicalCores = result.cores / threadsPerCoreInt;
  681. result.processors = processorsInt;
  682. result.governor = util.getValue(lines, 'governor') || '';
  683. // Test Raspberry
  684. if (result.vendor === 'ARM') {
  685. const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
  686. const rPIRevision = util.decodePiCpuinfo(linesRpi);
  687. if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
  688. result.family = result.manufacturer;
  689. result.manufacturer = rPIRevision.manufacturer;
  690. result.brand = rPIRevision.processor;
  691. result.revision = rPIRevision.revisionCode;
  692. result.socket = 'SOC';
  693. }
  694. }
  695. // socket type
  696. let lines2 = [];
  697. exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
  698. lines2 = stdout2.toString().split('\n');
  699. if (lines2 && lines2.length) {
  700. result.socket = util.getValue(lines2, 'Upgrade').replace('Socket', '').trim() || result.socket;
  701. }
  702. resolve(result);
  703. });
  704. });
  705. }
  706. if (_freebsd || _openbsd || _netbsd) {
  707. let modelline = '';
  708. let lines = [];
  709. if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
  710. exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) {
  711. let cache = [];
  712. if (!error) {
  713. const data = stdout.toString().split('# dmidecode');
  714. const processor = data.length > 1 ? data[1] : '';
  715. cache = data.length > 2 ? data[2].split('Cache Information') : [];
  716. lines = processor.split('\n');
  717. }
  718. result.brand = modelline.split('@')[0].trim();
  719. result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()) : 0;
  720. if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
  721. result.speed = getAMDSpeed(result.brand);
  722. }
  723. if (result.speed === 0) {
  724. const current = getCpuCurrentSpeedSync();
  725. if (current.avg !== 0) { result.speed = current.avg; }
  726. }
  727. _cpu_speed = result.speed;
  728. result.speedMin = result.speed;
  729. result.speedMax = Math.round(parseFloat(util.getValue(lines, 'max speed').replace(/Mhz/g, '')) / 10.0) / 100;
  730. result = cpuBrandManufacturer(result);
  731. result.vendor = cpuManufacturer(util.getValue(lines, 'manufacturer'));
  732. let sig = util.getValue(lines, 'signature');
  733. sig = sig.split(',');
  734. for (var i = 0; i < sig.length; i++) {
  735. sig[i] = sig[i].trim();
  736. }
  737. result.family = util.getValue(sig, 'Family', ' ', true);
  738. result.model = util.getValue(sig, 'Model', ' ', true);
  739. result.stepping = util.getValue(sig, 'Stepping', ' ', true);
  740. result.revision = '';
  741. const voltage = parseFloat(util.getValue(lines, 'voltage'));
  742. result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2);
  743. for (let i = 0; i < cache.length; i++) {
  744. lines = cache[i].split('\n');
  745. let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
  746. cacheType = cacheType.length ? cacheType[0] : '';
  747. const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
  748. let size = parseInt(sizeParts[0], 10);
  749. const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
  750. size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
  751. if (cacheType) {
  752. if (cacheType === 'l1') {
  753. result.cache[cacheType + 'd'] = size / 2;
  754. result.cache[cacheType + 'i'] = size / 2;
  755. } else {
  756. result.cache[cacheType] = size;
  757. }
  758. }
  759. }
  760. // socket type
  761. result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
  762. // # threads / # cores
  763. const threadCount = util.getValue(lines, 'thread count').trim();
  764. const coreCount = util.getValue(lines, 'core count').trim();
  765. if (coreCount && threadCount) {
  766. result.cores = parseInt(threadCount, 10);
  767. result.physicalCores = parseInt(coreCount, 10);
  768. }
  769. resolve(result);
  770. });
  771. }
  772. if (_sunos) {
  773. resolve(result);
  774. }
  775. if (_windows) {
  776. try {
  777. const workload = [];
  778. workload.push(util.powerShell('Get-WmiObject Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'));
  779. workload.push(util.powerShell('Get-WmiObject Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
  780. // workload.push(util.powerShell('Get-ComputerInfo -property "HyperV*"'));
  781. workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
  782. Promise.all(
  783. workload
  784. ).then(data => {
  785. let lines = data[0].split('\r\n');
  786. let name = util.getValue(lines, 'name', ':') || '';
  787. if (name.indexOf('@') >= 0) {
  788. result.brand = name.split('@')[0].trim();
  789. result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
  790. _cpu_speed = result.speed;
  791. } else {
  792. result.brand = name.trim();
  793. result.speed = 0;
  794. }
  795. result = cpuBrandManufacturer(result);
  796. result.revision = util.getValue(lines, 'revision', ':');
  797. result.cache.l1d = 0;
  798. result.cache.l1i = 0;
  799. result.cache.l2 = util.getValue(lines, 'l2cachesize', ':');
  800. result.cache.l3 = util.getValue(lines, 'l3cachesize', ':');
  801. if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
  802. if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
  803. result.vendor = util.getValue(lines, 'manufacturer', ':');
  804. result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', ':').replace(/,/g, '.')) / 10.0) / 100;
  805. if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
  806. result.speed = getAMDSpeed(result.brand);
  807. }
  808. if (result.speed === 0) {
  809. result.speed = result.speedMax;
  810. }
  811. result.speedMin = result.speed;
  812. let description = util.getValue(lines, 'description', ':').split(' ');
  813. for (let i = 0; i < description.length; i++) {
  814. if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
  815. result.family = description[i + 1];
  816. }
  817. if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
  818. result.model = description[i + 1];
  819. }
  820. if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
  821. result.stepping = description[i + 1];
  822. }
  823. }
  824. // socket type
  825. const socketId = util.getValue(lines, 'UpgradeMethod', ':');
  826. if (socketTypes[socketId]) {
  827. result.socket = socketTypes[socketId];
  828. }
  829. const socketByName = getSocketTypesByName(name);
  830. if (socketByName) {
  831. result.socket = socketByName;
  832. }
  833. // # threads / # cores
  834. const countProcessors = util.countLines(lines, 'Caption');
  835. const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', ':');
  836. const countCores = util.getValue(lines, 'NumberOfCores', ':');
  837. if (countProcessors) {
  838. result.processors = parseInt(countProcessors) || 1;
  839. }
  840. if (countCores && countThreads) {
  841. result.cores = parseInt(countThreads) || util.cores();
  842. result.physicalCores = parseInt(countCores) || util.cores();
  843. }
  844. if (countProcessors > 1) {
  845. result.cores = result.cores * countProcessors;
  846. result.physicalCores = result.physicalCores * countProcessors;
  847. }
  848. const parts = data[1].split(/\n\s*\n/);
  849. parts.forEach(function (part) {
  850. lines = part.split('\r\n');
  851. const cacheType = util.getValue(lines, 'CacheType');
  852. const level = util.getValue(lines, 'Level');
  853. const installedSize = util.getValue(lines, 'InstalledSize');
  854. // L1 Instructions
  855. if (level === '3' && cacheType === '3') {
  856. result.cache.l1i = parseInt(installedSize, 10);
  857. }
  858. // L1 Data
  859. if (level === '3' && cacheType === '4') {
  860. result.cache.l1d = parseInt(installedSize, 10);
  861. }
  862. // L1 all
  863. if (level === '3' && cacheType === '5' && !result.cache.l1i && !result.cache.l1d) {
  864. result.cache.l1i = parseInt(installedSize, 10) / 2;
  865. result.cache.l1d = parseInt(installedSize, 10) / 2;
  866. }
  867. });
  868. // lines = data[2].split('\r\n');
  869. // result.virtualization = (util.getValue(lines, 'HyperVRequirementVirtualizationFirmwareEnabled').toLowerCase() === 'true');
  870. // result.virtualization = (util.getValue(lines, 'HyperVisorPresent').toLowerCase() === 'true');
  871. const hyperv = data[2] ? data[2].toString().toLowerCase() : '';
  872. result.virtualization = hyperv.indexOf('true') !== -1;
  873. resolve(result);
  874. });
  875. } catch (e) {
  876. resolve(result);
  877. }
  878. }
  879. });
  880. });
  881. });
  882. }
  883. // --------------------------
  884. // CPU - Processor Data
  885. function cpu(callback) {
  886. return new Promise((resolve) => {
  887. process.nextTick(() => {
  888. getCpu().then(result => {
  889. if (callback) { callback(result); }
  890. resolve(result);
  891. });
  892. });
  893. });
  894. }
  895. exports.cpu = cpu;
  896. // --------------------------
  897. // CPU - current speed - in GHz
  898. function getCpuCurrentSpeedSync() {
  899. let cpus = os.cpus();
  900. let minFreq = 999999999;
  901. let maxFreq = 0;
  902. let avgFreq = 0;
  903. let cores = [];
  904. if (cpus && cpus.length) {
  905. for (let i in cpus) {
  906. if ({}.hasOwnProperty.call(cpus, i)) {
  907. let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10;
  908. avgFreq = avgFreq + freq;
  909. if (freq > maxFreq) { maxFreq = freq; }
  910. if (freq < minFreq) { minFreq = freq; }
  911. cores.push(parseFloat(freq.toFixed(2)));
  912. }
  913. }
  914. avgFreq = avgFreq / cpus.length;
  915. return {
  916. min: parseFloat(minFreq.toFixed(2)),
  917. max: parseFloat(maxFreq.toFixed(2)),
  918. avg: parseFloat((avgFreq).toFixed(2)),
  919. cores: cores
  920. };
  921. } else {
  922. return {
  923. min: 0,
  924. max: 0,
  925. avg: 0,
  926. cores: cores
  927. };
  928. }
  929. }
  930. function cpuCurrentSpeed(callback) {
  931. return new Promise((resolve) => {
  932. process.nextTick(() => {
  933. let result = getCpuCurrentSpeedSync();
  934. if (result.avg === 0 && _cpu_speed !== 0) {
  935. const currCpuSpeed = parseFloat(_cpu_speed);
  936. result = {
  937. min: currCpuSpeed,
  938. max: currCpuSpeed,
  939. avg: currCpuSpeed,
  940. cores: []
  941. };
  942. }
  943. if (callback) { callback(result); }
  944. resolve(result);
  945. });
  946. });
  947. }
  948. exports.cpuCurrentSpeed = cpuCurrentSpeed;
  949. // --------------------------
  950. // CPU - temperature
  951. // if sensors are installed
  952. function cpuTemperature(callback) {
  953. return new Promise((resolve) => {
  954. process.nextTick(() => {
  955. let result = {
  956. main: null,
  957. cores: [],
  958. max: null,
  959. socket: [],
  960. chipset: null
  961. };
  962. if (_linux) {
  963. // CPU Chipset, Socket
  964. try {
  965. const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;';
  966. const parts = execSync(cmd).toString().split('-----\n');
  967. if (parts.length === 2) {
  968. const lines = parts[0].split('\n');
  969. const lines2 = parts[1].split('\n');
  970. for (let i = 0; i < lines.length; i++) {
  971. const line = lines[i].trim();
  972. if (line.startsWith('acpi') && lines2[i]) {
  973. result.socket.push(Math.round(parseInt(lines2[i], 10) / 100) / 10);
  974. }
  975. if (line.startsWith('pch') && lines2[i]) {
  976. result.chipset = Math.round(parseInt(lines2[i], 10) / 100) / 10;
  977. }
  978. }
  979. }
  980. } catch (e) {
  981. util.noop();
  982. }
  983. const cmd = 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=$(echo $label | rev | cut -c 7- | rev)_input; if [ -f "$value" ]; then echo $(cat "$label")___$(cat "$value"); fi; fi; done; done;';
  984. try {
  985. exec(cmd, function (error, stdout) {
  986. stdout = stdout.toString();
  987. const tdiePos = stdout.toLowerCase().indexOf('tdie');
  988. if (tdiePos !== -1) {
  989. stdout = stdout.substring(tdiePos);
  990. }
  991. let lines = stdout.split('\n');
  992. lines.forEach(line => {
  993. const parts = line.split('___');
  994. const label = parts[0];
  995. const value = parts.length > 1 && parts[1] ? parts[1] : '0';
  996. if (value && (label === undefined || (label && label.toLowerCase().startsWith('core')))) {
  997. result.cores.push(Math.round(parseInt(value, 10) / 100) / 10);
  998. } else if (value && label && result.main === null) {
  999. result.main = Math.round(parseInt(value, 10) / 100) / 10;
  1000. }
  1001. });
  1002. if (result.cores.length > 0) {
  1003. if (result.main === null) {
  1004. result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
  1005. }
  1006. let maxtmp = Math.max.apply(Math, result.cores);
  1007. result.max = (maxtmp > result.main) ? maxtmp : result.main;
  1008. }
  1009. if (result.main !== null) {
  1010. if (result.max === null) {
  1011. result.max = result.main;
  1012. }
  1013. if (callback) { callback(result); }
  1014. resolve(result);
  1015. return;
  1016. }
  1017. exec('sensors', function (error, stdout) {
  1018. if (!error) {
  1019. let lines = stdout.toString().split('\n');
  1020. let tdieTemp = null;
  1021. let newSectionStarts = true;
  1022. let section = '';
  1023. lines.forEach(function (line) {
  1024. // determine section
  1025. if (line.trim() === '') {
  1026. newSectionStarts = true;
  1027. } else if (newSectionStarts) {
  1028. if (line.trim().toLowerCase().startsWith('acpi')) { section = 'acpi'; }
  1029. if (line.trim().toLowerCase().startsWith('pch')) { section = 'pch'; }
  1030. if (line.trim().toLowerCase().startsWith('core')) { section = 'core'; }
  1031. newSectionStarts = false;
  1032. }
  1033. let regex = /[+-]([^°]*)/g;
  1034. let temps = line.match(regex);
  1035. let firstPart = line.split(':')[0].toUpperCase();
  1036. if (section === 'acpi') {
  1037. // socket temp
  1038. if (firstPart.indexOf('TEMP') !== -1) {
  1039. result.socket.push(parseFloat(temps));
  1040. }
  1041. } else if (section === 'pch') {
  1042. // chipset temp
  1043. if (firstPart.indexOf('TEMP') !== -1) {
  1044. result.chipset = parseFloat(temps);
  1045. }
  1046. }
  1047. // cpu temp
  1048. if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
  1049. result.main = parseFloat(temps);
  1050. }
  1051. if (firstPart.indexOf('CORE ') !== -1) {
  1052. result.cores.push(parseFloat(temps));
  1053. }
  1054. if (firstPart.indexOf('TDIE') !== -1 && tdieTemp === null) {
  1055. tdieTemp = parseFloat(temps);
  1056. }
  1057. });
  1058. if (result.cores.length > 0) {
  1059. if (result.main === null) {
  1060. result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
  1061. }
  1062. let maxtmp = Math.max.apply(Math, result.cores);
  1063. result.max = (maxtmp > result.main) ? maxtmp : result.main;
  1064. } else {
  1065. if (result.main === null && tdieTemp !== null) {
  1066. result.main = tdieTemp;
  1067. result.max = tdieTemp;
  1068. }
  1069. }
  1070. if (result.main !== null || result.max !== null) {
  1071. if (callback) { callback(result); }
  1072. resolve(result);
  1073. return;
  1074. }
  1075. }
  1076. fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
  1077. if (err === null) {
  1078. fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
  1079. if (!error) {
  1080. let lines = stdout.toString().split('\n');
  1081. if (lines.length > 0) {
  1082. result.main = parseFloat(lines[0]) / 1000.0;
  1083. result.max = result.main;
  1084. }
  1085. }
  1086. if (callback) { callback(result); }
  1087. resolve(result);
  1088. });
  1089. } else {
  1090. exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
  1091. if (!error) {
  1092. let lines = stdout.toString().split('\n');
  1093. if (lines.length > 0 && lines[0].indexOf('=')) {
  1094. result.main = parseFloat(lines[0].split('=')[1]);
  1095. result.max = result.main;
  1096. }
  1097. }
  1098. if (callback) { callback(result); }
  1099. resolve(result);
  1100. });
  1101. }
  1102. });
  1103. });
  1104. });
  1105. } catch (er) {
  1106. if (callback) { callback(result); }
  1107. resolve(result);
  1108. }
  1109. }
  1110. if (_freebsd || _openbsd || _netbsd) {
  1111. exec('sysctl dev.cpu | grep temp', function (error, stdout) {
  1112. if (!error) {
  1113. let lines = stdout.toString().split('\n');
  1114. let sum = 0;
  1115. lines.forEach(function (line) {
  1116. const parts = line.split(':');
  1117. if (parts.length > 1) {
  1118. const temp = parseFloat(parts[1].replace(',', '.'));
  1119. if (temp > result.max) { result.max = temp; }
  1120. sum = sum + temp;
  1121. result.cores.push(temp);
  1122. }
  1123. });
  1124. if (result.cores.length) {
  1125. result.main = Math.round(sum / result.cores.length * 100) / 100;
  1126. }
  1127. }
  1128. if (callback) { callback(result); }
  1129. resolve(result);
  1130. });
  1131. }
  1132. if (_darwin) {
  1133. let osxTemp = null;
  1134. try {
  1135. osxTemp = require('osx-temperature-sensor');
  1136. } catch (er) {
  1137. osxTemp = null;
  1138. }
  1139. if (osxTemp) {
  1140. result = osxTemp.cpuTemperature();
  1141. }
  1142. if (callback) { callback(result); }
  1143. resolve(result);
  1144. }
  1145. if (_sunos) {
  1146. if (callback) { callback(result); }
  1147. resolve(result);
  1148. }
  1149. if (_windows) {
  1150. try {
  1151. util.powerShell('Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | Select CurrentTemperature').then((stdout, error) => {
  1152. if (!error) {
  1153. let sum = 0;
  1154. let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
  1155. lines.forEach(function (line) {
  1156. let value = (parseInt(line, 10) - 2732) / 10;
  1157. if (!isNaN(value)) {
  1158. sum = sum + value;
  1159. if (value > result.max) { result.max = value; }
  1160. result.cores.push(value);
  1161. }
  1162. });
  1163. if (result.cores.length) {
  1164. result.main = sum / result.cores.length;
  1165. }
  1166. }
  1167. if (callback) { callback(result); }
  1168. resolve(result);
  1169. });
  1170. } catch (e) {
  1171. if (callback) { callback(result); }
  1172. resolve(result);
  1173. }
  1174. }
  1175. });
  1176. });
  1177. }
  1178. exports.cpuTemperature = cpuTemperature;
  1179. // --------------------------
  1180. // CPU Flags
  1181. function cpuFlags(callback) {
  1182. return new Promise((resolve) => {
  1183. process.nextTick(() => {
  1184. let result = '';
  1185. if (_windows) {
  1186. try {
  1187. exec('reg query "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" /v FeatureSet', util.execOptsWin, function (error, stdout) {
  1188. if (!error) {
  1189. let flag_hex = stdout.split('0x').pop().trim();
  1190. let flag_bin_unpadded = parseInt(flag_hex, 16).toString(2);
  1191. let flag_bin = '0'.repeat(32 - flag_bin_unpadded.length) + flag_bin_unpadded;
  1192. // empty flags are the reserved fields in the CPUID feature bit list
  1193. // as found on wikipedia:
  1194. // https://en.wikipedia.org/wiki/CPUID
  1195. let all_flags = [
  1196. 'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic',
  1197. '', 'sep', 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse-36', 'psn', 'clfsh',
  1198. '', 'ds', 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'htt', 'tm', 'ia64', 'pbe'
  1199. ];
  1200. for (let f = 0; f < all_flags.length; f++) {
  1201. if (flag_bin[f] === '1' && all_flags[f] !== '') {
  1202. result += ' ' + all_flags[f];
  1203. }
  1204. }
  1205. result = result.trim().toLowerCase();
  1206. }
  1207. if (callback) { callback(result); }
  1208. resolve(result);
  1209. });
  1210. } catch (e) {
  1211. if (callback) { callback(result); }
  1212. resolve(result);
  1213. }
  1214. }
  1215. if (_linux) {
  1216. try {
  1217. exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
  1218. if (!error) {
  1219. let lines = stdout.toString().split('\n');
  1220. lines.forEach(function (line) {
  1221. if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
  1222. result = line.split(':')[1].trim().toLowerCase();
  1223. }
  1224. });
  1225. }
  1226. if (!result) {
  1227. fs.readFile('/proc/cpuinfo', function (error, stdout) {
  1228. if (!error) {
  1229. let lines = stdout.toString().split('\n');
  1230. result = util.getValue(lines, 'features', ':', true).toLowerCase();
  1231. }
  1232. if (callback) { callback(result); }
  1233. resolve(result);
  1234. });
  1235. } else {
  1236. if (callback) { callback(result); }
  1237. resolve(result);
  1238. }
  1239. });
  1240. } catch (e) {
  1241. if (callback) { callback(result); }
  1242. resolve(result);
  1243. }
  1244. }
  1245. if (_freebsd || _openbsd || _netbsd) {
  1246. exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; unset LC_ALL', function (error, stdout) {
  1247. let flags = [];
  1248. if (!error) {
  1249. let parts = stdout.toString().split('\tFlags:');
  1250. const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split('\n') : [];
  1251. lines.forEach(function (line) {
  1252. let flag = (line.indexOf('(') ? line.split('(')[0].toLowerCase() : '').trim().replace(/\t/g, '');
  1253. if (flag) {
  1254. flags.push(flag);
  1255. }
  1256. });
  1257. }
  1258. result = flags.join(' ').trim().toLowerCase();
  1259. if (callback) { callback(result); }
  1260. resolve(result);
  1261. });
  1262. }
  1263. if (_darwin) {
  1264. exec('sysctl machdep.cpu.features', function (error, stdout) {
  1265. if (!error) {
  1266. let lines = stdout.toString().split('\n');
  1267. if (lines.length > 0 && lines[0].indexOf('machdep.cpu.features:') !== -1) {
  1268. result = lines[0].split(':')[1].trim().toLowerCase();
  1269. }
  1270. }
  1271. if (callback) { callback(result); }
  1272. resolve(result);
  1273. });
  1274. }
  1275. if (_sunos) {
  1276. if (callback) { callback(result); }
  1277. resolve(result);
  1278. }
  1279. });
  1280. });
  1281. }
  1282. exports.cpuFlags = cpuFlags;
  1283. // --------------------------
  1284. // CPU Cache
  1285. function cpuCache(callback) {
  1286. return new Promise((resolve) => {
  1287. process.nextTick(() => {
  1288. let result = {
  1289. l1d: null,
  1290. l1i: null,
  1291. l2: null,
  1292. l3: null,
  1293. };
  1294. if (_linux) {
  1295. try {
  1296. exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
  1297. if (!error) {
  1298. let lines = stdout.toString().split('\n');
  1299. lines.forEach(function (line) {
  1300. let parts = line.split(':');
  1301. if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
  1302. result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
  1303. }
  1304. if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
  1305. result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
  1306. }
  1307. if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
  1308. result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
  1309. }
  1310. if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
  1311. result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : (parts[1].indexOf('K') !== -1 ? 1024 : 1));
  1312. }
  1313. });
  1314. }
  1315. if (callback) { callback(result); }
  1316. resolve(result);
  1317. });
  1318. } catch (e) {
  1319. if (callback) { callback(result); }
  1320. resolve(result);
  1321. }
  1322. }
  1323. if (_freebsd || _openbsd || _netbsd) {
  1324. exec('export LC_ALL=C; dmidecode -t 7 2>/dev/null; unset LC_ALL', function (error, stdout) {
  1325. let cache = [];
  1326. if (!error) {
  1327. const data = stdout.toString();
  1328. cache = data.split('Cache Information');
  1329. cache.shift();
  1330. }
  1331. for (let i = 0; i < cache.length; i++) {
  1332. const lines = cache[i].split('\n');
  1333. let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
  1334. cacheType = cacheType.length ? cacheType[0] : '';
  1335. const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
  1336. let size = parseInt(sizeParts[0], 10);
  1337. const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
  1338. size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
  1339. if (cacheType) {
  1340. if (cacheType === 'l1') {
  1341. result.cache[cacheType + 'd'] = size / 2;
  1342. result.cache[cacheType + 'i'] = size / 2;
  1343. } else {
  1344. result.cache[cacheType] = size;
  1345. }
  1346. }
  1347. }
  1348. if (callback) { callback(result); }
  1349. resolve(result);
  1350. });
  1351. }
  1352. if (_darwin) {
  1353. exec('sysctl hw.l1icachesize hw.l1dcachesize hw.l2cachesize hw.l3cachesize', function (error, stdout) {
  1354. if (!error) {
  1355. let lines = stdout.toString().split('\n');
  1356. lines.forEach(function (line) {
  1357. let parts = line.split(':');
  1358. if (parts[0].toLowerCase().indexOf('hw.l1icachesize') !== -1) {
  1359. result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
  1360. }
  1361. if (parts[0].toLowerCase().indexOf('hw.l1dcachesize') !== -1) {
  1362. result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
  1363. }
  1364. if (parts[0].toLowerCase().indexOf('hw.l2cachesize') !== -1) {
  1365. result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
  1366. }
  1367. if (parts[0].toLowerCase().indexOf('hw.l3cachesize') !== -1) {
  1368. result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
  1369. }
  1370. });
  1371. }
  1372. if (callback) { callback(result); }
  1373. resolve(result);
  1374. });
  1375. }
  1376. if (_sunos) {
  1377. if (callback) { callback(result); }
  1378. resolve(result);
  1379. }
  1380. if (_windows) {
  1381. try {
  1382. util.powerShell('Get-WmiObject Win32_processor | select L2CacheSize, L3CacheSize | fl').then((stdout, error) => {
  1383. if (!error) {
  1384. let lines = stdout.split('\r\n');
  1385. result.l1d = 0;
  1386. result.l1i = 0;
  1387. result.l2 = util.getValue(lines, 'l2cachesize', ':');
  1388. result.l3 = util.getValue(lines, 'l3cachesize', ':');
  1389. if (result.l2) { result.l2 = parseInt(result.l2, 10) * 1024; }
  1390. if (result.l3) { result.l3 = parseInt(result.l3, 10) * 1024; }
  1391. }
  1392. util.powerShell('Get-WmiObject Win32_CacheMemory | select CacheType,InstalledSize,Level | fl').then((stdout, error) => {
  1393. if (!error) {
  1394. const parts = stdout.split(/\n\s*\n/);
  1395. parts.forEach(function (part) {
  1396. const lines = part.split('\r\n');
  1397. const cacheType = util.getValue(lines, 'CacheType');
  1398. const level = util.getValue(lines, 'Level');
  1399. const installedSize = util.getValue(lines, 'InstalledSize');
  1400. // L1 Instructions
  1401. if (level === '3' && cacheType === '3') {
  1402. result.l1i = parseInt(installedSize, 10);
  1403. }
  1404. // L1 Data
  1405. if (level === '3' && cacheType === '4') {
  1406. result.l1d = parseInt(installedSize, 10);
  1407. }
  1408. // L1 all
  1409. if (level === '3' && cacheType === '5' && !result.l1i && !result.l1d) {
  1410. result.l1i = parseInt(installedSize, 10) / 2;
  1411. result.l1d = parseInt(installedSize, 10) / 2;
  1412. }
  1413. });
  1414. }
  1415. if (callback) { callback(result); }
  1416. resolve(result);
  1417. });
  1418. });
  1419. } catch (e) {
  1420. if (callback) { callback(result); }
  1421. resolve(result);
  1422. }
  1423. }
  1424. });
  1425. });
  1426. }
  1427. exports.cpuCache = cpuCache;
  1428. // --------------------------
  1429. // CPU - current load - in %
  1430. function getLoad() {
  1431. return new Promise((resolve) => {
  1432. process.nextTick(() => {
  1433. let loads = os.loadavg().map(function (x) { return x / util.cores(); });
  1434. let avgLoad = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
  1435. let result = {};
  1436. let now = Date.now() - _current_cpu.ms;
  1437. if (now >= 200) {
  1438. _current_cpu.ms = Date.now();
  1439. const cpus = os.cpus();
  1440. let totalUser = 0;
  1441. let totalSystem = 0;
  1442. let totalNice = 0;
  1443. let totalIrq = 0;
  1444. let totalIdle = 0;
  1445. let cores = [];
  1446. _corecount = (cpus && cpus.length) ? cpus.length : 0;
  1447. for (let i = 0; i < _corecount; i++) {
  1448. const cpu = cpus[i].times;
  1449. totalUser += cpu.user;
  1450. totalSystem += cpu.sys;
  1451. totalNice += cpu.nice;
  1452. totalIdle += cpu.idle;
  1453. totalIrq += cpu.irq;
  1454. let tmpTick = (_cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0);
  1455. let tmpLoad = (_cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0);
  1456. let tmpUser = (_cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0);
  1457. let tmpSystem = (_cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0);
  1458. let tmpNice = (_cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0);
  1459. let tmpIdle = (_cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0);
  1460. let tmpIrq = (_cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0);
  1461. _cpus[i] = cpu;
  1462. _cpus[i].totalTick = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].idle;
  1463. _cpus[i].totalLoad = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq;
  1464. _cpus[i].currentTick = _cpus[i].totalTick - tmpTick;
  1465. _cpus[i].load = (_cpus[i].totalLoad - tmpLoad);
  1466. _cpus[i].loadUser = (_cpus[i].user - tmpUser);
  1467. _cpus[i].loadSystem = (_cpus[i].sys - tmpSystem);
  1468. _cpus[i].loadNice = (_cpus[i].nice - tmpNice);
  1469. _cpus[i].loadIdle = (_cpus[i].idle - tmpIdle);
  1470. _cpus[i].loadIrq = (_cpus[i].irq - tmpIrq);
  1471. cores[i] = {};
  1472. cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
  1473. cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
  1474. cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
  1475. cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
  1476. cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
  1477. cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
  1478. cores[i].rawLoad = _cpus[i].load;
  1479. cores[i].rawLoadUser = _cpus[i].loadUser;
  1480. cores[i].rawLoadSystem = _cpus[i].loadSystem;
  1481. cores[i].rawLoadNice = _cpus[i].loadNice;
  1482. cores[i].rawLoadIdle = _cpus[i].loadIdle;
  1483. cores[i].rawLoadIrq = _cpus[i].loadIrq;
  1484. }
  1485. let totalTick = totalUser + totalSystem + totalNice + totalIrq + totalIdle;
  1486. let totalLoad = totalUser + totalSystem + totalNice + totalIrq;
  1487. let currentTick = totalTick - _current_cpu.tick;
  1488. result = {
  1489. avgLoad: avgLoad,
  1490. currentLoad: (totalLoad - _current_cpu.load) / currentTick * 100,
  1491. currentLoadUser: (totalUser - _current_cpu.user) / currentTick * 100,
  1492. currentLoadSystem: (totalSystem - _current_cpu.system) / currentTick * 100,
  1493. currentLoadNice: (totalNice - _current_cpu.nice) / currentTick * 100,
  1494. currentLoadIdle: (totalIdle - _current_cpu.idle) / currentTick * 100,
  1495. currentLoadIrq: (totalIrq - _current_cpu.irq) / currentTick * 100,
  1496. rawCurrentLoad: (totalLoad - _current_cpu.load),
  1497. rawCurrentLoadUser: (totalUser - _current_cpu.user),
  1498. rawCurrentLoadSystem: (totalSystem - _current_cpu.system),
  1499. rawCurrentLoadNice: (totalNice - _current_cpu.nice),
  1500. rawCurrentLoadIdle: (totalIdle - _current_cpu.idle),
  1501. rawCurrentLoadIrq: (totalIrq - _current_cpu.irq),
  1502. cpus: cores
  1503. };
  1504. _current_cpu = {
  1505. user: totalUser,
  1506. nice: totalNice,
  1507. system: totalSystem,
  1508. idle: totalIdle,
  1509. irq: totalIrq,
  1510. tick: totalTick,
  1511. load: totalLoad,
  1512. ms: _current_cpu.ms,
  1513. currentLoad: result.currentLoad,
  1514. currentLoadUser: result.currentLoadUser,
  1515. currentLoadSystem: result.currentLoadSystem,
  1516. currentLoadNice: result.currentLoadNice,
  1517. currentLoadIdle: result.currentLoadIdle,
  1518. currentLoadIrq: result.currentLoadIrq,
  1519. rawCurrentLoad: result.rawCurrentLoad,
  1520. rawCurrentLoadUser: result.rawCurrentLoadUser,
  1521. rawCurrentLoadSystem: result.rawCurrentLoadSystem,
  1522. rawCurrentLoadNice: result.rawCurrentLoadNice,
  1523. rawCurrentLoadIdle: result.rawCurrentLoadIdle,
  1524. rawCurrentLoadIrq: result.rawCurrentLoadIrq,
  1525. };
  1526. } else {
  1527. let cores = [];
  1528. for (let i = 0; i < _corecount; i++) {
  1529. cores[i] = {};
  1530. cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100;
  1531. cores[i].loadUser = _cpus[i].loadUser / _cpus[i].currentTick * 100;
  1532. cores[i].loadSystem = _cpus[i].loadSystem / _cpus[i].currentTick * 100;
  1533. cores[i].loadNice = _cpus[i].loadNice / _cpus[i].currentTick * 100;
  1534. cores[i].loadIdle = _cpus[i].loadIdle / _cpus[i].currentTick * 100;
  1535. cores[i].loadIrq = _cpus[i].loadIrq / _cpus[i].currentTick * 100;
  1536. cores[i].rawLoad = _cpus[i].load;
  1537. cores[i].rawLoadUser = _cpus[i].loadUser;
  1538. cores[i].rawLoadSystem = _cpus[i].loadSystem;
  1539. cores[i].rawLoadNice = _cpus[i].loadNice;
  1540. cores[i].rawLoadIdle = _cpus[i].loadIdle;
  1541. cores[i].rawLoadIrq = _cpus[i].loadIrq;
  1542. }
  1543. result = {
  1544. avgLoad: avgLoad,
  1545. currentLoad: _current_cpu.currentLoad,
  1546. currentLoadUser: _current_cpu.currentLoadUser,
  1547. currentLoadSystem: _current_cpu.currentLoadSystem,
  1548. currentLoadNice: _current_cpu.currentLoadNice,
  1549. currentLoadIdle: _current_cpu.currentLoadIdle,
  1550. currentLoadIrq: _current_cpu.currentLoadIrq,
  1551. rawCurrentLoad: _current_cpu.rawCurrentLoad,
  1552. rawCurrentLoadUser: _current_cpu.rawCurrentLoadUser,
  1553. rawCurrentLoadSystem: _current_cpu.rawCurrentLoadSystem,
  1554. rawCurrentLoadNice: _current_cpu.rawCurrentLoadNice,
  1555. rawCurrentLoadIdle: _current_cpu.rawCurrentLoadIdle,
  1556. rawCurrentLoadIrq: _current_cpu.rawCurrentLoadIrq,
  1557. cpus: cores
  1558. };
  1559. }
  1560. resolve(result);
  1561. });
  1562. });
  1563. }
  1564. function currentLoad(callback) {
  1565. return new Promise((resolve) => {
  1566. process.nextTick(() => {
  1567. getLoad().then(result => {
  1568. if (callback) { callback(result); }
  1569. resolve(result);
  1570. });
  1571. });
  1572. });
  1573. }
  1574. exports.currentLoad = currentLoad;
  1575. // --------------------------
  1576. // PS - full load
  1577. // since bootup
  1578. function getFullLoad() {
  1579. return new Promise((resolve) => {
  1580. process.nextTick(() => {
  1581. const cpus = os.cpus();
  1582. let totalUser = 0;
  1583. let totalSystem = 0;
  1584. let totalNice = 0;
  1585. let totalIrq = 0;
  1586. let totalIdle = 0;
  1587. let result = 0;
  1588. if (cpus && cpus.length) {
  1589. for (let i = 0, len = cpus.length; i < len; i++) {
  1590. const cpu = cpus[i].times;
  1591. totalUser += cpu.user;
  1592. totalSystem += cpu.sys;
  1593. totalNice += cpu.nice;
  1594. totalIrq += cpu.irq;
  1595. totalIdle += cpu.idle;
  1596. }
  1597. let totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser;
  1598. result = (totalTicks - totalIdle) / totalTicks * 100.0;
  1599. } else {
  1600. result = 0;
  1601. }
  1602. resolve(result);
  1603. });
  1604. });
  1605. }
  1606. function fullLoad(callback) {
  1607. return new Promise((resolve) => {
  1608. process.nextTick(() => {
  1609. getFullLoad().then(result => {
  1610. if (callback) { callback(result); }
  1611. resolve(result);
  1612. });
  1613. });
  1614. });
  1615. }
  1616. exports.fullLoad = fullLoad;