下一个计划 : .NET/.NET Core应用性能管理
前言
最近幾個月一直在研究開源的APM和監(jiān)控方案,并對比使用了Zipkin,CAT,Sky-walking,PinPoint(僅對比,未實(shí)際部署),Elastic APM,TICK Stack,Prometheus等開源產(chǎn)品,其中不乏功能強(qiáng)大的監(jiān)控和追蹤系統(tǒng),但它們都對.NET/.NET Core沒有支持或支持不夠完備。而在.NET/.NET Core平臺也僅有Metrics.NET,AppMetrics,MiniProfiler等輕量級監(jiān)控組件,它們也都和功能完備的APM系統(tǒng)差距甚遠(yuǎn),也無法完全滿足對當(dāng)前流行的微服務(wù)系統(tǒng)進(jìn)行全鏈路追蹤和端對端監(jiān)控的需求。為了滿足實(shí)際的監(jiān)控需求以及自身對APM系統(tǒng)的研究刨析,我決定從零開發(fā).NET/.NET Core的APM,它應(yīng)該包含
Http請求監(jiān)控
應(yīng)用健康檢查
方法執(zhí)行監(jiān)控
應(yīng)用內(nèi)數(shù)據(jù)庫訪問監(jiān)控
應(yīng)用內(nèi)緩存訪問監(jiān)控(Redis)
CLR/CoreCLR Runtime/GC/Threading監(jiān)控
請求鏈路監(jiān)控
分布式追蹤
為了實(shí)現(xiàn)如上需求,我創(chuàng)建了AspectCoreAPM(基于AspectCore AOP的APM client agent)和Butterfly(獨(dú)立的分布式追蹤Server)兩個開源項(xiàng)目,你可以在dotnet-lab[https://github.com/dotnet-lab]這個github organization下找到它們。下面將分別對兩個項(xiàng)目進(jìn)行簡單介紹。
Butterfly--A distributed tracing server
Butterfly被設(shè)計(jì)為分布式追蹤和APM的Server端,它將包含Collector,Storage,獨(dú)立的Web UI,并使用Open Tracing規(guī)范來設(shè)計(jì)追蹤數(shù)據(jù)。目前僅根據(jù)規(guī)范實(shí)現(xiàn)了Open Tracing API。
AspectCoreAPM
AspectCoreAPM抽象了APM的應(yīng)用探針設(shè)計(jì),它將會使用自動探針(收集CLR/CoreCLR數(shù)據(jù)),AOP探針(收集方法執(zhí)行數(shù)據(jù))和手動探針(業(yè)務(wù)數(shù)據(jù))三種方式來收集數(shù)據(jù)發(fā)送到不同Collector Server或Storage。鑒于Butterfly Server并未完全實(shí)現(xiàn),現(xiàn)階段使用InfluxDB作為數(shù)據(jù)存儲,并使用Grafana進(jìn)行監(jiān)控展示(在Butterfly Server完成后在Web UI進(jìn)行統(tǒng)一的監(jiān)控?cái)?shù)據(jù)展示)。AspectCoreAPM目前已經(jīng)完成了Http請求監(jiān)控,簡單的GC/Threading監(jiān)控和RedisClient監(jiān)控。
在使用AspectCoreAPM之前,我們需要先安裝InfluxDB和Grafana。
安裝InfluxDB:
wget https://dl.influxdata.com/influxdb/releases/influxdb_1.4.2_amd64.debsudo dpkg -i influxdb_1.4.2_amd64.deb安裝之后,執(zhí)行influx進(jìn)入influxdb的CLI,并創(chuàng)建一個名稱為aspectcore的database:
CREATE DATABASE aspectcore然后安裝Grafana:
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_4.6.2_amd64.deb sudo dpkg -i grafana_4.6.2_amd64.debGrafana默認(rèn)綁定的http地址為localhost,我們需要修改http_addr才可在外部訪問Grafana,使用vi打開Grafana的配置文件:
sudo vi grafana/grafana.ini找到http_addr配置修改為0.0.0.0:3000或你的外網(wǎng)IP。
在瀏覽器打開Grafana,默認(rèn)賬號和密碼均為admin,然后添加DataSource。Type選擇influxdb,并且database填寫我們上面創(chuàng)建的aspectcore:
下載并導(dǎo)入AspectCoreAPM的Dashborad :?https://grafana.com/dashboards/3837
接下來創(chuàng)建一個Asp.Net Core項(xiàng)目,并從nuget添加AspectCoreAPM:
Install-Package AspectCore.APM.AspNetCoreInstall-Package AspectCore.APM.LineProtocolCollectorInstall-Package AspectCore.APM.ApplicationProfiler修改Startup.cs:
public class Startup{ ??public Startup(IConfiguration configuration) ? ?{Configuration = configuration;} ? ?
?
?public IConfiguration Configuration { get; } ? ?// This method gets called by the runtime. Use this method to add services to the container.
??public IServiceProvider ConfigureServices(IServiceCollection services) ? ?{services.AddMvc();services.AddAspectCoreAPM(component =>{component.AddApplicationProfiler();
??//注冊ApplicationProfiler收集GC和ThreadPool數(shù)據(jù)component.AddHttpProfiler(); ? ? ?
?? ?//注冊HttpProfiler收集Http請求數(shù)據(jù)component.AddLineProtocolCollector(options => //注冊LineProtocolCollector將數(shù)據(jù)發(fā)送到InfluxDb{options.Server = "http://192.168.3.4:8086"; //你自己的InfluxDB Http地址options.Database = "aspectcore"; ? ?//你自己創(chuàng)建的Database});}); ? ? ?
?? ?return services.BuildAspectCoreServiceProvider(); //返回AspectCore AOP的ServiceProvider,這句代碼一定要有} ?
?? ?
?? ??// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
?? ? ?public void Configure(IApplicationBuilder app, IHostingEnvironment env) ? ?{app.UseAspectCoreAPM(); ? ? //啟動AspectCoreAPM,這句代碼一定要有app.UseHttpProfiler(); ? ? ?//啟動Http請求監(jiān)控if (env.IsDevelopment()){app.UseDeveloperExceptionPage();}app.UseMvc();} }
啟動應(yīng)用并訪問頁面。最后回到Grafana,在DataSource處選擇aspectcore,就能看到我們的監(jiān)控?cái)?shù)據(jù)啦。
有問題反饋
希望有更多的.NET/.NET Core開發(fā)者能關(guān)注到這個項(xiàng)目并參與進(jìn)來。
如果您有任何問題,請?zhí)峤?Issue?給我們。
Github :?https://github.com/dotnet-lab/AspectCore-APM
如果您覺得此項(xiàng)目對您有幫助,請點(diǎn)個Star~
AspectCore QQ群: 306531723
原文:http://www.cnblogs.com/liuhaoyang/p/next-plan-apm.html
.NET社區(qū)新聞,深度好文,歡迎訪問公眾號文章匯總 http://www.csharpkit.com
總結(jié)
以上是生活随笔為你收集整理的下一个计划 : .NET/.NET Core应用性能管理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中间件中渲染Razor视图
- 下一篇: ASP.NET Core 认证与授权[7