diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-08-03 17:38:42 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-08-03 17:38:42 -0500 |
| commit | a511408e7b915f04a329953152b36431bd80a10d (patch) | |
| tree | 41601e40910f48b54419fdfe595beeadf7591125 /src/slskd/Telemetry/API/TelemetryController.cs | |
| parent | f598d0c6f7b6a516174d251b968dc83593420b40 (diff) | |
| download | slskd-a511408e7b915f04a329953152b36431bd80a10d.tar.gz | |
add pki endpoint
Diffstat (limited to 'src/slskd/Telemetry/API/TelemetryController.cs')
| -rw-r--r-- | src/slskd/Telemetry/API/TelemetryController.cs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/slskd/Telemetry/API/TelemetryController.cs b/src/slskd/Telemetry/API/TelemetryController.cs index fcfde05e..2207ac8c 100644 --- a/src/slskd/Telemetry/API/TelemetryController.cs +++ b/src/slskd/Telemetry/API/TelemetryController.cs @@ -19,6 +19,7 @@ namespace slskd.Telemetry; using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Authorization; @@ -30,7 +31,7 @@ using Microsoft.AspNetCore.Mvc; [Route("api/v{version:apiVersion}/[controller]")] [ApiVersion("0")] [ApiController] -[Produces("text/plain", "application/json")] +[Produces("application/json")] public class TelemetryController : ControllerBase { /// <summary> @@ -45,21 +46,58 @@ public class TelemetryController : ControllerBase private TelemetryService Telemetry { get; } /// <summary> + /// KPIs for the app, based on the Prometheus dashboard + /// * process_Working_set_bytes = total memory used + /// * dotnet_total_memory_bytes = sum of all managed memory + /// * process_cpu_seconds_total = total cpu time spent (not a great measure) + /// * system_runtime_cpu_usage = % of cpu consumed + /// * system_net_sockets_* = TCP activity + /// KPIs for the _system_, not the app + /// * node_memory_* = info about _system_ memory + /// * node_filesystem_avail_bytes = how much space is left on the system + /// * node_network = info about network adapters on the system + /// Other + /// * process_start_time_seconds = unix timestamp of start time + /// </summary> + private List<Regex> KpiRegexes { get; } = new List<Regex> + { + new Regex("slskd_.*", RegexOptions.Compiled), + new Regex("node_(?!cpu)", RegexOptions.Compiled), + new Regex("process_.*", RegexOptions.Compiled), + new Regex("dotnet_total_memory_bytes", RegexOptions.Compiled), + new Regex("system_runtime_[cpu_usage|working_set|alloc_total]", RegexOptions.Compiled), + new Regex("system_net_sockets.*", RegexOptions.Compiled), + new Regex("microsoft_aspnetcore_server_kestrel_[current|total]_connections", RegexOptions.Compiled), + }; + + /// <summary> /// Gets application metrics. /// </summary> /// <returns></returns> [HttpGet("metrics")] [Authorize(Policy = AuthPolicy.Any)] + [Produces("text/plain", "application/json")] public async Task<IActionResult> Get() { - var response = await Telemetry.Prometheus.GetMetricsAsString(); - if (Request.Headers.Accept.ToString().Equals("application/json", StringComparison.OrdinalIgnoreCase)) { Dictionary<string, PrometheusMetric> dict = await Telemetry.Prometheus.GetMetricsAsObject(); return Ok(dict); } + var response = await Telemetry.Prometheus.GetMetricsAsString(); return Content(response, "text/plain"); } + + /// <summary> + /// Gets gets key performance indicators for the application. + /// </summary> + /// <returns></returns> + [HttpGet("metrics/kpi")] + [Authorize(Policy = AuthPolicy.Any)] + public async Task<IActionResult> GetKpis() + { + Dictionary<string, PrometheusMetric> dict = await Telemetry.Prometheus.GetMetricsAsObject(include: KpiRegexes); + return Ok(dict); + } } |
