利用Skywalking-netcore监控你的应用性能
Skywalking
SkyWalking开源项目由吴晟于2015年创建,同年10月在GitHub上作为个人项目开源。
SkyWalking项目的核心目标,是针对微服务、Cloud Native、容器化架构,提供应用性能监控(APM)和分布式调用链追踪能力。
2017年11月,SkyWalking社区正式决定,寻求加入Apache基金会,希望能使项目成为更为开放、全球化和强大的APM开源产品,并加强来自社区的合作和交流。最终实现构建一款功能强大、简单易用的开源APM产品。
2017年12月8日,Apache软件基金会孵化器项目管理委员会 ASF IPMC宣布“SkyWalking全票通过,进入Apache孵化器”。
什么是APM
APM = Application Performance Management,即应用性能管理,主要是针对企业级应用软件市场,对企业系统实施即时监控,以实现对应用程序性能管理和故障管理的系统化的解决方案。
APM的覆盖范围包括五个层次的实现:终端用户体验,应用架构映射,应用事务的分析,深度应用诊断,和数据分析。
过去,企业的IT部门在收集系统性能参数时,一般重点关注为最终用户提供服务的硬件组件的利用率,如CPU利用率、内存占用、网络吞吐量。虽然这种方法也提供了一些宝贵的信息,但却忽视了最重要的因素:最终用户的响应时间。
现在,通过事务处理过程监测、模拟等手段,可以真实测量用户响应时间,此外还可以报告谁正在使用某一应用、该应用的使用频率以及用户所进行的事务处理过程是否成功完成、发生错误时的参数与堆栈调用信息、数据库查询语句跟踪等。
.Net Core
自微软发布 .net core 2.0以来,.net开发者迎来了幸福的春天,我们的程序将不再局限于Windows平台。2.x版的.net core已趋于稳定,各厂的配套也在逐步跟上,使得整个生态在逐渐的丰富起来。
SkyWalking-netcore是.net core平台下的代理程序,在NCC社区的Lemon大神带领下进行开发,并于2018年4月17日正式加入OpenSkywalking,于2018年4月19日发布v0.1.0版本。
实验目标
布署一个基于SkyWalking的.net core应用监控系统,监控Web应用的性能。
所需第三方软件
XShell
WinSCP
Visual Studio 2017
.net Core 2.0.3 SDK
JDK8+
Elasticsearch 5.x
网络结构
本次实验采用三台服务器 ,Elasticsearch 与 Collector 放在一台服务器上,收集另外两台Web服务器提供的数据,实验应用架构如下图。
实验架构
实验过程
安装系统
Server-01、Web01、Web02安装 CentOS系统,安装过程详见《IT基础设施:CentOS7安装指南》
IP配置表
| 服务器 | IP | 备注 |
|---|---|---|
| Server-01 | 192.168.10.191 | 提供ES服务、Collector与WebUI |
| Web01 | 192.168.10.192 | 运行App1 |
| Web02 | 192.168.10.193 | 运行 App2 |
| MSSQL | 暂无 | 因.net Core的代理程序暂未提供支持,故本文不演示此部分,待新版本发布后更新 |
| WebService | 暂无 | 因.net Core的代理程序暂未提供支持,故本文不演示此部分,待新版本发布后更新 |
安装 .net core 2.0 SDK
在Web01、Web02上安装.net core 2.0 SDK,详见《在CentOS7下安装.Net Core 2.0.3 SDK》
安装JDK8
因为oracle现在要同意协议才能下载,直接使用wget加链接下载不到,所以要加上前面的那些代码:
wget --no-check-certificate --no-cookie --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.rpm
也可以先用迅雷下到主机,再通过局域网下载到虚拟机
使用rpm -ivh jdk-8u45-linux-x64.rpm进行安装
命令执行完毕即安装完成,使用java -version 检查是否安装成功
部署Elasticsearch
1、到官网下载5.x版,目前为5.6.9
下载5.x
2、使用WinSCP上传到Server-01,解压到/home/elasticsearch5.6.9下。
3、修改/home/elasticsearch5.6.9/config/elasticsearch.yml
设置
cluster.name: CollectorDBCluster。此名称需要和collector配置文件一致。设置
node.name: masterNode, 节点名称可以设置为任意名字,如为集群模式,则每个节点名称需要不同。
增加如下配置
cluster.name: CollectorDBClusternetwork.host: 0.0.0.0thread_pool.bulk.queue_size: 1000
最终配置如下:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#!/usr/bin/env sh
PRG="$0"
PRGDIR=`dirname "$PRG"`
[ -z "$WEBAPP_HOME" ] && WEBAPP_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
WEBAPP_LOG_DIR="${WEBAPP_HOME}/logs"
JAVA_OPTS=" -Xms256M -Xmx512M"
JAR_PATH="${WEBAPP_HOME}/webapp"
if [ ! -d "${WEBAPP_HOME}/logs" ]; then
mkdir -p "${WEBAPP_LOG_DIR}"
fi
_RUNJAVA=${JAVA_HOME}/bin/java
[ -z "$JAVA_HOME" ] && _RUNJAVA=java
eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} -jar ${JAR_PATH}/skywalking-webapp.jar \
--server.port=8080 --collector.ribbon.listOfServers=192.168.10.191:10800 \
2>${WEBAPP_LOG_DIR}/webapp.log 1> /dev/null &"
if [ $? -eq 0 ]; then
sleep 1
echo "Skywalking Web Application started successfully!"
else
echo "Skywalking Web Application started failure!"
exit 1
fi
运行/home/elasticsearch5.6.9/bin/elasticsearch.sh启动Elasticsearch
部署collector
下载release的版本https://github.com/OpenSkywalking/skywalking-netcore/releases
下载
将压缩包解压到Server-01的/home/collector/目录
修改
/home/collector/bin/webappService.sh中的127.0.0.1为Server-01的IP地址,目前为192.168.10.191。
最终脚本如下:
- # Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#!/usr/bin/env shPRG="$0"PRGDIR=`dirname "$PRG"`
- [ -z "$WEBAPP_HOME" ] && WEBAPP_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
- WEBAPP_LOG_DIR="${WEBAPP_HOME}/logs"JAVA_OPTS=" -Xms256M -Xmx512M"JAR_PATH="${WEBAPP_HOME}/webapp"if [ ! -d "${WEBAPP_HOME}/logs" ]; then
- mkdir -p "${WEBAPP_LOG_DIR}"fi_RUNJAVA=${JAVA_HOME}/bin/java
- [ -z "$JAVA_HOME" ] && _RUNJAVA=javaeval exec "\"$_RUNJAVA\" ${JAVA_OPTS} -jar ${JAR_PATH}/skywalking-webapp.jar \
- --server.port=8080 --collector.ribbon.listOfServers=192.168.10.191:10800 \
- 2>${WEBAPP_LOG_DIR}/webapp.log 1> /dev/null &"if [ $? -eq 0 ]; then
- sleep 1 echo "Skywalking Web Application started successfully!"else
- echo "Skywalking Web Application started failure!"
- exit 1fi
修改
/home/collector/config/application.yml中的所有localhost为Server-01的IP地址,目前为192.168.10.191。
最终配置文件如下:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the# "License");
you may not use this file except in compliance# with the License.
You may obtain a copy of the License at
## http://www.apache.org/licenses/LICENSE-2.0
## Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.#cluster:
# zookeeper:
# hostPort: localhost:2181
# sessionTimeout: 100000naming:jetty:host: 192.168.10.191port: 10800contextPath: /cache:# guava:caffeine:remote:gRPC:host: 192.168.10.191port: 11800agent_gRPC:gRPC:host: 192.168.10.191port: 11800#Set these two setting to open ssl#sslCertChainFile: $path#sslPrivateKeyFile: $path#Set your own token to active auth#authentication: xxxxxxagent_jetty:jetty:host: 192.168.10.191port: 12800contextPath: /analysis_register: default:analysis_jvm: default:analysis_segment_parser: default:bufferFilePath: ../buffer/bufferOffsetMaxFileSize: 10MbufferSegmentMaxFileSize: 500Mui:jetty:host: 192.168.10.191port: 12800contextPath: /storage:elasticsearch:clusterName: CollectorDBClusterclusterTransportSniffer: trueclusterNodes: localhost:9300indexShardsNumber: 2indexReplicasNumber: 0highPerformanceMode: truettl: 7#storage:# h2:
# url: jdbc:h2:~/memorydb
# userName: saconfiguration: default
:# namespace: xxxxxapplicationApdexThreshold: 2000serviceErrorRateThreshold: 10.00serviceAverageResponseTimeThreshold: 2000instanceErrorRateThreshold: 10.00instanceAverageResponseTimeThreshold: 2000applicationErrorRateThreshold: 10.00applicationAverageResponseTimeThreshold: 2000
运行/home/collector/bin/startup.sh启动WebUI和Collector。
创建WebApplication
接下来,我们创建一个Web应用,并在其中加入Skywalking for dotnet core的代理程序。
1、打开VS2017,创建一个.Net Core MVC应用,请跟着我操作:VS中点击菜单“文件”——“新建”——“项目”(按Ctrl+Shift+N同等效果),在弹出的对话框中从左到右进行如下操作。
.Net Core Web应用
选择项目类型
2、等项目建好,右键点击“依赖项”——“管理Nuget程序包”,打开Nuget管理器。
操作
在“浏览”选项卡,输入“Skywalking.AspNetCore”搜索,并安装
找到包
安装前需要接受许可证,点击“我接受”(不接受请关闭本文)
许可证
3、安装完成后,打开Startup.cs,在ConfigureServices函数中加入
services.AddSkyWalking(option =>{ //这里填本应用的名称,每个应用不同option.ApplicationCode = "OurApplication1";
//这里填Collector的地址option.DirectServers = "192.168.10.191:11800";});
Startup.cs完整代码如下
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using SkyWalking.AspNetCore;namespace WebApplication2{ public class Startup{public Startup(IConfiguration configuration){Configuration = configuration;} public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.public void ConfigureServices(IServiceCollection services){services.AddSkyWalking(option =>{ //这里填本应用的名称,每个应用不同option.ApplicationCode = "OurApplication1";
//这里填Collector的地址option.DirectServers = "192.168.10.191:11800";});services.AddMvc();} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.public void Configure(IApplicationBuilder app, IHostingEnvironment env){ if (env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseBrowserLink();} else{app.UseExceptionHandler("/Home/Error");}app.UseStaticFiles();app.UseMvc(routes =>{routes.MapRoute(name: "default",
template: "{controller=Home}/{action=Index}/{id?}");});}}}
打开Program.cs文件,允许非本地访问,最终代码如下
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;namespace WebApplication2
{ public class Program{public static void Main(string[] args){BuildWebHost(args).Run();} public static IWebHost BuildWebHost(string[] args) =>WebHost.CreateDefaultBuilder(args).UseUrls("http://*:5000").UseStartup<Startup>().Build();}}
4、发布:点击我们的WEB应用,右键——发布,接下来看图操作。
发布
发布到文件夹
选择目标位置
发布
没有失败,恭喜,大吉大利,今晚吃鸡
我们可以看到,发布完成后的文件,一大堆,我们把这个文件夹改名为App1
发布成功
5、接下来,我们在StartUp.cs中把ApplicationCode改一下,按上面的步骤再发布一次。
image.png
这次发布生成的Publish3文件夹,我们改名为App2
布署Web
1、打开WinSCP,连上Web01,将App1拖到/home下。
2、打开XShell,连上Web01,执行如下命令
# 关掉防火墙(生产环境不宜)systemctl stop firewalld
# 给予执行权限chmod 777 /home/App1/WebApplication2.dll
# 在后台运行应用nohup dotnet /home/App1/WebApplication2.dll &
同样的操作,将App2布署到Web02上。
访问应用
我们打开两个应用,随机点击一下应用顶部的链接。
http://192.168.10.192:5000,这是我们的app1
http://192.168.10.193:5000,这是我们的app2
查看监测
打开http://192.168.10.191:8080,查看监测情况
监测到的应用
查看被访问的服务响应速度
服务状态
结语
Skywalking-netcore做为.Net core社区的新生命,具有无限的潜力,据可靠消息,新版本将更深入地监测数据库操作及状态,HTTP请求消息以及StackTrace跟踪,让我们一起为它打Call加油吧。猛戮这里,到Github给Skywalking-netcore点星星。 :)
原文地址: https://www.jianshu.com/p/3ddd986c7581
利用Skywalking-netcore监控你的应用性能的更多相关文章
- Metrics.NET step by step使用Metrics监控应用程序的性能
使用Metrics监控应用程序的性能 在编写应用程序的时候,通常会记录日志以便事后分析,在很多情况下是产生了问题之后,再去查看日志,是一种事后的静态分析.在很多时候,我们可能需要了解整个系统在当前,或 ...
- 使用动态跟踪技术SystemTap监控MySQL、Oracle性能
[IT168 技术]本文根据吕海波2018年5月11日在[第九届中国数据库技术大会]上的演讲内容整理而成. 讲师介绍: 吕海波,美创科技研究员,ITPUB管理版版主.出版技术书籍<Oracle内 ...
- Atitit 如何利用先有索引项进行查询性能优化
Atitit 如何利用先有索引项进行查询性能优化 1.1. 再分析的话就是我们所写的查询条件,其实大部分情况也无非以下几种:1 1.2. 范围查找 动态索引查找1 1.2.1. 索引联合 所谓的索引联 ...
- 【阿里云产品公测】利用PTS服务优化网站数据库读写性能
[阿里云产品公测]利用PTS服务优化网站数据库读写性能 作者:阿里云用户千鸟 写这个帖子主要也是因为在用PTS测试网站的时候,手动访问网站进入报错页面,主要原因是数据库连接对象存在问题,导致并发多的时 ...
- 自学Zabbix4.1 zabbix监控web服务器访问性能
自学Zabbix4.1 zabbix监控web服务器访问性能 使用Zabbix实现对web性能的监控,通过它可以了解web站点的可用性以及性能.最终将各项指标绘制到图形中,这样我们可以了解到一个站点的 ...
- 利用Linux文件系统内存cache来提高性能
https://www.linuxjournal.com/article/6345 利用Linux文件系统内存cache来提高性能 本地磁盘文件->socket发送,4步骤数据流向: hard ...
- 【性能测试实战:jmeter+k8s+微服务+skywalking+efk】系列之:性能监控、分析、调优等
说明: 本文是基于虚拟机演示的,资源有限 skywalking中拓扑图 kubectl get po -A -owide 测试执行:单场景 查询礼品 jmeter -n -t gift.jmx -l ...
- 利用StopWatch类监控Java代码执行时间并分析性能
springframework中的StopWatch类可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.一般用来测量代码执行所用的时间或者计算性能数据,在优化代码性能上可以使用Sto ...
- AspNet Core下利用 app-metrics+Grafana + InfluxDB实现高大上的性能监控界面
在日常系统工作中,我们为了洞察系统的问题和运作情况通常会记录日志的方式来进行分析,但是在很多情况下都是被动的在出问题后才会去查日志.在很多时候,我们可能更需要相对实时的了解整个系统或者某一时段的运行的 ...
随机推荐
- JavaScript DOM 高级程序设计读书笔记一
创建可重用的对象 简而言之,对象就是包含一组变量(称为属性)和函数(称为方法)的集合的实例.对象通常由类派生而来,而类中定义了对象拥有的属性和方法.如果你的脚本中都是对象之间的交互操作,那么就可以称之 ...
- java的数组
作用:存储相同类型的一组数组,相当于一个容器,存放数据的.对同种数据类型集中存储.管理.便于遍历 数组类型:就是数组中存储的数据的类型 特点:数组中的所有元素必须属于相同的数据类型,数组中所有元素在内 ...
- BAT面试经验分享——iOS高级开发工程师的自我总结!
序言 目前形势,参加到iOS队伍的人是越来越多,甚至已经到供过于求了. 今年,找过工作人可能会更深刻地体会到今年的就业形势不容乐观,随着各大公司秋招的开始,很多小伙伴都行动起来了,我也有幸获得了一份不 ...
- 2017-12-19python全栈9期第四天第三节之iterable可迭代对象join之字符串和列表转换成字符串和range
#!/user/bin/python# -*- coding:utf-8 -*-s = 'zd's1 = '_'.join(s)print(s1)li = ['zs','ls','ww','zl',' ...
- 随机逻辑回归random logistic regression-特征筛选
python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...
- CentOS 7 安装docker (图文)
一定要用root账号登录系统,打开终端/或远程工具(如xshell)登录系统 检查是否已经安装命令 rpm –qa|grep docker 出现如上说明已安装 也可用命令docker -v (如 ...
- idea 错误: 找不到或无法加载主类
1.cmd进入项目目录 2.输入maven命令重构项目 mvn clean mvn idea:idea install
- file 自定义上传附件并展示缩略图
效果图镇楼.. 写的有点乱.上传一个实例供大家参考--附件下载地址如何下: https://files.cnblogs.com/files/fchx91/uploadFiles.rar 2019- ...
- 通过Hack方式实现SDC中Stage配置联动刷新
目录 问题描述 如何从外部获取下拉列表参数 如何实现根据下拉列表选项动态刷新 总结 问题描述 最近项目组准备开发一个IoT平台项目,需要使用到StreamSets DataCollector组件进行数 ...
- Node的express配置使用ejs模板
注册ejs模板为html页.以.ejs为后缀的模板页,现在的后缀名可以是.html app.engine('.html', require('ejs').__express); 设置视图模板的默认后缀 ...