Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2. $cat = 'mem';
  3.  
  4. $meminfo_file = '/proc/meminfo';
  5. $meminfo_content = file($meminfo_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  6. $meminfo_metrics = array(
  7. 'MemTotal' => 'memtotal',
  8. 'MemFree' => 'memfree',
  9. 'Buffers' => 'buffers',
  10. 'Cached' => 'cached',
  11. 'SwapCached' => 'swapcached',
  12. 'SwapTotal' => 'swaptotal',
  13. 'SwapFree' => 'swapfree',
  14. 'Dirty' => 'dirty',
  15. 'Slab' => 'slab',
  16. );
  17. $meminfo_o = array();
  18.  
  19. foreach ($meminfo_content as $m) {
  20. $value = array();
  21. foreach ($meminfo_metrics as $metric => $name) {
  22. if (preg_match("/^$metric:\s+(\d+) .*/", $m, $value)) {
  23. $meminfo_o["$cat.$name"] = $value[1];
  24. break;
  25. }
  26. }
  27. }
  28.  
  29. var_dump($meminfo_o);
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement