{"action":"opened","issue":{"url":"https://api.github.com/repos/Monitorr/Monitorr/issues/193","repository_url":"https://api.github.com/repos/Monitorr/Monitorr","labels_url":"https://api.github.com/repos/Monitorr/Monitorr/issues/193/labels{/name}","comments_url":"https://api.github.com/repos/Monitorr/Monitorr/issues/193/comments","events_url":"https://api.github.com/repos/Monitorr/Monitorr/issues/193/events","html_url":"https://github.com/Monitorr/Monitorr/issues/193","id":381741943,"node_id":"MDU6SXNzdWUzODE3NDE5NDM=","number":193,"title":"macOS Mojave 'stats' are broken","user":{"login":"Archigos","id":891049,"node_id":"MDQ6VXNlcjg5MTA0OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/891049?v=4","gravatar_id":"","url":"https://api.github.com/users/Archigos","html_url":"https://github.com/Archigos","followers_url":"https://api.github.com/users/Archigos/followers","following_url":"https://api.github.com/users/Archigos/following{/other_user}","gists_url":"https://api.github.com/users/Archigos/gists{/gist_id}","starred_url":"https://api.github.com/users/Archigos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Archigos/subscriptions","organizations_url":"https://api.github.com/users/Archigos/orgs","repos_url":"https://api.github.com/users/Archigos/repos","events_url":"https://api.github.com/users/Archigos/events{/privacy}","received_events_url":"https://api.github.com/users/Archigos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-16T20:06:04Z","updated_at":"2018-11-16T20:06:04Z","closed_at":null,"author_association":"NONE","body":"## Your environment:\r\n- **Operating system**: macOS Mojave (10.14)\r\n- **Webserver**:             Apache 2.4.34\r\n- **PHP Version**:          7.1.19 x64 NTS\r\n- **Monitorr Version**:   1.7.7d\r\n\r\n## Describe your issue:\r\n\r\nThis information isn't on the Wiki and I attempted to talk about this in Discord. (John told me to make this Issue). Monitorr stats do not work on macOS Mojave so I managed to alter the code and get most of the stats working. These first two screenshots show the error messages you'll get running it on Mojave before code changes.\r\n![image](https://user-images.githubusercontent.com/891049/48642213-2e948e80-e9aa-11e8-8988-ed326b18c48e.png)\r\n![image](https://user-images.githubusercontent.com/891049/48642233-35bb9c80-e9aa-11e8-8c58-486b2827d5d6.png)\r\n\r\nWhile messing with the code, I posted the following screenshot showing that I managed to fix both Uptime and CPU%. In the screenshot itself, I just faked the RAM to get rid of the error.\r\n![image](https://user-images.githubusercontent.com/891049/48642290-73b8c080-e9aa-11e8-99da-873059349177.png)\r\nAs you can see, the uptime is in a slightly different format (Mojave uptime gives a string similar to: `14:20  up 2 days, 10:39, 3 users, load averages: 10.05 11.16 10.82` {Current Time, Uptime, User Count, etc.} They don't provide seconds so I tweaked it.\r\n\r\nAfter that screenshot, I managed to get the RAM more accurate by getting currently used memory and hard coding the total memory since I couldn't figure out a way to pull that and wanted to still give an accurate percent.\r\n\r\n\r\nI'm not exactly sure of line numbers to reference since I was moving stuff around a bit while editing, but around line 425? in functions.php in regards to Uptime, I assume you'll have to do a system check, but when you determine it's a Mac, change the following:\r\n```$uptime = shell_exec(\"cut -d. -f1 /proc/uptime\");\r\n$days = floor($uptime) / 60 / 60 / 24;\r\n$days_padded = sprintf(\"%02d\", $days);\r\n$hours = round($uptime) / 60 / 60 % 24;\r\n$hours_padded = sprintf(\"%02d\", $hours);\r\n$mins = round($uptime) / 60 % 60;\r\n$mins_padded = sprintf(\"%02d\", $mins);\r\n$secs = round($uptime) % 60;\r\n$secs_padded = sprintf(\"%02d\", $secs);\r\n$total_uptime = \"$days_padded:$hours_padded:$mins_padded:$secs_padded\";\r\n```\r\nto:\r\n```\r\n$uptime       = preg_split(\"/[\\s]+/\", trim(shell_exec('uptime')));\r\n$days         = $uptime[2];\r\n$days_padded  = sprintf(\"%02d\", $days);\r\n$uptime_time  = explode(\":\", $uptime[4]);\r\n$hours        = $uptime_time[0];\r\n$hours_padded = sprintf(\"%02d\", $hours);\r\n$mins         = $uptime_time[1];\r\n$mins_padded  = sprintf(\"%02d\", $mins);\r\n$total_uptime = \"{$days_padded}d:{$hours_padded}h:{$mins_padded}m\";\r\n```\r\n\r\nFor CPU:\r\nInstead of calling `getServerLoad()` (around line 160)\r\nYour two line:\r\n```\r\n$cpuLoad = getServerLoad();\r\n$cpuPercent = round($cpuLoad, 2);\r\n```\r\nIgnore that function and do:\r\n```\r\n$exec_loads = sys_getloadavg();\r\n$exec_cores = trim(shell_exec(\"grep -P '^processor' /proc/cpuinfo | wc -l\"));\r\n$cpuPercent = round($exec_loads[1] / ($exec_cores + 1), 0);\r\n```\r\n\r\nFor RAM, as of now, best I could do was hard code total memory:\r\n```\r\nfunction getRamTotal()\r\n{\r\n  $result = 0;\r\n  if(PHP_OS == 'WINNT')\r\n  {\r\n  ...... // a few lines of code\r\n  } else {\r\n    return 40 * 1024;  // My system has 40GB\r\n    $fh = fopen('/proc/meminfo', 'r');\r\n    .... // rest of your function\r\n}\r\n```\r\nIn `getRamFree()`, again inside the 'else' from the systetem detect:\r\n```\r\nif(PHP_OS == 'WINNT')\r\n{\r\n  ... // a few lines of code\r\n} else {\r\n  if($fh = fopen('/proc/meminfo', 'r') !== false)\r\n  {\r\n    ... your code\r\n  } else {\r\n      $memoryFree   = round(memory_get_usage(true) / 1024, 2);\r\n      // sadly while messing around getting this to work, I deleted some of your code, so don't remember\r\n         if you need to return $memoryFree or tweak it for percentage still... I'm sure you'll figure it out.\r\n  }\r\n}\r\n```\r\n\r\nI think that's it, if not, feel free to contact me."}}
{"actor":{"display_login":"Archigos"}}