1- using LinkRouter . App . Configuration ;
1+ using LinkRouter . App . Configuration ;
22using Microsoft . AspNetCore . Mvc ;
3+ using Prometheus ;
4+
35
46namespace LinkRouter . App . Http . Controllers ;
57
@@ -8,6 +10,26 @@ public class RedirectController : Controller
810{
911
1012 private readonly Config Config ;
13+
14+
15+ private readonly Counter RouteCounter = Metrics . CreateCounter (
16+ "linkrouter_requests" ,
17+ "Counts the number of requests to the link router" ,
18+ new CounterConfiguration
19+ {
20+ LabelNames = new [ ] { "route" }
21+ }
22+ ) ;
23+
24+
25+ private readonly Counter NotFoundCounter = Metrics . CreateCounter (
26+ "linkrouter_404_requests" ,
27+ "Counts the number of not found requests to the link router" ,
28+ new CounterConfiguration
29+ {
30+ LabelNames = new [ ] { "route" }
31+ }
32+ ) ;
1133
1234 public RedirectController ( Config config )
1335 {
@@ -20,8 +42,17 @@ public IActionResult RedirectToExternalUrl(string path)
2042 var redirectRoute = Config . Routes . FirstOrDefault ( x => x . Route == path || x . Route == path + "/" || x . Route == "/" + path ) ;
2143
2244 if ( redirectRoute != null )
45+ {
46+ RouteCounter
47+ . WithLabels ( redirectRoute . Route )
48+ . Inc ( ) ;
49+
2350 return Redirect ( redirectRoute . RedirectUrl ) ;
51+ }
2452
53+ NotFoundCounter
54+ . WithLabels ( path )
55+ . Inc ( ) ;
2556
2657 if ( Config . NotFoundBehavior . RedirectOn404 )
2758 return Redirect ( Config . NotFoundBehavior . RedirectUrl ) ;
@@ -32,6 +63,10 @@ public IActionResult RedirectToExternalUrl(string path)
3263 [ HttpGet ( "/" ) ]
3364 public IActionResult GetRootRoute ( )
3465 {
66+ RouteCounter
67+ . WithLabels ( "/" )
68+ . Inc ( ) ;
69+
3570 string url = Config . RootRoute ;
3671
3772 return Redirect ( url ) ;
0 commit comments