summary refs log tree commit diff
path: root/LibSystemdCli.Models/SystemdServiceData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibSystemdCli.Models/SystemdServiceData.cs')
-rw-r--r--LibSystemdCli.Models/SystemdServiceData.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/LibSystemdCli.Models/SystemdServiceData.cs b/LibSystemdCli.Models/SystemdServiceData.cs
index 1efcfd7..8d35c26 100644
--- a/LibSystemdCli.Models/SystemdServiceData.cs
+++ b/LibSystemdCli.Models/SystemdServiceData.cs
@@ -9,14 +9,30 @@ public class SystemdServiceData {
     [JsonPropertyName("multiData")]
     public Dictionary<string, List<string>> MultiData { get; set; } = new();
 
-    public bool IsRunning => Status is "active" or "reloading";
+    public bool IsRunning => Status is "active" or "reloading" or "deactating" or "activating";
     public string Status => GetSingleData("ActiveState") ?? "unknown";
+    
+    public long MemoryCurrent {
+        get {
+            if (long.TryParse(GetSingleData("MemoryCurrent") ?? "0", out long mem)) return mem;
+            return 0;
+        }
+    }
+
+    public long MemoryPeak {
+        get {
+            if (long.TryParse(GetSingleData("MemoryPeak") ?? "0", out long mem)) return mem;
+            return 0;
+        }
+    }
+    
+    
     public void AddData(string key, string value) {
         if (MultiData.ContainsKey(key)) {
             MultiData[key].Add(value);
         }
         else if (SingleData.ContainsKey(key)) {
-            MultiData[key] = new List<string> { SingleData[key], value };
+            MultiData[key] = [SingleData[key], value];
             SingleData.Remove(key);
         }
         else {
@@ -43,4 +59,17 @@ public class SystemdServiceData {
 
         return null;
     }
+
+    public void SetOldData(SystemdServiceData oldData) {
+        var now = DateTime.Now;
+        
+        var cpuDiff = CpuUsageNs - oldData.CpuUsageNs;
+        var timeDiff = now - oldData.Timestamp;
+        CpuUsagePercent = cpuDiff / timeDiff.TotalMilliseconds / 1_000_000d;
+    }
+    
+    public DateTime Timestamp { get; set; } = DateTime.Now;
+    public long CpuUsageNs => long.Parse(GetSingleData("CPUUsageNSec") ?? "0");
+    
+    public double CpuUsagePercent { get; set; }
 }
\ No newline at end of file