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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 详解Spring Cloud 断路器集群监控(Turbine)

    一. 简介 上一篇文章我们已经实现了对单个服务实例的监控,当然在实际应用中,单个实例的监控数据没有多大的价值,我们更需要的是一个集群系统的监控信息,这时我们就需要引入Turbine.Turbine能够汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控. 二. 构建监控局和服务 2.1 整体结构与准备 本文的工程实现是基于上一篇文章的工程,通过引入Turbine来聚合service-ribbon服务的监控信息,并输出给Hystrix Dashboard来进行展示

  • 微服务搭建集成Spring Cloud Turbine详解

    1.概述 本文中,我将向你介绍Spring Cloud Netflix Turbine.它将多个Hystrix Metrics Streams 聚合为一个,以便显示在一个仪表板视图中. 简要介绍Hystrix . 在微服务架构中,我们有许多小应用程序相互通信以完成请求.这些下游服务有可能无法正确响应或完全失败.为了防止发生级联故障,我们为微服务设置了Hystrix回退机制. 每个实现Hystrix的微服务都可以选择公开Hystrix Metrics Streams(通过actuator端点/hy

  • spring cloud 的监控turbine-rabbitmq的示例

    前提是你已经有了注册中心,然后搭建一个基础spring cloud 服务,并配置注册服务等等前提环境搭建 接下来描述的服务提供者和服务调用者的配置都是一样的,来自<spring cloud 与 docker微服务架构实战>的读后的个人总结. pom文件中需要引入spring-cloud-starter-hystrix/spring-cloud-starter-hystrix-dashboard/spring-cloud-netflix-hystrix-stream/spring-cloud-s

  • Spring Cloud之服务监控turbine的示例

    turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过turbine来监控集群下hystrix的metrics情况,通过eureka来发现hystrix服务. 新建turbine项目 TurbineApplication.java package turbine; import org.springframework.boot.SpringApplication; import org.springframework.boo

  • Spring Cloud Gateway 服务网关快速实现解析

    Spring Cloud Gateway 服务网关 API 主流网关有NGINX.ZUUL.Spring Cloud Gateway.Linkerd等:Spring Cloud Gateway构建于 Spring 5+,基于 Spring Boot 2.x 响应式的.非阻塞式的 API.同时,它支持 websockets,和 Spring 框架紧密集成,用来代替服务网关Zuul,开发体验相对来说十分不错. Spring Cloud Gateway 是 Spring Cloud 微服务平台的一个子

  • 关于Spring Cloud的熔断器监控问题

    目录 Hystrix监控 actuator的监控节点 集成hystrix dashboard 监控详情解读 集成Turbine监控 参考 Hystrix监控 actuator的监控节点 在actuator下有用来监控hystrix的端点/actuator/hystrix.stream. 访问: http://localhost:9202/actuator/hystrix.stream 输出:(注意监控时需要请求@HystrixCommand配置的微服务) ping: data: {"type&q

  • 详解Spring Cloud Zuul 服务网关

    有了Eureka服务注册发现.Hystrix断路器.Ribbon服务调用负载均衡,以及spring cloud config 集群配置中心,似乎一个微服务框架已五脏俱全,last but not least,一个服务网关却不可或缺. Spring Cloud Zuul路由是微服务架构的不可或缺的一部分,提供动态路由,监控,弹性,安全等的边缘服务.Zuul是Netflix出品的一个基于JVM路由和服务端的负载均衡器. Zuul介绍 在整个Spring Cloud微服务框架里,Zuul扮演着"智能网

  • 详解Spring Cloud 跨服务数据聚合框架

    AG-Merge Spring Cloud 跨服务数据聚合框架 解决问题 解决Spring Cloud服务拆分后分页数据的属性或单个对象的属性拆分之痛, 支持对静态数据属性(数据字典).动态主键数据进行自动注入和转化, 其中聚合的静态数据会进行 一级混存 (guava). 举个栗子: 两个服务,A服务的某张表用到了B服务的某张表的值,我们在对A服务那张表查询的时候,把B服务某张表的值聚合在A服务的那次查询过程中 示例 具体示例代码可以看 ace-merge-demo 模块 |------- ac

  • Servlet+MyBatis项目转Spring Cloud微服务,多数据源配置修改建议

    一.项目需求 在开发过程中,由于技术的不断迭代,为了提高开发效率,需要对原有项目的架构做出相应的调整. 二.存在的问题 为了不影响项目进度,架构调整初期只是把项目做了简单的maven管理,引入springboot并未做spring cloud微服务处理.但随着项目的进一步开发,急需拆分现有业务,做微服务处理.因此架构上的短板日益突出.spring cloud config 无法完全应用,每次项目部署需要修改大量配置文件.严重影响开发效率,因此便萌生了对项目架构再次调整的决心. 三.调整建议 为了

  • spring Cloud微服务跨域实现步骤

    这篇文章主要介绍了spring Cloud微服务跨域实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 第一步:在gateway网关的配置文件中加上下面这些: ly: cors: allowedOrigins: - http://manage.leyou.com - http://xxx.xxx.com # 允许哪些网址就继续加,不要写 *,否则cookie就无法使用了 allowedCredentials: true # 代表携带cook

  • Spring Cloud 网关服务 zuul 动态路由的实现方法

    zuul动态路由 网关服务是流量的唯一入口.不能随便停服务.所以动态路由就显得尤为必要. 数据库动态路由基于事件刷新机制热修改zuul的路由属性. DiscoveryClientRouteLocator 可以看到DiscoveryClientRouteLocator 是默认的刷新的核心处理类. //重新加载路由信息方法 protected方法.需要子方法重新方法. protected LinkedHashMap<String, ZuulRoute> locateRoutes() //触发刷新的

  • 简单了解spring cloud 网关服务

    微服务 网关服务 网关服务是微服务体系里面重要的一环. 微服务体系内,各个服务之间都会有通用的功能比如说:鉴权.安全.监控.日志.服务调度转发.这些都是可以单独抽象出来做一个服务来处理.所以微服务网关应运而生.其主要作用作为微服务体系里面流量的唯一入口去做一些功能的实现. 微服务的网关担当的主要职责可以分为俩种 主要业务功能抽取,鉴权.安全.服务调度.限流.熔断等 非主要的业务功能抽取,监控.日志.缓存.黑白名单.埋点等 Spring Cloud 网关服务 现在市面主要流行的俩种 Netflix

  • Spring boot admin 服务监控利器详解

    目录 一.简介 二.搭建 1.服务端 2.客户端 3.启动项目 4.客户端配置 3.微服务 3.1.服务端 3.2.客户端 4.我的微服务预警发送其他服务状态信息思路 一.简介 用于对 Spring Boot 应用的管理和监控.可以用来监控服务是否健康.是否在线.以及一些jvm数据等等.Spring Boot Admin 分为服务端(spring-boot-admin-server)和客户端(spring-boot-admin-client),服务端和客户端之间采用 http 通讯方式实现数据交

随机推荐