Skip to content

Commit aca91ac

Browse files
updates to go and dotnet metrics integrations
1 parent 17394dd commit aca91ac

File tree

3 files changed

+45
-53
lines changed

3 files changed

+45
-53
lines changed
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.AspNetCore.Mvc.RazorPages;
8-
using Prometheus;
9-
namespace work.Pages
10-
{
11-
public class IndexModel : PageModel
12-
{
13-
private static readonly Counter ProcessedJobCount = Metrics
14-
.CreateCounter("dotnet_request_operations_total", "The total number of processed requests");
15-
public void OnGet()
16-
{
17-
var sw = Stopwatch.StartNew();
18-
19-
sw.Stop();
20-
ProcessedJobCount.Inc();
21-
var histogram =
22-
Metrics
23-
.CreateHistogram(
24-
"dotnet_request_duration_seconds",
25-
"Histogram for the duration in seconds.",
26-
new[] { 0.02, 0.05, 0.1, 0.15, 0.2, 0.5, 0.8, 1 },
27-
"GET",
28-
"/");
29-
30-
histogram
31-
.Observe(sw.Elapsed.TotalSeconds);
32-
33-
}
34-
}
35-
}
1+
using System;
2+
using System.Diagnostics;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Prometheus;
9+
namespace work.Pages
10+
{
11+
public class IndexModel : PageModel
12+
{
13+
private static readonly Counter ProcessedJobCount = Metrics
14+
.CreateCounter("dotnet_request_operations_total", "The total number of processed requests");
15+
public void OnGet()
16+
{
17+
var sw = Stopwatch.StartNew();
18+
19+
sw.Stop();
20+
ProcessedJobCount.Inc();
21+
var histogram =
22+
Metrics.CreateHistogram(
23+
"dotnet_request_duration_seconds",
24+
"Histogram for the duration in seconds.",
25+
new HistogramConfiguration
26+
{
27+
Buckets = Histogram.LinearBuckets(start: 1, width: 1, count: 5)
28+
});
29+
30+
histogram.Observe(sw.Elapsed.TotalSeconds);
31+
32+
}
33+
}
34+
}

prometheus-monitoring/go-application/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ func main() {
2020

2121
fmt.Println("starting...")
2222

23-
requestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
24-
Name: "go_request_duration_seconds",
25-
Help: "Histogram for the duration in seconds.",
26-
Buckets: []float64{1, 2, 5, 6, 10},
27-
},
23+
requestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
24+
Name: "go_request_duration_seconds",
25+
Help: "Histogram for the duration in seconds.",
26+
Buckets: []float64{1, 2, 5, 6, 10},
27+
},
2828
[]string{"endpoint"},
2929
)
3030

prometheus-monitoring/readme.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33

44
To run any of the commands, please ensure you open a terminal and navigate to the path where this readme is located.
55

6-
## Start Prometheus
6+
## Start Prometheus, Grafana & Dashboards
77

88
```
99
docker-compose up -d prometheus
1010
docker-compose up -d grafana
11+
docker-compose up -d grafana-dashboards
1112
```
1213

13-
Wait for Grafana to start up
14-
Import the dashboards
15-
```
16-
TODO
17-
```
18-
19-
You should see all application targets un `UNKNOWN` or `DOWN` status.
20-
```http://localhost:9090/targets```
2114

2215
## Start the example app you prefer
2316

2417
```
25-
docker-compose up -d golang-application
26-
docker-compose up -d python-application
27-
docker-compose up -d dotnet-application
28-
docker-compose up -d nodejs-application
18+
docker-compose up -d --build go-application
19+
docker-compose up -d --build python-application
20+
docker-compose up -d --build dotnet-application
21+
docker-compose up -d --build nodejs-application
2922
```
3023

3124
## Generate some requests by opening the application in the browser

0 commit comments

Comments
 (0)