zoukankan      html  css  js  c++  java
  • .NetCore 使用Zipkin 分布式服务追踪监控服务性能

    参考资料

    https://zipkin.io/

    https://github.com/openzipkin/zipkin/

    https://github.com/openzipkin/zipkin4net

    搭建环境

    CentOS 7.X

    Java 8 SDK

    zipkin官网有三种安装方式可以参考

    Docker

    docker run -d -p 9411:9411 openzipkin/zipkin

    Java

    如果你已经拥有Java8的环境可以如下安装

    curl -sSL https://zipkin.io/quickstart.sh | bash -s
    java -jar zipkin.jar

    源码安装

    git clone https://github.com/openzipkin/zipkin
    cd zipkin
    ./mvnw -DskipTests --also-make -pl zipkin-server clean install
    java -jar ./zipkin-server/target/zipkin-server-*exec.jar

    安装好之后访问下地址看下Zipkin效果

    .NetCore中怎么来使用Zipkin

    首先添加如下2个nuget包

    为了不使Configure方法太过臃肿,我这里扩展下需要用到的IApplicationBuilder接口

    在Configure中注入IApplicationLifetime 、ILoggerFactory两个对象

      app.UserZipkinCore(applicationLifetime, loggerFactory);
    public static void UserZipkinCore(this IApplicationBuilder app,IApplicationLifetime applicationLifetime,ILoggerFactory loggerFactory)
            {
                applicationLifetime.ApplicationStarted.Register(() =>
                {
                    TraceManager.SamplingRate = 1.0f;
                    var logger = new TracingLogger(loggerFactory, "zipkin4net");
                    var httpsender = new HttpZipkinSender("http://ipaddress:9411", "application/json");
                    var tracer = new ZipkinTracer(httpsender, new JSONSpanSerializer());
                    TraceManager.RegisterTracer(tracer);
                    TraceManager.Start(logger);
                });
                applicationLifetime.ApplicationStopped.Register(() => TraceManager.Stop());
                app.UseTracing("IdentityServer4"); 
            }
    SamplingRate:跟踪日志的颗粒度
    UseTracing:在Zipkin上新建的服务名称

    启动引用程序查看Zipkin中的记录

    关于Zipkin的界面功能就不做特别介绍一看都懂

     
     
  • 相关阅读:
    关于华为x1 7.0无法从eclipse发布的更新as发布的apk
    2015-10-29
    Android Exception18(Stuido debug .....)
    阿里巴巴校招运营专员笔试题
    业务性产品经理(商业领域)笔试题
    Android编程之常识
    2015-08-24
    What most young programmers need to learn
    hdu 1556 Color the ball
    跟着实例学习设计模式(3)-工厂方法(创建型)
  • 原文地址:https://www.cnblogs.com/liyouming/p/9228297.html
Copyright © 2011-2022 走看看