专业提供深圳网站设计公司,铁道部建设司网站,网站流量多少做网盟,手机网站php源码Prometheus是CNCF毕业的第二个项目#xff0c;算是明星产品#xff08;可自行了解Prometheus的功能#xff09;#xff0c;asp.net core当然不能错过与之配套使用。在.net中是通过prometheus.net【https://github.com/prometheus-net/prometheus-net】引入的。上图是用Prom… Prometheus是CNCF毕业的第二个项目算是明星产品可自行了解Prometheus的功能asp.net core当然不能错过与之配套使用。在.net中是通过prometheus.net【https://github.com/prometheus-net/prometheus-net】引入的。上图是用Prometheus作监控结构图Prometheus默认采有拉的方式从应用服务中把metrics数据拉取出来以便提供给Grafana去作展示。下面通过一个例子来进行说明。1、下载Prometheus【https://prometheus.io/download/】prometheus.yml是配置文件因为采有拉模式需要在配置文件中配置应用服务的url http://localhost:5000可以双击prometheus.exe启动了。2、下载Grafana【https://grafana.com/grafana/download?platformwindows】启动grafana-server.exe访问http://localhost:3000/用户名密码默认username:admin,password:admin现在开始配置Grafana:a、配置数据源b、配置监控面板3、创建一个asp.net core 5.0的api项目引进nuget包prometheus-net.AspNetCore同时在Starup.cs的configure中添加Prometheus的中间件 public void Configure(IApplicationBuilder app, IWebHostEnvironment env){if (env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseSwagger();app.UseSwaggerUI(c c.SwaggerEndpoint(/swagger/v1/swagger.json, PrometheusSimpal v1));}app.UseRouting();//http请求的中间件app.UseHttpMetrics();app.UseAuthorization();app.UseEndpoints(endpoints {//映射监控地址为 /metricsendpoints.MapMetrics();endpoints.MapControllers();});}
启动服务http://loclahost:5000本例是采用grafana模板10915来展示数据的展示的信息只是请求和controller的跟踪信息可以通过固定中间件来完全收集如果有业务方面的信息跟踪展示就需要开发人家根据自己的精力逻辑来展示了。