Hướng dẫn Monitoring Server với App Metrics, Prometheus và Grafana trên ASP.NET Core

Hướng dẫn Monitoring Server với App Metrics, Prometheus và Grafana

1. Công cụ

2. Cài đặt
- Install package qua manager package tool
- Config tại file Program.cs

 return WebHost.CreateDefaultBuilder(args)
                        .UseMetrics(
                            options =>
                            {
                                options.EndpointOptions = endpointsOptions =>
                                {
                                    endpointsOptions.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
                                    endpointsOptions.MetricsEndpointOutputFormatter = new MetricsPrometheusProtobufOutputFormatter();
                                };
                            })
                .UseStartup<Startup>();

- Config tại startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            .....
            services.AddHealth().AddHealthReportingHostedService();
            services.AddMvcCore().AddMetricsCore();
        }
3. Cài đặt Promethes
- Config prometheus.yml
  - job_name'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    schemehttps
    metrics_path/metrics-text

    static_configs:
    - targets: ['localhost:44324']

 Chạy prometheus. Vào trình duyệt gõ: http://localhost:9090/targets nếu state UP thì connect thành công
4. Cài Grafana
- Các bước cài cũng chỉ next next và finish, nên mình sẽ không hướng dẫn củ thể lên đây
- Truy cập http://localhost:3000/
- Đăng nhập với tài khoản admin, pass: admin
- Add data source prometheus như dưới:

- Nếu Save và Test thành công vào import

Nhập: 2204. -> Nhấn Load và tận hưởng:

nếu có thắc mắc hãy liên hệ Đinh Công Tân VCCorp
Post a Comment