Skip to content

Commit

Permalink
file cache metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Jun 11, 2023
1 parent a13bf8c commit 80b62e7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions XLWebServices/Controllers/FileController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Prometheus;
using XLWebServices.Services;

namespace XLWebServices.Controllers;
Expand All @@ -12,6 +13,8 @@ public class FileController : ControllerBase

private static bool alwaysUseFileProxy = false;
private static bool noAllowForceProxy = false;

private static readonly Counter Requests = Metrics.CreateCounter("file_requests", "File Cache Requests", "Proxy");

public FileController(FileCacheService cache, IConfiguration config)
{
Expand All @@ -34,9 +37,13 @@ public IActionResult Get(string id, [FromQuery] bool forceProxy = false)
{
var contentType = file.ContentType;
contentType ??= "application/octet-stream";

Requests.WithLabels(true.ToString()).Inc();

return File(file.GetData(), contentType, file.OriginalName);
}

Requests.WithLabels(false.ToString()).Inc();

return Redirect(file.OriginalUrl);
}
Expand All @@ -56,6 +63,8 @@ public IActionResult GetProxy(string id)
{
return Redirect(file.OriginalUrl);
}

Requests.WithLabels(true.ToString()).Inc();

var contentType = file.ContentType;
contentType ??= "application/octet-stream";
Expand Down

0 comments on commit 80b62e7

Please sign in to comment.