当前位置: 首页 > news >正文

寻找做网站万户高端网站建设

寻找做网站,万户高端网站建设,如何用手机免费开网店,网站定制开发要多久上一篇博文中说到Prometheus有四种指标类型#xff1a;Counter#xff08;计数器#xff09;、Gauge#xff08;仪表盘#xff09;、Histogram#xff08;直方图#xff09;、Summary#xff08;摘要#xff09;#xff0c;并且我们做了一个Counter的Demo#xff0c… 上一篇博文中说到Prometheus有四种指标类型Counter计数器、Gauge仪表盘、Histogram直方图、Summary摘要并且我们做了一个Counter的Demo接下来看看Histogram。3、Summary摘要summary是采集展示百分位数百分位定义在一组由小到大的数字中某个数字大于90%的数字这个数字就是第90个的百分位数。通过demo的来理解一下吧假如我们业务需求是要知道订单金额1030507090的百分位数该怎么实现呢需要在MetricsHub.cs中添加Summary类型的指标收集集合using Prometheus; using System.Collections.Generic;namespace PrometheusSample.Middlewares {public class MetricsHub{private static Dictionarystring, Counter _counterDictionary new Dictionarystring, Counter();private static Dictionarystring, Dictionarystring, Gauge _gaugeDictionary  new Dictionarystring, Dictionarystring, Gauge();private static Dictionarystring, Summary _summaryDictionary  new Dictionarystring, Summary();private static Dictionarystring, Histogram _histogramDictionary  new Dictionarystring, Histogram();public Counter GetCounter(string key){if (_counterDictionary.ContainsKey(key)){return _counterDictionary[key];}else{return null;}}public Dictionarystring, Gauge GetGauge(string key){if (_gaugeDictionary.ContainsKey(key)){return _gaugeDictionary[key];}else{return null;}}public Summary GetSummary(string key){if (_summaryDictionary.ContainsKey(key)){return _summaryDictionary[key];}else{return null;}}public Histogram GetHistogram(string key){if (_histogramDictionary.ContainsKey(key)){return _histogramDictionary[key];}else{return null;}}public void AddCounter(string key, Counter counter){_counterDictionary.Add(key, counter);}public void AddGauge(string key, Dictionarystring, Gauge gauges){_gaugeDictionary.Add(key, gauges);}public void AddSummary(string key, Summary summary){_summaryDictionary.Add(key, summary);}public void AddHistogram(string key, Histogram histogram){_histogramDictionary.Add(key, histogram);}} } 接下来就要在BusinessMetricsMiddleware的中间件中添加处理Summary指标的代码了using Microsoft.AspNetCore.Http; using PrometheusSample.Models; using System.IO; using System.Threading.Tasks;namespace PrometheusSample.Middlewares {/// summary/// 请求记录中间件/// /summarypublic class BusinessMetricsMiddleware{private readonly RequestDelegate _next;public BusinessMetricsMiddleware(RequestDelegate next){_next next;}public async Task InvokeAsync(HttpContext context, MetricsHub metricsHub){var originalBody context.Response.Body;try{using (var memStream new MemoryStream()){//从管理返回的Response中取出返回数据根据返回值进行监控指标计数context.Response.Body memStream;await _next(context);memStream.Position 0;string responseBody new StreamReader(memStream).ReadToEnd();memStream.Position 0;await memStream.CopyToAsync(originalBody);if (metricsHub.GetCounter(context.Request.Path) ! null || metricsHub.GetGauge(context.Request.Path) ! null){//这里约定所有action返回值是一个APIResult类型var result System.Text.Json.JsonSerializer.DeserializeAPIResult(responseBody, new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive true });if (result ! null result.Result){//获取到Countervar counter metricsHub.GetCounter(context.Request.Path);if (counter ! null){//计数counter.Inc();}var gauges metricsHub.GetGauge(context.Request.Path);if (gauges ! null){//存在增加指标就Incif (gauges.ContainsKey()){gauges[].Inc();} //存在减少指标-就Decif (gauges.ContainsKey(-)){gauges[-].Dec();}}var histogram metricsHub.GetHistogram(context.Request.Path);if (histogram ! null){var parseResult int.TryParse(result.Data.ToString(), out int i);if (parseResult){histogram.Observe(i);}}var summary metricsHub.GetSummary(context.Request.Path);if (summary ! null){var parseResult int.TryParse(result.Data.ToString(), out int i);if (parseResult){summary.Observe(i);}} }}}}finally{context.Response.Body originalBody;}}} } 再就是在Starsup中配置对应url的Summary参数了using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; using Prometheus; using PrometheusSample.Middlewares; using PrometheusSample.Services; using System.Collections.Generic;namespace PrometheusSample {public class Startup{public Startup(IConfiguration configuration){Configuration configuration;}public IConfiguration Configuration { get; }public void ConfigureServices(IServiceCollection services){MetricsHandle(services);services.AddScopedIOrderService, OrderService();services.AddControllers();services.AddSwaggerGen(c {c.SwaggerDoc(v1, new OpenApiInfo { Title PrometheusSample, Version v1 });});}public void Configure(IApplicationBuilder app, IWebHostEnvironment env){if (env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseSwagger();app.UseSwaggerUI(c c.SwaggerEndpoint(/swagger/v1/swagger.json, PrometheusSample v1));}app.UseRouting();//http请求的中间件app.UseHttpMetrics();app.UseAuthorization();//自定义业务跟踪app.UseBusinessMetrics();app.UseEndpoints(endpoints {//映射监控地址为 /metricsendpoints.MapMetrics();endpoints.MapControllers();});}/// summary/// 处理监控事项/// /summary/// param nameservices/paramvoid MetricsHandle(IServiceCollection services){var metricsHub new MetricsHub();//countermetricsHub.AddCounter(/register, Metrics.CreateCounter(business_register_user, 注册用户数。));metricsHub.AddCounter(/order, Metrics.CreateCounter(business_order_total, 下单总数。));metricsHub.AddCounter(/pay, Metrics.CreateCounter(business_pay_total, 支付总数。));metricsHub.AddCounter(/ship, Metrics.CreateCounter(business_ship_total, 发货总数。));//gaugevar orderGauge Metrics.CreateGauge(business_order_count, 当前下单数量。);var payGauge Metrics.CreateGauge(business_pay_count, 当前支付数量。);var shipGauge Metrics.CreateGauge(business_ship_count, 当前发货数据。);metricsHub.AddGauge(/order, new Dictionarystring, Gauge {{ , orderGauge}});metricsHub.AddGauge(/pay, new Dictionarystring, Gauge {{-,orderGauge},{,payGauge}});metricsHub.AddGauge(/ship, new Dictionarystring, Gauge {{,shipGauge},{-,payGauge}});//histogram var orderHistogram Metrics.CreateHistogram(business_order_histogram, 订单直方图。,new HistogramConfiguration{Buckets Histogram.LinearBuckets(start: 1000, width: 1000, count: 6)}) ; metricsHub.AddHistogram(/order, orderHistogram);//summary var orderSummary Metrics.CreateSummary(business_order_summary, 10分钟内的订单数量,new SummaryConfiguration{Objectives new[]{new QuantileEpsilonPair(0.1, 0.05), new QuantileEpsilonPair(0.3, 0.05), new QuantileEpsilonPair(0.5, 0.05),new QuantileEpsilonPair(0.7, 0.05), new QuantileEpsilonPair(0.9, 0.05),}});metricsHub.AddSummary(/order, orderSummary);services.AddSingleton(metricsHub);}} } 其实 new QuantileEpsilonPair(0.1, 0.05) 第一个参数是百分位0.05是误差范围是10%-5%10%5%。最后一步就是打开Grafana来配置展示图表了。最终展示结果同时事例中给出了最大、最少、平均、汇总、当前值以供参考。
http://www.sadfv.cn/news/209358/

