2019-06-20 12:37:48 +10:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinfo.hpp"
|
|
|
|
|
|
|
|
#include "posix/except.hpp"
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
using cruft::util::sysinfo;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
std::ostream&
|
|
|
|
cruft::util::operator<< (std::ostream &os, sysinfo const &)
|
|
|
|
{
|
|
|
|
os << "{ ";
|
|
|
|
|
|
|
|
{
|
|
|
|
struct utsname name;
|
|
|
|
cruft::posix::error::try_code (uname (&name));
|
|
|
|
|
2019-06-20 14:42:38 +10:00
|
|
|
os << "os: { name: '" << name.sysname << "', version: '" << name.version << "' }"
|
|
|
|
<< ", hostname: '" << name.nodename << '\'';
|
2019-06-20 12:37:48 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto const uid = geteuid ();
|
|
|
|
auto const user = getpwuid (uid);
|
2019-06-20 14:42:38 +10:00
|
|
|
os << ", username: '" << user->pw_name << '\'';
|
2019-06-20 12:37:48 +10:00
|
|
|
}
|
|
|
|
|
2019-06-20 12:46:39 +10:00
|
|
|
{
|
|
|
|
auto const size = posix::error::try_call (sysconf, _SC_PAGESIZE);
|
|
|
|
auto const total = posix::error::try_call (sysconf, _SC_PHYS_PAGES);
|
|
|
|
auto const now = posix::error::try_call (sysconf, _SC_AVPHYS_PAGES);
|
|
|
|
|
|
|
|
os << ", ram: { total: " << size * total << ", available: " << size * now << " },";
|
|
|
|
}
|
|
|
|
|
2019-06-20 12:37:48 +10:00
|
|
|
return os << " }";
|
|
|
|
}
|