33using LinkRouter . App . Configuration ;
44using Microsoft . AspNetCore . Mvc ;
55using MoonCore . Services ;
6+ using Prometheus ;
67
78namespace LinkRouter . App . Http . Controllers ;
89
@@ -11,6 +12,26 @@ public class RedirectController : Controller
1112{
1213
1314 private readonly Config Config ;
15+
16+
17+ private readonly Counter RouteCounter = Metrics . CreateCounter (
18+ "linkrouter_requests" ,
19+ "Counts the number of requests to the link router" ,
20+ new CounterConfiguration
21+ {
22+ LabelNames = new [ ] { "route" }
23+ }
24+ ) ;
25+
26+
27+ private readonly Counter NotFoundCounter = Metrics . CreateCounter (
28+ "linkrouter_404_requests" ,
29+ "Counts the number of not found requests to the link router" ,
30+ new CounterConfiguration
31+ {
32+ LabelNames = new [ ] { "route" }
33+ }
34+ ) ;
1435
1536 public RedirectController ( Config config )
1637 {
@@ -23,8 +44,17 @@ public IActionResult RedirectToExternalUrl(string path)
2344 var redirectRoute = Config . Routes . FirstOrDefault ( x => x . Route == path || x . Route == path + "/" || x . Route == "/" + path ) ;
2445
2546 if ( redirectRoute != null )
47+ {
48+ RouteCounter
49+ . WithLabels ( redirectRoute . Route )
50+ . Inc ( ) ;
51+
2652 return Redirect ( redirectRoute . RedirectUrl ) ;
53+ }
2754
55+ NotFoundCounter
56+ . WithLabels ( path )
57+ . Inc ( ) ;
2858
2959 if ( Config . NotFoundBehavior . RedirectOn404 )
3060 return Redirect ( Config . NotFoundBehavior . RedirectUrl ) ;
@@ -35,6 +65,10 @@ public IActionResult RedirectToExternalUrl(string path)
3565 [ HttpGet ( "/" ) ]
3666 public IActionResult GetRootRoute ( )
3767 {
68+ RouteCounter
69+ . WithLabels ( "/" )
70+ . Inc ( ) ;
71+
3872 string url = Config . RootRoute ;
3973
4074 return Redirect ( url ) ;
0 commit comments