zaela-Server/common/serverinfo.cpp

95 lines
2 KiB
C++
Raw Permalink Normal View History

2013-05-09 10:44:08 -04:00
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
2013-02-16 16:14:39 -08:00
2013-05-09 10:44:08 -04:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
2013-02-16 16:14:39 -08:00
2013-05-09 10:44:08 -04:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
2013-02-16 16:14:39 -08:00
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
2013-05-09 10:44:08 -04:00
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
2013-02-16 16:14:39 -08:00
2013-05-09 10:44:08 -04:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2013-02-16 16:14:39 -08:00
*/
2019-04-16 01:09:25 -07:00
#include "serverinfo.h"
#include <uv.h>
size_t EQ::GetRSS()
{
size_t rss = 0;
if (0 != uv_resident_set_memory(&rss)) {
return 0;
2013-02-16 16:14:39 -08:00
}
2019-04-16 01:09:25 -07:00
return rss;
2013-05-06 13:07:41 -04:00
}
2013-02-16 16:14:39 -08:00
2019-04-16 01:09:25 -07:00
double EQ::GetUptime()
{
double uptime = 0.0;
2013-02-16 16:14:39 -08:00
2019-04-16 01:09:25 -07:00
if (0 != uv_uptime(&uptime)) {
return 0.0;
}
return uptime;
}
size_t EQ::GetPID()
{
return uv_os_getpid();
}
2013-05-06 13:07:41 -04:00
2019-04-16 01:09:25 -07:00
std::vector<eq_cpu_info_t> EQ::GetCPUs()
{
std::vector<eq_cpu_info_t> ret;
uv_cpu_info_t *cpu_info = nullptr;
int count = 0;
2013-02-16 16:14:39 -08:00
2019-04-16 01:09:25 -07:00
if (0 != uv_cpu_info(&cpu_info, &count)) {
return ret;
2013-02-16 16:14:39 -08:00
}
2019-04-16 01:09:25 -07:00
ret.reserve(count);
for (int i = 0; i < count; ++i) {
eq_cpu_info_t r;
auto &entry = cpu_info[i];
2013-02-16 16:14:39 -08:00
2019-04-16 01:09:25 -07:00
r.model = entry.model;
r.speed = entry.speed / 1000.0;
r.time_user = entry.cpu_times.user;
r.time_sys = entry.cpu_times.sys;
r.time_idle = entry.cpu_times.idle;
r.time_nice = entry.cpu_times.nice;
r.time_irq = entry.cpu_times.irq;
ret.push_back(r);
}
uv_free_cpu_info(cpu_info, count);
return ret;
2013-02-16 16:14:39 -08:00
}
2019-04-16 01:09:25 -07:00
eq_utsname_t EQ::GetOS()
{
eq_utsname_t ret;
uv_utsname_t name;
if (0 != uv_os_uname(&name)) {
return ret;
}
ret.machine = name.machine;
ret.release = name.release;
ret.sysname = name.sysname;
ret.version = name.version;
return ret;
}