.net应用监控类库Metrics.NET入门

要开始使用库,请安装Metrics.NET NuGet包,使用包管理UI或包管理控制台运行:

Install-Package Metrics.NET

在您的应用程序的初始化代码中添加以下Metrics.NET配置代码:

using Metrics;

Metric.Config
    .WithHttpEndpoint("http://localhost:1234/")
    .WithAllCounters();

运行该应用程序并将Web浏览器指向http://localhost:1234/

Metrics可视化应用程序应该已经有了从各个性能计数器捕获的多个Gauges

你现在可以开始测量了:

public class SampleMetrics
{
    private readonly Timer timer = Metric.Timer("Requests", Unit.Requests);
    private readonly Counter counter = Metric.Counter("ConcurrentRequests", Unit.Requests);

    public void Request(int i)
    {
        this.counter.Increment();
        using (this.timer.NewContext()) // measure until disposed
        {
            // do some work
        }
        this.counter.Decrement();
    }
}

译自:https://github.com/Recognos/Metrics.NET/wiki/Getting-Started

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值