comparison main.cpp @ 0:bb144f2c5a3b

initial commit
author Yasuri <yasuri@charliesmp.net>
date Sun, 04 Oct 2026 13:36:00 -0500
parents
children 841975e638f2
comparison
equal deleted inserted replaced
-1:000000000000 0:bb144f2c5a3b
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <iomanip>
5 int main() {
6 std::string myText;
7 std::ifstream Meminfo("/proc/meminfo");
8 std::string uptimeText;
9 std::ifstream Uptime("/proc/uptime");
10 std::string distro;
11 std::ifstream OsRelease("/etc/os-release");
12 long total = 0;
13 long available = 0;
14 while (std::getline (Meminfo, myText)) {
15 std::istringstream ss(myText);
16 std::string name;
17 long value;
18 ss >> name >> value;
19 if (name == "MemTotal:") {
20 total = value;
21 }
22 if (name == "MemAvailable:") {
23 available = value;
24 }
25 }
26 std::string osLine;
27 while (std::getline(OsRelease, osLine)) {
28 size_t pos = osLine.find('=');
29 if (pos == std::string::npos) continue;
30 std::string key = osLine.substr(0, pos);
31 std::string val = osLine.substr(pos + 1);
32 if (key == "PRETTY_NAME") {
33 distro = val.substr(1, val.size() - 2);
34 }
35 }
36 long timeup = 0;
37 while (std::getline (Uptime, uptimeText)) {
38 std::istringstream ss2(uptimeText);
39 double uptime;
40 ss2 >> uptime;
41 timeup = uptime;
42 }
43 std::cout << std::fixed << std::setprecision(2);
44 std::cout << "Used: " << (total - available) / (1024.0 * 1024.0) << " GB" << "/" << total / (1024.0 * 1024.0) << "GB" << std::endl;
45 std::cout << "Uptime: " << "Hours: " << timeup / 3600 << " Minutes: " << (timeup % 3600) / 60 << std::endl;
46 std::cout << "OS: " << distro << std::endl;
47 Meminfo.close();
48 }