Json logs
4 files changed, 95 insertions, 5 deletions
diff --git a/LibSystemdCli.Models/SystemdJournalLogItem.cs b/LibSystemdCli.Models/SystemdJournalLogItem.cs
new file mode 100644
index 0000000..c829378
--- /dev/null
+++ b/LibSystemdCli.Models/SystemdJournalLogItem.cs
@@ -0,0 +1,83 @@
+using System.Text.Json.Serialization;
+
+namespace LibSystemdCli;
+
+public class SystemdJournalLogItem {
+ [JsonPropertyName("_BOOT_ID")]
+ public string BootId { get; set; } = null!;
+
+ [JsonPropertyName("__CURSOR")]
+ public string Cursor { get; set; } = null!;
+
+ [JsonPropertyName("_SYSTEMD_INVOCATION_ID")]
+ public string SystemdInvocationId { get; set; } = null!;
+
+ [JsonPropertyName("_MACHINE_ID")]
+ public string MachineId { get; set; } = null!;
+
+ [JsonPropertyName("__SEQNUM")]
+ public string SequenceNumber { get; set; } = null!;
+
+ [JsonPropertyName("_RUNTIME_SCOPE")]
+ public string RuntimeScope { get; set; } = null!;
+
+ [JsonPropertyName("__SEQNUM_ID")]
+ public string SequenceNumberId { get; set; } = null!;
+
+ [JsonPropertyName("_HOSTNAME")]
+ public string Hostname { get; set; } = null!;
+
+ [JsonPropertyName("SYSLOG_FACILITY")]
+ public string SyslogFacility { get; set; } = null!;
+
+ [JsonPropertyName("_COMM")]
+ public string Comm { get; set; } = null!;
+
+ [JsonPropertyName("SYSLOG_IDENTIFIER")]
+ public string SyslogIdentifier { get; set; } = null!;
+
+ [JsonPropertyName("_TRANSPORT")]
+ public string Transport { get; set; } = null!;
+
+ [JsonPropertyName("_GID")]
+ public string Gid { get; set; } = null!;
+
+ [JsonPropertyName("__MONOTONIC_TIMESTAMP")]
+ public string MonotonicTimestamp { get; set; } = null!;
+
+ [JsonPropertyName("PRIORITY")]
+ public string Priority { get; set; } = null!;
+
+ [JsonPropertyName("_SYSTEMD_SLICE")]
+ public string SystemdSlice { get; set; } = null!;
+
+ [JsonPropertyName("_SYSTEMD_UNIT")]
+ public string SystemdUnit { get; set; } = null!;
+
+ [JsonPropertyName("_STREAM_ID")]
+ public string StreamId { get; set; } = null!;
+
+ [JsonPropertyName("_CMDLINE")]
+ public string Cmdline { get; set; } = null!;
+
+ [JsonPropertyName("__REALTIME_TIMESTAMP")]
+ public string RealtimeTimestamp { get; set; } = null!;
+
+ [JsonPropertyName("_SYSTEMD_CGROUP")]
+ public string SystemdCgroup { get; set; } = null!;
+
+ [JsonPropertyName("_PID")]
+ public string Pid { get; set; } = null!;
+
+ [JsonPropertyName("MESSAGE")]
+ public string Message { get; set; } = null!;
+
+ [JsonPropertyName("_UID")]
+ public string Uid { get; set; } = null!;
+
+ [JsonPropertyName("_CAP_EFFECTIVE")]
+ public string CapEffective { get; set; } = null!;
+
+ [JsonPropertyName("_EXE")]
+ public string Exe { get; set; } = null!;
+}
\ No newline at end of file
diff --git a/LibSystemdCli/SystemdExecutor.cs b/LibSystemdCli/SystemdExecutor.cs
index eb6dfc9..06c9538 100644
--- a/LibSystemdCli/SystemdExecutor.cs
+++ b/LibSystemdCli/SystemdExecutor.cs
@@ -28,4 +28,11 @@ public class SystemdExecutor
// await Task.Delay(100);
}
}
+
+ public static async IAsyncEnumerable<SystemdJournalLogItem> GetUnitLogs(string serviceName) {
+ await foreach (var line in CommandExecutor.ExecuteCommandAsync("journalctl", $"--catalog --all --pager-end --follow --output=json --unit={serviceName}"))
+ {
+ yield return JsonSerializer.Deserialize<SystemdJournalLogItem>(line)!;
+ }
+ }
}
\ No newline at end of file
diff --git a/SystemdCtl.Client/Pages/ServiceManage.razor b/SystemdCtl.Client/Pages/ServiceManage.razor
index 9a32087..c622833 100644
--- a/SystemdCtl.Client/Pages/ServiceManage.razor
+++ b/SystemdCtl.Client/Pages/ServiceManage.razor
@@ -35,7 +35,7 @@
private static bool IsClient => !Environment.CommandLine.Contains("/");
- private List<string> LogLines { get; set; } = new();
+ private List<SystemdJournalLogItem> LogLines { get; set; } = new();
protected override async Task OnInitializedAsync() {
Console.WriteLine("OnInitializedAsync");
@@ -47,7 +47,7 @@
LogLines.Clear();
var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };
- var _items = Http.GetAsyncEnumerableFromJsonAsync<string>($"/api/unit/{ServiceName}/logs");
+ var _items = Http.GetAsyncEnumerableFromJsonAsync<SystemdJournalLogItem>($"/api/unit/{ServiceName}/logs");
await foreach (var item in _items) {
LogLines.Add(item);
if (LogLines.Count > 100) LogLines.RemoveAt(0);
diff --git a/SystemdCtl/Controllers/UnitController.cs b/SystemdCtl/Controllers/UnitController.cs
index 212df7d..00916bf 100644
--- a/SystemdCtl/Controllers/UnitController.cs
+++ b/SystemdCtl/Controllers/UnitController.cs
@@ -18,11 +18,11 @@ public class UnitController : ControllerBase
}
[HttpGet("unit/{serviceName}/logs")]
- public async IAsyncEnumerable<string> GetUnitLogs(string serviceName)
+ public async IAsyncEnumerable<SystemdJournalLogItem> GetUnitLogs(string serviceName)
{
- await foreach (var line in CommandExecutor.ExecuteCommandAsync("journalctl", $"-xaefu {serviceName}"))
+ await foreach (var log in SystemdExecutor.GetUnitLogs(serviceName))
{
- yield return line;
+ yield return log;
await Response.Body.FlushAsync();
}
}
|