前言

.net core 2.* 实施性能监控

这个工具其实给运维 大大们用起来是更爽的。但是Grafana现在还没有找到中文版。

本文需要了解的相关技术与内容:

InfluxDb(分布式时序数据库,开源)(注:分布式部分已商业化最新的分布式版本已不在开源,单例的继续开源)

Grafana(开源的,功能齐全的度量仪表盘和图形编辑器)

App Metrics(主角,开源的支持.NET Core的监控插件,采用管道注入的方式,对代码的入侵性极小)

效果图

安装influxdb

influxdb在1.*版本之后就不再有网页版本了。

所以大家选择版本的时候一定要注意这个事情免得找不到influxdb 的 admin控制台

下载地址

https://dl.influxdata.com/influxdb/releases/influxdb-1.6.3_windows_amd64.zip

我这里选择的是1.6.3版本

解压文件夹之后进行如下配置,打开config中的配置文件

修改如下几项目

[meta]
# Where the metadata/raft database is stored
dir = "D:/influxdb/meta"
[data]
# The directory where the TSM storage engine stores TSM files.
dir = "D:/influxdb/data"
# The directory where the TSM storage engine stores WAL files.
wal-dir = "D:/influxdb/wal"

如果使用的是1.*之前的版本就可以打开admin控制台

配置是这样的

[admin]
# Determines whether the admin service is enabled.
enabled = true # The default bind address used by the admin service.
bind-address = ":8083"

然后运行influxdb

influxd -config influxdb.conf

运行起来之后就是这个样子

好多 人都使用了1.*之后的版本,没有admin控制台给大家 推荐一个工具

InfluxDBStudio-0.1.0  用这个货创建一个数据库就可以了

配置Grafana

下载地址:

https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.3.1.windows-amd64.zip 

解压之后 在文件夹之后直接运行这个程序

grafana-server.exe

Grafana默认会监听3000的端口,所以我们进入

http://127.0.0.1:3000,
默认账号密码:admin admin

就是这样的效果啦

安装默认的模板

地址如下:https://grafana.com/dashboards/2125

这里选择刚才我们下载的json文件就可以,或者直接输入2125都可以

添加数据库配置文件

配置好了之后就会出现这个样子了

在.net core配置

先把这些DLL引用了吧。项目右键编辑帖进去  重新生成一下就可以了。

    <PackageReference Include="App.Metrics" Version="2.1.0" />
<PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="2.0.0" />
<PackageReference Include="App.Metrics.AspNetCore.Reporting" Version="2.0.0" />
<PackageReference Include="App.Metrics.AspNetCore.Tracking" Version="2.0.0" />
<PackageReference Include="App.Metrics.Extensions.Reporting.InfluxDB" Version="1.2.0" />
<PackageReference Include="App.Metrics.Formatters.Json" Version="2.1.0" />
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="2.0.0" />

修改appsettings.json配置文件

{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"InfluxDB": {
"IsOpen": true,
"DataBaseName": "LogDb",
"ConnectionString": "http://127.0.0.1:8086",
"username": "admin",
"password": "xxxxxxxxxx",
"app": "LogDbDemo",
"env": "stage"
}
}

修改startup进行管道接管

ConfigureServices添加 如下

            #region Metrics监控配置
string IsOpen = Configuration.GetSection("InfluxDB")["IsOpen"].ToLower();
if (IsOpen == "true")
{
string database = Configuration.GetSection("InfluxDB")["DataBaseName"];
string InfluxDBConStr = Configuration.GetSection("InfluxDB")["ConnectionString"];
string app = Configuration.GetSection("InfluxDB")["app"];
string env = Configuration.GetSection("InfluxDB")["env"];
string username = Configuration.GetSection("InfluxDB")["username"];
string password = Configuration.GetSection("InfluxDB")["password"]; var uri = new Uri(InfluxDBConStr); var metrics = AppMetrics.CreateDefaultBuilder()
.Configuration.Configure(
options =>
{
options.AddAppTag(app);
options.AddEnvTag(env);
})
.Report.ToInfluxDb(
options =>
{
options.InfluxDb.BaseUri = uri;
options.InfluxDb.Database = database;
options.InfluxDb.UserName = username;
options.InfluxDb.Password = password;
options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
options.HttpPolicy.FailuresBeforeBackoff = 5;
options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
options.FlushInterval = TimeSpan.FromSeconds(5);
})
.Build(); services.AddMetrics(metrics);
services.AddMetricsReportScheduler();
services.AddMetricsTrackingMiddleware();
services.AddMetricsEndpoints(); }
#endregion

Configure添加这些东西

      #region 注入Metrics
string IsOpen = Configuration.GetSection("InfluxDB")["IsOpen"].ToLower();
if (IsOpen == "true")
{
app.UseMetricsAllMiddleware();
// Or to cherry-pick the tracking of interest
app.UseMetricsActiveRequestMiddleware();
app.UseMetricsErrorTrackingMiddleware();
app.UseMetricsPostAndPutSizeTrackingMiddleware();
app.UseMetricsRequestTrackingMiddleware();
app.UseMetricsOAuth2TrackingMiddleware();
app.UseMetricsApdexTrackingMiddleware(); app.UseMetricsAllEndpoints();
// Or to cherry-pick endpoint of interest
app.UseMetricsEndpoint();
app.UseMetricsTextEndpoint();
app.UseEnvInfoEndpoint();
}
#endregion

