mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
support got uptime and loadavg for osx. 2.0.145
This commit is contained in:
parent
fbd722bf76
commit
f564c903ac
3 changed files with 44 additions and 1 deletions
|
@ -849,10 +849,12 @@ int SrsServer::do_cycle()
|
||||||
srs_info("update memory info, usage/free.");
|
srs_info("update memory info, usage/free.");
|
||||||
srs_update_meminfo();
|
srs_update_meminfo();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if ((i % SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES) == 0) {
|
if ((i % SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES) == 0) {
|
||||||
srs_info("update platform info, uptime/load.");
|
srs_info("update platform info, uptime/load.");
|
||||||
srs_update_platform_info();
|
srs_update_platform_info();
|
||||||
}
|
}
|
||||||
|
#ifndef SRS_OSX
|
||||||
if ((i % SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES) == 0) {
|
if ((i % SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES) == 0) {
|
||||||
srs_info("update network devices info.");
|
srs_info("update network devices info.");
|
||||||
srs_update_network_devices();
|
srs_update_network_devices();
|
||||||
|
|
|
@ -28,6 +28,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#ifdef SRS_OSX
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
|
@ -666,6 +669,7 @@ void srs_update_platform_info()
|
||||||
|
|
||||||
r.srs_startup_time = srs_get_system_startup_time_ms();
|
r.srs_startup_time = srs_get_system_startup_time_ms();
|
||||||
|
|
||||||
|
#ifndef SRS_OSX
|
||||||
if (true) {
|
if (true) {
|
||||||
FILE* f = fopen("/proc/uptime", "r");
|
FILE* f = fopen("/proc/uptime", "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
|
@ -694,6 +698,43 @@ void srs_update_platform_info()
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// man 3 sysctl
|
||||||
|
if (true) {
|
||||||
|
struct timeval tv;
|
||||||
|
size_t len = sizeof(timeval);
|
||||||
|
|
||||||
|
int mib[2];
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_BOOTTIME;
|
||||||
|
if (sysctl(mib, 2, &tv, &len, NULL, 0) < 0) {
|
||||||
|
srs_warn("sysctl boottime failed, ignore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t bsec = tv.tv_sec;
|
||||||
|
time_t csec = ::time(NULL);
|
||||||
|
r.os_uptime = difftime(csec, bsec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// man 3 sysctl
|
||||||
|
if (true) {
|
||||||
|
struct loadavg la;
|
||||||
|
size_t len = sizeof(loadavg);
|
||||||
|
|
||||||
|
int mib[2];
|
||||||
|
mib[0] = CTL_VM;
|
||||||
|
mib[1] = VM_LOADAVG;
|
||||||
|
if (sysctl(mib, 2, &la, &len, NULL, 0) < 0) {
|
||||||
|
srs_warn("sysctl loadavg failed, ignore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.load_one_minutes = (double)la.ldavg[0] / la.fscale;
|
||||||
|
r.load_five_minutes = (double)la.ldavg[1] / la.fscale;
|
||||||
|
r.load_fifteen_minutes = (double)la.ldavg[2] / la.fscale;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
r.ok = true;
|
r.ok = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR 2
|
#define VERSION_MAJOR 2
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 144
|
#define VERSION_REVISION 145
|
||||||
|
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
|
|
Loading…
Reference in a new issue