Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $cat = 'mem';
- $meminfo_file = '/proc/meminfo';
- $meminfo_content = file($meminfo_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- $meminfo_metrics = array(
- 'MemTotal' => 'memtotal',
- 'MemFree' => 'memfree',
- 'Buffers' => 'buffers',
- 'Cached' => 'cached',
- 'SwapCached' => 'swapcached',
- 'SwapTotal' => 'swaptotal',
- 'SwapFree' => 'swapfree',
- 'Dirty' => 'dirty',
- 'Slab' => 'slab',
- );
- $meminfo_o = array();
- foreach ($meminfo_content as $m) {
- $value = array();
- foreach ($meminfo_metrics as $metric => $name) {
- if (preg_match("/^$metric:\s+(\d+) .*/", $m, $value)) {
- $meminfo_o["$cat.$name"] = $value[1];
- break;
- }
- }
- }
- var_dump($meminfo_o);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement