miniprofiler的对数据库的监测使用。以nancy,petapoco为例
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为例的更多相关文章
- Atitit.软件仪表盘(4)--db数据库子系统-监测
Atitit.软件仪表盘(4)--db数据库子系统-监测 连接数::: 死锁表列表:死锁基础列表(最近几条记录,时间,sql等) 3.对服务器进行监控,获取CUP,I/O使用情况 4.对数据库进行 ...
- 数据库性能监测工具——SQL Server Profiler
使用SQL Server Profiler 进行sql监控需要一些设置: 其他的就是进行分析了~ 清除SQL SERVER缓存 常用的方法: DBCC DROPCLEANBUFFERS 从缓冲池中删除 ...
- mysql数据库数据监测
#!/bin/bash MYSQL="mysql -h10.10.10.10 -P8036 -uusername -ppassword --default-character-set=utf ...
- Oracle数据库无法向listener注册的解决一例
当机器的IP地址改变了,或者机器名改变后, 动态注册可能会失败. 运行 lsnrctl status时,无论等待多久,都会发生:no services 这样的信息. 此时,最好的解决方法,就是删除原有 ...
- MySQL数据库字符集由utf8修改为utf8mb4一例
对于mysql 5.5 而言,如果不设定字符集,mysql默认的字符集是 latin1 拉丁文字符集: 为了统一管理和应用开发的方便,一般都会统一将操作系统,客户端,数据库各方面的字符集都设置为 ut ...
- java操作数据库,以页面显示学生信息为例
该部分内容实现的功能主要是:从数据库中查询数据并展示到页面,在页面中新增数据信息,在页面中修改数据信息,在页面中删除数据信息. =================stuList.jsp======== ...
- 【原创】相对完整的一套以Jmeter作为工具的性能测试教程(接口性能测试,数据库性能测试以及服务器端性能监测)
准备工作 jmeter3.1,为什么是3.1,因为它是要配合使用的serveragent所支持的最高版本,下载链接 https://pan.baidu.com/s/1dWu5Ym JMeterPlug ...
- ABP使用Miniprofiler监测EF
在上篇教程中,我们在WebApi项目中集成了Miniprofiler,本篇文章中,将继续集成Miniprofiler EF6,以实时监测分析EF的执行语句.执行效率等.Miniprofiler会针对E ...
- PYTHON--定期监测服务器端口,并将结果写入MYSQL
定时监测服务器端口,然后将结果入写数据库. 监测用NC命令,入库就用PYTHON的MYSQL模块 再调一个基于函数的多线程... 妥妥的.. 是网上两个功能的合成.. 俺不生产代码,俺只是BAIDU的 ...
随机推荐
- Python程序的首行
>问题 >>在一些python程序中的首行往往能够看见下面这两行语句中的一句 >>>#!/usr/bin/Python >>>#!/usr/bin ...
- leetcode 155
题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...
- DNS 中的协议字段详细定义
DNS中的协议字段定义 Table of Contents 1 概述 2 DNS Classes 3 DNS OpCodes 4 DNS RCODEs 5 DNS Label Types 6 DNS资 ...
- Add&Delete WindowService
Part One-Add: Step4: Add the new service to windows service: $commandLine = 'D:\IMS\2.16.0.42-DataSe ...
- Jquery,jquery-cookie.js 做的点击记住用户名和密码!
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Application Engine
Exit(1) : Terminate the AE immediately and rollback all DB changes madeexit(0) : Terminate the AE im ...
- github android
作者:ruijun 链接:https://www.zhihu.com/question/37160415/answer/79569042 来源:知乎 著作权归作者所有,转载请联系作者获得授权. ### ...
- 编写ros串口节点,使用官方serial包
参考http://www.roswiki.com/read.php?tid=557&fid=39 1.通过sudo apt-get install ros-<distro>-ser ...
- redhat 更新 python 为 2.7.6
1. 下载 wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz 2. 解压,编译 tar zxvf Python-2.7.6.tgz ./ ...
- python之编写购物车(第二天)
作业: 编写购物车 具体实现了如下功能: 1.可购买的商品信息显示 2.显示购物车内的商品信息.数量.总金额 3.购物车内的商品数量进行增加.减少和商品的删除 4.用户余额的充值 5.用户购买完成进行 ...