运行项目跑一圈之后 返回Grafana就出现了这样的图例

.Net Core 2.*+ InfluxDB+Grafana+App Metrics实时性能监控的更多相关文章

  1. 使用App Metrics实现性能监控

    App Metrics监控需要安装InfluxDB时序数据库和Grafana可视化分析工具 1.安装InfluxDB 下载地址:https://portal.influxdata.com/downlo ...

  2. .Net Core 2.0+ InfluxDB+Grafana+App Metrics 实现跨平台的实时性能监控

    最近这段时间一直在忙,没时间写博客,负责了一个项目,从前端到后端一直忙,同时还有其他第几个项目的系统架构要处理. 去年就开始关注net core了,只是平时写写demo,没用在项目中,正好这次机会就用 ...

  3. 基于 Njmon + InfluxDB + Grafana 实现性能指标实时可视监控

    引言 最近逛 nmon 官网时,发现了一个新工具 njmon,功能与 nmon 类似,但输出为 JSON 格式,可以用于服务器性能统计. 可以使用 njmon 来向 InfluxDB 存储服务器性能统 ...

  4. 【jmeter】基于InfluxDB&Grafana的JMeter实时性能测试数据的监控和展示

    本文主要讲述如何利用JMeter监听器Backend Listener,配合使用InfluxDB+Grafana展示实时性能测试数据 关于JMeter实时测试数据 JMeter从2.11版本开始,命令 ...

  5. jmeter --- 基于InfluxDB&Grafana的JMeter实时性能测试数据的监控和展示

    转自:https://blog.csdn.net/RickyOne_RR/article/details/50637839 本文主要讲述如何利用JMeter监听器Backend Listener,配合 ...

  6. 转:基于InfluxDB&Grafana的JMeter实时性能测试数据的监控和展示

    本文主要讲述如何利用JMeter监听器Backend Listener,配合使用InfluxDB+Grafana展示实时性能测试数据 关于JMeter实时测试数据 JMeter从2.11版本开始,命令 ...

  7. .NetCore使用skywalking实现实时性能监控

    一.简介 很久之前写了一篇 <.Net Core 2.0+ InfluxDB+Grafana+App Metrics 实现跨平台的实时性能监控>关于NetCore性能监控的文章,使用Inf ...

  8. [#] - .Net平台的实时性能监控

    App Metricshttps://www.app-metrics.io ASP.NET Core之跨平台的实时性能监控http://www.cnblogs.com/GuZhenYin/p/7170 ...

  9. 搭建jmeter+influxdb+grafana压测实时监控平台(超详细,小白适用)

    1.前言 在使用jmeter做性能测试的时候,监控系统性能的时候,无论是使用插件还是报告生成,都没法实现实时监控.使用JMeter+Influxdb+Grafana可以实现实时监控. 本次环境搭建各软 ...

随机推荐

  1. 编译teamtalk遇到的问题

    一.编译log4cxx遇到的问题 1.error: narrowing conversion 这是在gcc-6下面一个官方的错误 解决方法 https://issues.apache.org/jira ...

  2. R中数据的输入和数据的标注

    数据的导入 默认情况下数据导入时,字符型变量将转化为因子.若不希望转化,可设置 stringsAsFactors=FALSE 从带分隔符的文本文件中导入数据 read.table() file --& ...

  3. 本地安装mysql脚本

    [root@tianyun ~]# vim mysql_install.sh #!/usr/bin/env bash #mysql install 2 #by tianyun #yum 配置yum源 ...

  4. mybatis标签selectkey无法返回主键值

  5. x86—EFLAGS寄存器详解[转]

    鉴于EFLAGS寄存器的重要性,所以将这一部分内容从处理器体系结构及寻址模式一文中单独抽出另成一文,这部分内容主要来自Intel Developer Mannual,在后续的内核系列中遇到的许多和EF ...

  6. VUE项目引入jquery

    既然写项目,那么少不了用jq,那我们就引入进来吧 1.因为已经安装了vue脚手架,所以需要在webpack中全局引入jquery 打开package.json文件,在里面加入这行代码,jquery后面 ...

  7. c 判断一个字符是否为字母数字

    #include <stdio.h> #include <wctype.h> int main () { int i; wchar_t str[] = L"c3po. ...

  8. python 输出三角形

    pattern = input("请输入你要选择的模式:") while True: if pattern == "A": row = eval(input(& ...

  9. CF892D—Gluttony(思维,好题)

    http://codeforces.com/contest/892/problem/D D. Gluttony You are given an array a with n distinct int ...

  10. 【java设计模式】-07适配器模式

    适配器模式 定义: 将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 类型: 结构型模式 应用实例: 1.JAVA JDK 1.1 提供 ...