Spring Cloud之服务监控turbine的示例
作者:冰清雪酷 发布时间:2023-04-20 23:26:44
标签:Spring,Cloud,turbine
turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务。
新建turbine项目
TurbineApplication.java
package turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
/**
* Created by sai.luo on 2017/4/26.
*/
@SpringBootApplication
@EnableTurbine
@EnableHystrix
@EnableHystrixDashboard
public class TurbineApplication{
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class,args);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>turbine</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- hystrix依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<!-- turnbine依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
spring:
application:
name: turbine
server:
port: 8000
turbine:
app-config: hello,helloClient ##需要监控的服务名
aggregator:
clusterConfig: main ##需要监控的服务集群名
clusterNameExpression: metadata['cluster']
eureka:
instance:
preferIpAddress: true
statusPageUrlPath: /info.html
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
启动服务
helloserviceeureka 项目 appliation.yml 增加集群配置
更改为
spring:
application:
name: hello
server:
port: 9001
eureka:
instance:
lease-renewal-interval-in-seconds: 3
lease-expiration-duration-in-seconds: 5
metadata-map:
cluster: main
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
registry-fetch-interval-seconds: 3
logging:
level:
com:
netflix:
eureka: OFF
discovery: OFF
pom.xml增加hystrix依赖包
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
同理ribboneureka 项目 application.yml 增加集群配置
更改后如下
spring:
application:
name: helloClient
server:
port: 20000
eureka:
instance:
lease-renewal-interval-in-seconds: 3
lease-expiration-duration-in-seconds: 5
metadata-map:
cluster: main
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
registry-fetch-interval-seconds: 3
logging:
level:
com:
netflix:
eureka: OFF
discovery: OFF
pom.xml增加hystrix依赖包
RibbonEurekaApplication.java 增加注解
@EnableHystrix
启动项目
访问 localhost:8000/hystrixx 可以看到页面
注: turbine只能监控hystrix服务,不是hystrix服务,不能监控,如 hello这个服务虽然配置了集群,但是没有使用hystrix,所以不会受监控。
项目地址 https://github.com/luosai001/Spring-Cloud-Sample/tree/master
来源:https://blog.csdn.net/luosai19910103/article/details/70820904
0
投稿
猜你喜欢
- 本文介绍一些Java初学者常问的问题,可以用%除以一个小数吗? a += b 和 a = a + b 的效果有区别吗? 声明一个数组为什么需
- maven没有打包xml文件的问题最近使用maven带管理项目,采用SSM的技术栈,在配置好一些配置文件,打包部署到tomcat上,出现没有
- 楼主大菜鸟一只,第一次写技术博客,如果有概念错误或代码不规范的地方,还请各位多多批评指正。话不多说,来看题:前一阵子开发了一个用户控件,里面
- 前言C# 11 中即将到来一个可以让重视性能的开发者狂喜的重量级特性,这个特性主要是围绕着一个重要底层性能设施 ref 和 struct 的
- 我们经常要将数字进行格式化,比如取2位小数,这是最常见的。Java 提供DecimalFormat类,帮你用最快的速度将数字格式化为你需要的
- disruptor不过多介绍了,描述下当前的业务场景,两个应用A,B,应用 A 向应用 B 传递数据 . 数据传送比较快,如果用http直接
- 模糊查询Spring Data Jpa的使用可以减少开发者对sql语句的编写,甚至完全不需要编写sql语句。但是,开发过程中总会遇到各种复杂
- 1. 异常1.1 try…catch异常处理try catch的异常处理的格式写法 :try{ &nbs
- 一、前言使用动态配置的原因: properties 和 yaml 是写到项目中的,好多时候有些配置需要修改,每次修改就要重新启动项目,不仅增
- 直接调用Math里面的random即可,简单方便int i = (int)(Math.random()*100+1);
- 本文主要介绍了Spring Boot 应用可视化监控,分享给大家,具体如下:1、Spring Boot 应用暴露监控指标【版本 1.5.7.
- 什么是 Spring Boot 插件?Spring Boot 插件是一种扩展机制,它提供了一种简单的方式来扩展 Spring Boot 的功
- Java阻塞队列阻塞队列和普通队列主要区别在阻塞二字:阻塞添加:队列已满时,添加元素线程会阻塞,直到队列不满时才唤醒线程执行添加操作阻塞删除
- 1、引入依赖<dependency> <groupId>org.apache.pdfbox</gr
- 这篇文章主要介绍了java 读取系统Properties代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值
- 这篇文章主要介绍了Spring整合Dubbo框架过程及原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- 前言JDK 1.5 之前 synchronized 的性能是比较低的,但在 JDK 1.5 中,官方推出一个重量级功能 Lock,一举改变了
- 1 请求映射 在SpringBoot中使用@XxxMapping注解完成前端请求与后端方法的一个映射。以前的时候,通常使用url映射命名的
- Handler是用于操作线程内部的消息队列的类。这有点绕,没关系,我们慢慢的来讲。前面Looper一篇讲到了Looper是用于给线程创建消息
- 本文实例为大家分享了java实现人员信息管理系统的具体代码,供大家参考,具体内容如下实现增删改查.java入门的练手小程序1.Person类