commit 65e052e14f819574c0289051d746644d0f7cf7f3 Author: okno Date: Thu Apr 9 12:57:15 2026 +0200 Upload files to "/" diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..395aa67 --- /dev/null +++ b/Program.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; + +class Program +{ + static void Main(string[] args) + { + while (true) + { + //int i = 0; + SystemReader systemReader = new SystemReader(); + DriveInfo drive = new DriveInfo("/"); + Console.Clear(); + Console.WriteLine("TThop system stats by RozbitiOkno"); + int processCount = Directory.GetDirectories("/proc") + .Count(dir => int.TryParse(Path.GetFileName(dir), out _)); + Console.WriteLine("\nProcesses: " + processCount); + systemReader.getRam(); + Console.WriteLine("\n--- RAM usage --- --- Disk space ---"); + Console.WriteLine("Total RAM: " + systemReader._totalRam / 1048576 + " GB Total: " + drive.TotalSize / 1073741824 + " GB"); + Console.WriteLine("Availible RAM: " + systemReader._avaibleRam / 1048576 + " GB Free: " + drive.AvailableFreeSpace / 1073741824 + " GB"); + systemReader.getCpuLoad(); + Console.Write("\n--- CPU load ---"); + Console.WriteLine(" --- System uptime ---"); + systemReader._cpuLoad = Math.Round((systemReader._cpuLoad / systemReader.cpuCores) * 100); + if (systemReader._cpuLoad >= 1) { Console.ForegroundColor = ConsoleColor.Green; } + if (systemReader._cpuLoad >= 30) { Console.ForegroundColor = ConsoleColor.DarkGreen; } + if (systemReader._cpuLoad >= 50) { Console.ForegroundColor = ConsoleColor.Yellow; } + if (systemReader._cpuLoad >= 80) { Console.ForegroundColor = ConsoleColor.Red; } + if (systemReader._cpuLoad >= 90) { Console.ForegroundColor = ConsoleColor.DarkRed; } + Console.Write("CPU load: " + systemReader._cpuLoad + "%"); + Console.ResetColor(); + double uptimeSeconds = Math.Round(systemReader.getUptime()); + TimeSpan uptime = TimeSpan.FromSeconds(uptimeSeconds); + Console.ResetColor(); + Console.Write(" " + uptime); + systemReader.getCpuTemp(); + Console.WriteLine("\n\n--- CPU - temp ---"); + Console.Write("CPU temp: " + systemReader._cpuTemp + " °C"); + if (systemReader._cpuTemp == -1) { Console.WriteLine(" - cant get system data (not suported)"); } + else { Console.WriteLine(""); } + Thread.Sleep(1000); + /* while (i < 3) + { + Console.Write("."); + Thread.Sleep(1000); + i++; + }*/ + + continue; + } + + + } + +} + + +//double uptime = systemReader.getUptime(); \ No newline at end of file diff --git a/SystemReader.cs b/SystemReader.cs new file mode 100644 index 0000000..0f7effb --- /dev/null +++ b/SystemReader.cs @@ -0,0 +1,62 @@ +class SystemReader +{ + public int _avaibleRam; + public int _totalRam; + public int getRam() + { + foreach (var line in File.ReadLines("/proc/meminfo")) + { + if (line.StartsWith("MemTotal")) + _totalRam = int.Parse(line.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1]); + + if (line.StartsWith("MemAvailable")) + _avaibleRam = int.Parse(line.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1]); + } + return 0; + } + + + + public double _cpuLoad; + public int cpuCores = Environment.ProcessorCount; + + public double getCpuLoad() + { + if (File.Exists("/proc/loadavg")) + { + string loadStr = File.ReadAllText("/proc/loadavg"); + // první číslo = load za poslední 1 minutu + _cpuLoad = double.Parse(loadStr.Split(' ')[0], System.Globalization.CultureInfo.InvariantCulture); + } + else + { + _cpuLoad = -1; + } + return _cpuLoad; + } + + + public int _cpuTemp; + + public int getCpuTemp() + { + if (File.Exists("/sys/class/thermal/thermal_zone0/temp")) + { + string tempStr = File.ReadAllText("/sys/class/thermal/thermal_zone0/temp"); + _cpuTemp = int.Parse(tempStr) / 1000; // převod na °C + } + else + { + _cpuTemp = -1; // soubor neexistuje + } + return _cpuTemp; + } + + public double getUptime() +{ + string uptime = File.ReadAllText("/proc/uptime").Split(' ')[0]; + return double.Parse(uptime, System.Globalization.CultureInfo.InvariantCulture); +} + +} + diff --git a/tthop.csproj b/tthop.csproj new file mode 100644 index 0000000..ed9781c --- /dev/null +++ b/tthop.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/tthop.sln b/tthop.sln new file mode 100644 index 0000000..cac2582 --- /dev/null +++ b/tthop.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tthop", "tthop.csproj", "{E4CF627D-7793-BDE2-31FE-B505FB1918FB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E4CF627D-7793-BDE2-31FE-B505FB1918FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4CF627D-7793-BDE2-31FE-B505FB1918FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4CF627D-7793-BDE2-31FE-B505FB1918FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4CF627D-7793-BDE2-31FE-B505FB1918FB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {22D1B5DE-443B-420F-8C57-A32B861E9CF5} + EndGlobalSection +EndGlobal