diff --git a/prometheus-monitoring/dotnet-application/src/Pages/Index.cshtml.cs b/prometheus-monitoring/dotnet-application/src/Pages/Index.cshtml.cs index 9a959d1..ff7b76f 100644 --- a/prometheus-monitoring/dotnet-application/src/Pages/Index.cshtml.cs +++ b/prometheus-monitoring/dotnet-application/src/Pages/Index.cshtml.cs @@ -1,35 +1,34 @@ -using System; -using System.Diagnostics; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Prometheus; -namespace work.Pages -{ - public class IndexModel : PageModel - { - private static readonly Counter ProcessedJobCount = Metrics - .CreateCounter("dotnet_request_operations_total", "The total number of processed requests"); - public void OnGet() - { - var sw = Stopwatch.StartNew(); - - sw.Stop(); - ProcessedJobCount.Inc(); - var histogram = - Metrics - .CreateHistogram( - "dotnet_request_duration_seconds", - "Histogram for the duration in seconds.", - new[] { 0.02, 0.05, 0.1, 0.15, 0.2, 0.5, 0.8, 1 }, - "GET", - "/"); - - histogram - .Observe(sw.Elapsed.TotalSeconds); - - } - } -} +using System; +using System.Diagnostics; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Prometheus; +namespace work.Pages +{ + public class IndexModel : PageModel + { + private static readonly Counter ProcessedJobCount = Metrics + .CreateCounter("dotnet_request_operations_total", "The total number of processed requests"); + public void OnGet() + { + var sw = Stopwatch.StartNew(); + + sw.Stop(); + ProcessedJobCount.Inc(); + var histogram = + Metrics.CreateHistogram( + "dotnet_request_duration_seconds", + "Histogram for the duration in seconds.", + new HistogramConfiguration + { + Buckets = Histogram.LinearBuckets(start: 1, width: 1, count: 5) + }); + + histogram.Observe(sw.Elapsed.TotalSeconds); + + } + } +} diff --git a/prometheus-monitoring/go-application/main.go b/prometheus-monitoring/go-application/main.go index 3052401..9caadfb 100644 --- a/prometheus-monitoring/go-application/main.go +++ b/prometheus-monitoring/go-application/main.go @@ -20,11 +20,11 @@ func main() { fmt.Println("starting...") - requestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Name: "go_request_duration_seconds", - Help: "Histogram for the duration in seconds.", - Buckets: []float64{1, 2, 5, 6, 10}, - }, + requestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{ + Name: "go_request_duration_seconds", + Help: "Histogram for the duration in seconds.", + Buckets: []float64{1, 2, 5, 6, 10}, + }, []string{"endpoint"}, ) diff --git a/prometheus-monitoring/readme.md b/prometheus-monitoring/readme.md index b851ef1..ef5242d 100644 --- a/prometheus-monitoring/readme.md +++ b/prometheus-monitoring/readme.md @@ -3,29 +3,22 @@ To run any of the commands, please ensure you open a terminal and navigate to the path where this readme is located. -## Start Prometheus +## Start Prometheus, Grafana & Dashboards ``` docker-compose up -d prometheus docker-compose up -d grafana +docker-compose up -d grafana-dashboards ``` -Wait for Grafana to start up -Import the dashboards -``` -TODO -``` - -You should see all application targets un `UNKNOWN` or `DOWN` status. -```http://localhost:9090/targets``` ## Start the example app you prefer ``` -docker-compose up -d golang-application -docker-compose up -d python-application -docker-compose up -d dotnet-application -docker-compose up -d nodejs-application +docker-compose up -d --build go-application +docker-compose up -d --build python-application +docker-compose up -d --build dotnet-application +docker-compose up -d --build nodejs-application ``` ## Generate some requests by opening the application in the browser