Returns (total, used) memory on system, in GB. Used is computed as total - available. Calls "free" and parses output. Sample output for reference: total used free shared buffers cache available Mem: 126747197440 26363965440 56618553344 31
()
| 58 | |
| 59 | |
| 60 | def _memory(): |
| 61 | """Returns (total, used) memory on system, in GB. |
| 62 | |
| 63 | Used is computed as total - available. |
| 64 | |
| 65 | Calls "free" and parses output. Sample output for reference: |
| 66 | |
| 67 | total used free shared buffers cache available |
| 68 | Mem: 126747197440 26363965440 56618553344 31678464 2091614208 41673064448 99384889344 |
| 69 | Swap: 0 0 0 |
| 70 | """ |
| 71 | |
| 72 | free_lines = subprocess.check_output(["free", "-b", "-w"], |
| 73 | universal_newlines=True).split('\n') |
| 74 | free_grid = [x.split() for x in free_lines] |
| 75 | # Identify columns for "total" and "available" |
| 76 | total_idx = free_grid[0].index("total") |
| 77 | available_idx = free_grid[0].index("available") |
| 78 | total = int(free_grid[1][1 + total_idx]) |
| 79 | available = int(free_grid[1][1 + available_idx]) |
| 80 | used = total - available |
| 81 | total_gb = total / (1024.0 * 1024.0 * 1024.0) |
| 82 | used_gb = used / (1024.0 * 1024.0 * 1024.0) |
| 83 | return (total_gb, used_gb) |
| 84 | |
| 85 | |
| 86 | def datetime_to_seconds_since_epoch(dt): |
no test coverage detected