miniprofiler的使用


miniprofiler的详细介绍请看这里http://miniprofiler.com/。(可以对数据库和页面等监控如 ado ef mvc mongodb)

本文以nancy和petapoco为示例


安装

Install-Package MiniProfiler

你也可以使用其他的类库,如MiniProfiler.EF6 MiniProfiler.WCF MiniProfiler.MongoDb MiniProfiler.MongoDb之类的。我用的是petapoco,所以用Install-Package MiniProfiler就可以了

数据库部分

在petapoco.cs的类中修改如下

 public void OpenSharedConnection()
{
if (_sharedConnectionDepth == 0)
{
_sharedConnection = _factory.CreateConnection();
_sharedConnection.ConnectionString = _connectionString;
//MiniProfiler 加入MiniProfiler
_sharedConnection= new StackExchange.Profiling.Data.ProfiledDbConnection( (DbConnection) _sharedConnection , MiniProfiler.Current); if (_sharedConnection.State == ConnectionState.Broken)
{ _sharedConnection.Close(); } if (_sharedConnection.State == ConnectionState.Closed)
{ _sharedConnection.Open(); } _sharedConnection = OnConnectionOpened(_sharedConnection); if (KeepConnectionAlive)
{ _sharedConnectionDepth++; } // Make sure you call Dispose
} _sharedConnectionDepth++;
}

其实就是替换_sharedConnection= new StackExchange.Profiling.Data.ProfiledDbConnection( (DbConnection) _sharedConnection , MiniProfiler.Current);

官方的文档

public static DbConnection GetOpenConnection()
{
var cnn = CreateRealConnection(); // A SqlConnection, SqliteConnection ... or whatever // wrap the connection with a profiling connection that tracks timings
return new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);
}

Bootstrapper部分 RequestStartup的方法中如下:

  protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{ //MiniProfiler
MiniProfiler.Start();
//请求结束后,停止miniprofiler
pipelines.AfterRequest.AddItemToEndOfPipeline(
(ctx) =>
{
MiniProfiler.Stop();
});
}

module部分

假设你的module叫MiniProfiler。

主要字符串的编码。

  Get["/MiniProfiler"] = _ =>
{
var renderStr = StackExchange.Profiling.MiniProfiler.RenderIncludes().ToString();
return View["MiniProfiler", renderStr];
};

视图部分

主要字符串的编码。Html.Raw是htmldecode的作用

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{
Layout = null;
}
<!doctype html>
<html lang="zh-cn">
<head>
</head>
<body>
@Html.Raw(Model)
</body>
</html>

查看 http://localhost:9777/miniprofiler

结果类似如下

30.0 ms
6.6 ms
1.1 ms
17.5 ms
14114.3 ms
537.0 ms

点击进去可以查看加载时间。以及调用的sql语句等。

miniprofiler的对数据库的监测使用。以nancy,petapoco为例的更多相关文章

  1. Atitit.软件仪表盘(4)--db数据库子系统-监测

    Atitit.软件仪表盘(4)--db数据库子系统-监测 连接数::: 死锁表列表:死锁基础列表(最近几条记录,时间,sql等) 3.对服务器进行监控,获取CUP,I/O使用情况   4.对数据库进行 ...

  2. 数据库性能监测工具——SQL Server Profiler

    使用SQL Server Profiler 进行sql监控需要一些设置: 其他的就是进行分析了~ 清除SQL SERVER缓存 常用的方法: DBCC DROPCLEANBUFFERS 从缓冲池中删除 ...

  3. mysql数据库数据监测

    #!/bin/bash MYSQL="mysql -h10.10.10.10 -P8036 -uusername -ppassword --default-character-set=utf ...

  4. Oracle数据库无法向listener注册的解决一例

    当机器的IP地址改变了,或者机器名改变后, 动态注册可能会失败. 运行 lsnrctl status时,无论等待多久,都会发生:no services 这样的信息. 此时,最好的解决方法,就是删除原有 ...

  5. MySQL数据库字符集由utf8修改为utf8mb4一例

    对于mysql 5.5 而言,如果不设定字符集,mysql默认的字符集是 latin1 拉丁文字符集: 为了统一管理和应用开发的方便,一般都会统一将操作系统,客户端,数据库各方面的字符集都设置为 ut ...

  6. java操作数据库,以页面显示学生信息为例

    该部分内容实现的功能主要是:从数据库中查询数据并展示到页面,在页面中新增数据信息,在页面中修改数据信息,在页面中删除数据信息. =================stuList.jsp======== ...

  7. 【原创】相对完整的一套以Jmeter作为工具的性能测试教程(接口性能测试,数据库性能测试以及服务器端性能监测)

    准备工作 jmeter3.1,为什么是3.1,因为它是要配合使用的serveragent所支持的最高版本,下载链接 https://pan.baidu.com/s/1dWu5Ym JMeterPlug ...

  8. ABP使用Miniprofiler监测EF

    在上篇教程中,我们在WebApi项目中集成了Miniprofiler,本篇文章中,将继续集成Miniprofiler EF6,以实时监测分析EF的执行语句.执行效率等.Miniprofiler会针对E ...

  9. PYTHON--定期监测服务器端口,并将结果写入MYSQL

    定时监测服务器端口,然后将结果入写数据库. 监测用NC命令,入库就用PYTHON的MYSQL模块 再调一个基于函数的多线程... 妥妥的.. 是网上两个功能的合成.. 俺不生产代码,俺只是BAIDU的 ...

随机推荐

  1. Python之路----------ConfigParser模块

    Python的ConfigParser 废话不说,拿去用 #coding=utf-8 import configparser ''' 基於Python3.0版本寫的配置文件的創建.增加.刪除.修改等方 ...

  2. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版新增查询引擎管理

    欲了解V3.0版本的相关内容可查看下面的链接地址. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版本发布 RDIFramework.NET — 基于.NET的快速信 ...

  3. php计算字符串长度

    /** * 计算字符串的长度(非字节) * 先用正则将字符串分解为个体单元,然后再计算单元的个数即得出字符串的长度 * from wordpress * @param string $string * ...

  4. ko trick

    (1)let a = ko.observable(‘A’)绑定到select,如果下拉列表中找不到'A', 变量a会赋值成undefined.   要解决此问题可以使用绑定valueAllowUnse ...

  5. AutoBundle in asp.net mvc 5

    using System.Collections.Concurrent; using System.Text; namespace System.Web.Optimization { public s ...

  6. Windows Server 2008 任务计划无法自动运行的解决办法

    问题:编写的bat脚本,直接执行,成功:但是在任务管理器中配置该任务,运行不成功,结果显示为:0x1,系统环境为 Windows Server 2008. 分析:bat任务没有调用执行. 解决方案: ...

  7. 在线免费生成 <IDEA>全系列 注册码

    body { background: #fff; color: #333; font-family: Consolas, sans-serif; margin: 2em auto; width: 70 ...

  8. 使用git 更新线上代码

    先本地代码合并://1合并分支git branch//2查看taggit tag //3添加tagcloud_crm]$ git tag -a v1.0.2 -m "0902"// ...

  9. python中遍历文件的3个方法

    转自: http://www.jb51.net/article/54640.htm 用python进行文件遍历有多种方法,这里列举并说明一下. os.path.walk() 这是一个传统的用法. wa ...

  10. centos安装mono

    1.查看mono最新版本 http://download.mono-project.com/sources/mono 2.安装依赖环境 sudo yum install cmake automake ...