-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/ebrvc/DevOps-GroupC into…
… feature/software-quality-tools
- Loading branch information
Showing
9 changed files
with
590 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
using Prometheus; | ||
|
||
public static class ApplicationMetrics | ||
{ | ||
public static readonly Histogram HttpRequestDuration = Metrics | ||
.CreateHistogram("minitwit_http_request_duration_seconds", "Histogram of HTTP request duration.", | ||
new HistogramConfiguration | ||
{ | ||
// Define buckets with appropriate ranges for your application | ||
Buckets = Histogram.LinearBuckets(start: 0.1, width: 0.1, count: 10), | ||
LabelNames = new[] { "endpoint" } | ||
}); | ||
|
||
public static readonly Counter HttpResponseStatusCodeTotal = Metrics | ||
.CreateCounter("minitwit_http_response_status_code_total", "Total number of HTTP responses sent by the application by status code.", | ||
new CounterConfiguration | ||
{ | ||
// Add a label for the HTTP status code | ||
LabelNames = new[] { "status_code" } | ||
}); | ||
|
||
public static readonly Counter HttpRequestTotal = Metrics | ||
.CreateCounter("minitwit_http_requests_total", "Total number of HTTP requests made to the application.", | ||
new CounterConfiguration | ||
{ | ||
LabelNames = new[] { "endpoint" } | ||
}); | ||
|
||
|
||
} | ||
using Prometheus; | ||
|
||
public static class ApplicationMetrics | ||
{ | ||
public static readonly Histogram HttpRequestDuration = Metrics | ||
.CreateHistogram("minitwit_http_request_duration_seconds", "Histogram of HTTP request duration.", | ||
new HistogramConfiguration | ||
{ | ||
// Define buckets with appropriate ranges for your application | ||
Buckets = Histogram.LinearBuckets(start: 0.1, width: 0.1, count: 10), | ||
LabelNames = new[] { "endpoint" } | ||
}); | ||
|
||
public static readonly Counter HttpResponseStatusCodeTotal = Metrics | ||
.CreateCounter("minitwit_http_response_status_code_total", "Total number of HTTP responses sent by the application by status code.", | ||
new CounterConfiguration | ||
{ | ||
// Add a label for the HTTP status code | ||
LabelNames = new[] { "status_code" } | ||
}); | ||
|
||
public static readonly Counter HttpRequestTotal = Metrics | ||
.CreateCounter("minitwit_http_requests_total", "Total number of HTTP requests made to the application.", | ||
new CounterConfiguration | ||
{ | ||
LabelNames = new[] { "endpoint" } | ||
}); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
using csharp_minitwit.Utils; | ||
|
||
using Microsoft.AspNetCore.Http; | ||
// Assuming ApplicationMetrics is in the same namespace, or add the appropriate using statement | ||
|
||
namespace csharp_minitwit.Middlewares | ||
{ | ||
public class CatchAllMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public CatchAllMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
var watch = Stopwatch.StartNew(); | ||
|
||
// Used to monitor total requests received grouped by endpoint | ||
ApplicationMetrics.HttpRequestTotal.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)).Inc(); | ||
|
||
await _next(context); | ||
|
||
watch.Stop(); | ||
|
||
// Used to monitor response delay grouped by endpoint | ||
ApplicationMetrics.HttpRequestDuration | ||
.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)) | ||
.Observe(watch.Elapsed.TotalSeconds); | ||
|
||
// Used to monitor response status codes grouped by endpoint | ||
ApplicationMetrics.HttpResponseStatusCodeTotal.WithLabels(context.Response.StatusCode.ToString()).Inc(); | ||
} | ||
} | ||
} | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Http; | ||
using System.Threading.Tasks; | ||
using csharp_minitwit.Utils; | ||
// Assuming ApplicationMetrics is in the same namespace, or add the appropriate using statement | ||
|
||
namespace csharp_minitwit.Middlewares | ||
{ | ||
public class CatchAllMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public CatchAllMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
var watch = Stopwatch.StartNew(); | ||
|
||
// Used to monitor total requests received grouped by endpoint | ||
ApplicationMetrics.HttpRequestTotal.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)).Inc(); | ||
|
||
await _next(context); | ||
|
||
watch.Stop(); | ||
|
||
// Used to monitor response delay grouped by endpoint | ||
ApplicationMetrics.HttpRequestDuration | ||
.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)) | ||
.Observe(watch.Elapsed.TotalSeconds); | ||
|
||
// Used to monitor response status codes grouped by endpoint | ||
ApplicationMetrics.HttpResponseStatusCodeTotal.WithLabels(context.Response.StatusCode.ToString()).Inc(); | ||
} | ||
} | ||
} |
Oops, something went wrong.