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

广州做网站找哪家好建设网站怎么收费标准

广州做网站找哪家好,建设网站怎么收费标准,论坛cms系统,中国菲律宾商会上一篇博文中说到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、Histogram直方图直方图维基百科的定义是一种对数据分布情况的图形表示是一种二维统计图表它的两个坐标分别是统计样本和该样本对应的某个属性的度量以长条图bar的形式具体表现。因为直方图的长度及宽度很适合用来表现数量上的变化所以较容易解读差异小的数值。还是拿上一篇的Sample来说明假如每个订单都有一个金额在order时在返回值{resulttrue,data1000}的data属性中返回这里我们就可以用直方图来收集这个金额由于订单的金额不一样我们就可以用直方图来展示一定范围金额内订单的数据监控出一定金额范围内的订单比例了。就是说在一定数量的订单里少于1000元的有多少个订单少于2000元有多少个订单少于3000元的有多少个订单……首先我们得修改BusinessController中Order Action的业务逻辑把订单金额作为返回值[HttpGet(/order)]public IActionResult Order(string orderno){try{_logger.LogInformation(下单);//返回订单金额var random new Random();return new JsonResult(new { Result true, data random.Next(1, 8000) });}catch (Exception exc){_logger.LogCritical(exc, exc.Message);return new JsonResult(new{Result false,Message exc.Message});}} 这里的金额为了方便demo是随机生成一个1到8000的随机数。需要在MetricsHub.cs中添加Histogram类型的指标收集集合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, 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 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 AddHistogram(string key, Histogram histogram){_histogramDictionary.Add(key, histogram);}} }接下来就要在BusinessMetricsMiddleware的中间件中添加处理Histogram指标的代码了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);}}}}}}finally{context.Response.Body originalBody;}}} } 再就是在Starsup中配置对应url的Histogram参数了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: 5)});metricsHub.AddHistogram(/order, orderHistogram);services.AddSingleton(metricsHub);}} } Histogram.LinearBuckets(start: 1000, width: 1000, count: 5)是金额从1000开始每1000为一个台阶一共6个台阶0~10001001~20002001~30003001~40004001~5000还有一个是大于5000的。最后一步就是打开Grafana来配置展示图表了。订单金额分布图订单比例分布图图中histogram_quantile(0.80, sum(rate(business_order_histogram_bucket[5m])) by (le))的意思是“80%的订单金额小于等于这个值”5分钟内的值。最终展示结果聪明的你一定发现这篇博文与上一篇如出一辙是的只是监控指标展示类型不同而以。
http://www.huolong8.cn/news/112232/

相关文章:

  • 电子商务网站建设定位设想物流网站的功能与特色
  • 安阳实力网站建设首选佛山学校网站建设
  • 批量做网站软件江苏高端品牌网站建设
  • 大良o2o网站建设摄影工作室网站源码
  • 太原网站优化技术邯郸市城乡住房建设局网站
  • 个人简历模板免费网站互联网技术怎么学
  • 电子商务网站建设及推广方案论文wordpress 暖岛 主题
  • 如何做明星的个人网站wordpress自动保存编辑器图片
  • 建设网站宣传页建立平台还是搭建平台
  • 郑州优秀网站建设公司课程网站建设的财务分析
  • 买东西最便宜的网站河北住房和城乡建设厅网站驱动
  • 网站开发工具安全性能网页ui设计模板代码
  • 论述网站推广的方法与技巧wordpress建站详细教程视频
  • 某些网站网速慢百度法务部联系方式
  • 确定网站设计公司简报佛山seo优化排名
  • 火车头wordpress建站群中国设计最好的网站
  • 汕头哪里学网站建设最好长春建站软件
  • 建设局网站首页崔各庄地区网站建设
  • 网站的动态图怎么做的小程序招商
  • 宁波网站优化公司软件推广公司简介怎么写
  • 安徽省卫生计生网站医共体建设辽阳专业网站建设品牌
  • 信用门户网站建设观摩手机网页设计网站建设
  • 网站开发大作业报告wordpress toptheme
  • 网络推广哪个网站好网站开发服务外包合同
  • 手机网站页面布局wordpress提示框插件
  • 网站框架设计理念网站建设所需费用明细
  • 外链网站哪些网站国内打不开
  • 福田建设网站中国舆情在线网
  • 用ps设计网站做多大的巨野网站建设
  • 企业为什么需要搭建一个网站营销型企业网站策划方案