相关文章:

  • 织梦网站会员中心模板代理做网站怎么样
  • 网站cdn自己做win2008网站404
  • 户外网站模板中国排名第一的游戏
  • 小榄网站建设公司宁波网页设计职业
  • 网站建设需要什么哪家做网站最便宜
  • 智慧团建网站官网入口登录赣州网站建设服务
  • 重庆网站建设cqhtwl大学社团网站建设
  • 什么是网站开发时间进度表广州物流网站建设
  • 哪些网站是用wordpresscentos7系统做网站
  • 上海公司网站建设公司浙江网络推广
  • 中国建设银行黄陂支行网站露营旅游网站策划书
  • 利用免费网站做SEO石家庄58同城最新招聘信息
  • 通过域名访问网站苏州网站建设网络
  • 度假村网站模板站长工具箱
  • 国家建设环保局网站手机网站北京
  • wordpress编辑模板厦门优化网站排名
  • 北京网站建设正邦建筑网站主页
  • 天津河东做网站哪家好seo sem是什么意思
  • 用dw制作个介绍家乡网站餐饮网站建设的毕设报告
  • 汕头网站建设seo外包公司网站开发人员离职后修改公司网站
  • 用邮箱地址做网站域名好吗肇庆高端模板建站
  • 车床加工东莞网站建设诸城哪有做公司网站的
  • 亳州网站制作谷歌地图下载
  • 高密市赏旋网站设计有限公司深圳光明区最新消息
  • 网站后台html页面医疗保险网站开通建设
  • 湛江专业建网站哪家好百度移动端网站
  • 假的建设银行网站做网站是学什么编程语言
  • 淮北市网站制作公司网站简繁体转换.rar
  • 邢台网站制作的地方揭阳新站seo方案
  • 公司怎么建立自己网站企业营销策划报告