【微服务|Sentinel】簇点链路|微服务集群环境搭建

2022年7月11日 308点热度 0人点赞 0条评论

簇点链路

"簇点链路"中显示刚刚调用的资源(单机实时),簇点链路(单机调用链路)页面实时地去拉取指定客户端资源的运行情况。

它一共提供两种展示模式:一种用树状结构展示资源的调用链路,另外一种则不区分调用链路展示资源的运行情况。

注意: 簇点监控是内存态的信息,它仅展示启动后调用过的资源。

默认以树状视图展示

图片
  • 列表展示了该服务下所有的接口,包括通过QPS,拒接QPS,线程数,平均RT,分钟通过,分钟拒绝。
  • 172.20.10.3:8721 为当前的服务ip地址,端口为服务于sentinel控制台的交互的端口,服务本地会起一个该端口占用的HttpServer,该Server会与sentinel控制台做交互,比如sentinel控制台添加了一个限流规则,会把规则数据push给这个HttpServer接收,HttpServer再将规则注册到Sentinel中。
  • 可以对当前的资源添加流控、降级、热点、授权等操作。

列表视图:图片

我们可以看到在操作列表下,有流控、降级、热点、授权等选项。

接下来,我们将对上述功能做详细的介绍。

测试环境(微服务集群)

父pom文件

        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>

代码结构一览

图片

生产者多节点部署

图片

生产者

/**
 * 生产者controller
 *
 * @author issa
 **/

@RefreshScope
@RequestMapping(value = "/producer")
@RestController
public class ProducerController {

    @GetMapping("/{id}")
    @SentinelResource("test")
    public String producerById(@PathVariable(value = "id") String id) {

        ProducerVO producerVO = new ProducerVO();
        producerVO.setId(id);
        producerVO.setPort(UUID.randomUUID().toString());

        return producerVO.toString();
    }
}

生产者启动类

/**
 * 生产者
 *
 * @author issa
 **/

@EnableDiscoveryClient
@SpringBootApplication
public class ProducerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProducerApplication.classargs);
    }

}

消费者

/**
 * 消费者controller
 *
 * @author issavior
 **/

@RequestMapping(value = "/consumer")
@RestController
@RefreshScope
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProducerFeign producerFeign;

    @GetMapping("/rest/{id}")
    @SentinelResource("rest")
    public String restConsumerById(@PathVariable(value = "id") String id) {

        return restTemplate.getForObject("http://ossa-service-producer/producer/" + id, String.class);
    }

    @GetMapping("/feign/{id}")
    @SentinelResource("feign")
    public String feignConsumerById(@PathVariable(value = "id") String id) {

        return producerFeign.producerById(id);
    }
}

消费者启动类

/**
 * 消费者
 *
 * @author issavior
 */

@EnableFeignClients("com.ossa.common.feignapi")
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.classargs);
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {

        return new RestTemplate();
    }
}

feignapi

/**
 * @author issavior
 */

@FeignClient(value = "ossa-service-producer")
@RequestMapping(value = "/producer")
public interface ProducerFeign {

    /**
     * 根据ID查询商品
     *
     * @param id 商品的主键ID
     * @return 相关商品的信息
     */

    @GetMapping("/{id}")
    String producerById(@PathVariable(value = "id") String id);
}

16020【微服务|Sentinel】簇点链路|微服务集群环境搭建

root

这个人很懒,什么都没留下

文章评论