Middleware for collecting metrics:
- Proceed request time
- Response status code counts
Based on Prometheus and Grafana
Repository contains a project for middleware and tools script
- Install prometheus-net.AspNetCore. It is needed to expose metric endpoint
- Install NuGet package
- In Startup.cs add middleware into core pipeline:
app.UseMetricServer(); // Prometheus exstension to expose metric endpoint
app.UseCactusMetric();
- Clone ToolsScript folder to your machine
- Edit configs to match for your project
- Use docker-compose.metrics.yml to start tools
Use MetricMiddlewareConfig object to change standart behavior:
- ExcludeStatusCodeMetric - set true to exclude status code metric
- ProceedRequestTimeBuckets - proceed request time buckets upper levels (milliseconds). Affect performance (fewer - better performance) Default: {50.0, 100, 200, 500, 1000, 1500, 2000} Details here
In ToolScripts/prometheus there are two config files:
- alert.rules - contains rules for Prometheus alerting Details here
- prometheus.yml - contains Prometheus config Details here Add servers to monitor in scrape_configs section
In ToolScripts/alertmanager there is config.yml for alerting configuration Details here
In Grafana included two dashboards:
- Docker (actually not perfect without swarm)
- General - shows proceed request times, response status code counts, CPU/memory usage, uptime You can add your own dashboards in ToolScriptsgrafana/provisioning/dashboards folder
To update preconfigured dashboards, export it and import back in Grafana (Details here)
For the first login, after that Grafana suggests changing password
Login: admin
Password: admin
OR you can set admin password in ToolsScripts/grafana/config.monitoring file in GF_SECURITY_ADMIN_PASSWORD parameter
You should change networks sections and path in volumes sections (if you changed docker-compose.metrics.yml path)