All Projects → runcoding → metrics-spring-boot

runcoding / metrics-spring-boot

Licence: other
Spring Boot 基于Sentinel服务接口监控及其手自一体化限流

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
TSQL
950 projects

Projects that are alternatives of or similar to metrics-spring-boot

Springcloud Learning
Spring Cloud基础教程,持续连载更新中
Stars: ✭ 6,839 (+40129.41%)
Mutual labels:  sentinel
langx-java
Java tools, helper, common utilities. A replacement of guava, apache-commons, hutool
Stars: ✭ 50 (+194.12%)
Mutual labels:  aop
MethodBoundaryAspect.Fody
A Fody weaver which allows to decorate methods and hook into method start, method end and method exceptions.
Stars: ✭ 173 (+917.65%)
Mutual labels:  aop
Norns
dotnet core aop static weaving on roslyn
Stars: ✭ 23 (+35.29%)
Mutual labels:  aop
cosmos-snapshots
Automatic snapshots of the blockchain state
Stars: ✭ 71 (+317.65%)
Mutual labels:  sentinel
Lokie
iOS efficient AOP Library using C++ and libffi
Stars: ✭ 139 (+717.65%)
Mutual labels:  aop
Discovery
☀️ Nepxion Discovery is a solution for Spring Cloud with blue green, gray, route, limitation, circuit breaker, degrade, isolation, tracing, dye, failover 蓝绿、灰度、路由、限流、熔断、降级、隔离、追踪、流量染色、故障转移
Stars: ✭ 4,658 (+27300%)
Mutual labels:  sentinel
tiny4j
IOC, AOP, REST...
Stars: ✭ 15 (-11.76%)
Mutual labels:  aop
aitlas
AiTLAS implements state-of-the-art AI methods for exploratory and predictive analysis of satellite images.
Stars: ✭ 134 (+688.24%)
Mutual labels:  sentinel
hasor
Hasor是一套基于 Java 语言的开发框架,区别于其它框架的是 Hasor 有着自己一套完整的体系,同时还可以和先有技术体系做到完美融合。它包含:IoC/Aop容器框架、Web框架、Jdbc框架、RSF分布式RPC框架、DataQL引擎,等几块。
Stars: ✭ 938 (+5417.65%)
Mutual labels:  aop
pf-azure-sentinel
Parse pfSense/OPNSense logs using Logstash, GeoIP tag entities, add additional context to logs, then send to Azure Sentinel for analysis.
Stars: ✭ 24 (+41.18%)
Mutual labels:  sentinel
Lidea
大型分布式系统实时监控平台
Stars: ✭ 28 (+64.71%)
Mutual labels:  sentinel
app-xyo-nodejs
XYO Archivist/Diviner CLI
Stars: ✭ 41 (+141.18%)
Mutual labels:  sentinel
controller-logger
AOP based API logging for Spring Boot
Stars: ✭ 57 (+235.29%)
Mutual labels:  aop
LSFramework
手写山寨版spring学习aop、ioc思想的demo,没看过spring的源码,因为实在是太庞大了,参考部分网上博客及开源代码完成。
Stars: ✭ 53 (+211.76%)
Mutual labels:  aop
Springcloud
基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中
Stars: ✭ 6,997 (+41058.82%)
Mutual labels:  sentinel
Deflector.NET
A library for intercepting all method calls at runtime in nearly any .NET application.
Stars: ✭ 80 (+370.59%)
Mutual labels:  aop
Farseer.Net
Provides consistent standard use of common components of the .Net Core language
Stars: ✭ 42 (+147.06%)
Mutual labels:  aop
CSharpCampReCapProject
Kodlama.io | C# Camp | Recap Project | Car Rental System | 2021
Stars: ✭ 17 (+0%)
Mutual labels:  aop
CrmWebApi
🎉 CRM后台管理系统(后端 WebApi)
Stars: ✭ 13 (-23.53%)
Mutual labels:  aop

轻量级流量控制

基于Sentinel实现服务手自一体限流。

使用效果图

[演示视频](https://raw.githubusercontent.com/runcoding/static/master/wiki/pic/monitor.mov)

如何使用

步骤一:

<dependency>
   <groupId>com.runcoding</groupId>
   <artifactId>monitor-spring</artifactId>
   <version>1.0.0-SNAPSHOT</version>
</dependency>

步骤二:

spring:
  application:
    name: monitor-center  # 应用名称
  profiles:
    active: dev           # 运行环境(显示在钉钉消息中)

server:
  tomcat:
    max-threads:  100     # Reactor线程池最大线程数(目前使用的是tomcat)

# 哨兵限流配置支持与spring config结合的热更新方式。通过Eureka服务发现节点。注意刷新时会重启Eureka注册节点。
csp:
  sentinel:
    rules:
      system:            # 配置哨兵平台规则
        systemLoad: 10.0 # 配置最高系统加载平均值,是排队到可用处理器的可运行实体数目与可用处理器上可运行实体数目的总和在某一段时间进行平均的结果
        avgRt: 10000     # 平均RT时间(ms)
        qps:   1000      # 每秒接受处理的请求数
        maxThread: 200   # 最高并行执行线程数
    # http://tool.chinaz.com/Tools/unixtime.aspx
    authorityWhite: MonitorController.job(0)|1536595200000,OrderProducerService.send(2)|-1 #监控方法白名单(Unix时间单位ms,-1不设置过期时间,Unix时间 1536595200000 = 2018-09-11 00:00:00)
    authorityBlock: MonitorController.degrade(0)|-1 #监控黑名单方法
    isAutoRule:   true         # 是否自动开启限流
    maxLoadAverageRate: 0.95   # 最大的负载比例(当前正在运行的线程/容器最大数量),这里的容器默认指tomcat。超过后会进入打断执行线程判断
    isAutoInterrupt: true      # 是否自动打断执行线程(如果设置为false,maxRunTimeoutMillis和maxBlockTimeMillis配置将失效)
    maxRunTimeoutMillis: 10000 # 最长的方法执行时长(ms,默认10s),超过这个时间执行线程会被打断,并且加入到黑名单中
    maxBlockTimeMillis: 180000 # 加入黑名单时长(ms,默认3分钟)
    warnTimeoutMillis: 3000    # 调用请求超时3s,输出服务当前运行日志
    maxTardinessMillis: 500    # 超过这个时间(ms,默认0.5s)的请求,将在每小时被统计
    api:
     # port: 8099              # 服务向外暴露端口,供dashboard请求(不填不暴露),目前不建议使用
    dashboard:
     # server: localhost:8090  # dashboard 监控台地址,目前不建议使用
  webHook:
    # 钉钉文档 https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1
    dingTalk:
      atMobiles: 1580000000,158000001 #接受钉钉,通知需要被@的人
      accessToken: 84b2a8576d5193637 #钉钉通知机器人

eureka:   # 多节点部署需配置eureka,用做哨兵变更规则

具体可查看: SentinelWebConfig.java

@Resource
private MonitorProcessor monitorProcessor;

monitorProcessor.setWarnChatBot(chatBotSendLog());

/**自定义异常报警*/
public MonitorSendFunction chatBotSendLog(){
    return ((methodName, t, args) -> {
        if(!(t instanceof  RuntimeException)){
            return;
        }
        /**处理RuntimeException异常*/
        String throwablePackageName = t.getClass().getPackage().getName();
        if(StringUtils.startsWith(throwablePackageName,"java.lang") ||
           StringUtils.startsWith(throwablePackageName,"org.springframework")    ){
            boolean checkEnableSend = DTWebHookProcessor.checkEnableSend(methodName + t.getClass().getSimpleName());
            if(!checkEnableSend){
                return;
            }
            /**是否死锁*/
            boolean  isDeadlock = t instanceof DeadlockLoserDataAccessException;
            /**运行时异常*/
            DTWebHookProcessor.chatbotSendByMarkdown("运行时异常报警",
                   "## 服务在运行时出现了异常,请即时处理 \n - 服务:"+appName+"-"+ appEnv
                           +"\n - ip:"+HostNameUtil.getIp()
                           +"\n - 方法:"+methodName
                           +"\n - 参数:"+JSON.toJSONString(args)
                           + (isDeadlock ? "\n - 死锁: 当前执行出现了死锁" : "")
                           +"\n - error:"+t.toString()+"\n"+t.getMessage()
                           +"\n - 问题处理人:",
                   false);
       }
    });
}

自动流控规则与实现

SentinelRuleProcessor.java

  • 开启自动流控 isAutoRule = true

  • 自动流控:当处理线程大于最大线程池95%时,该运行方法将只有50%线程数的线程可以运行该方法。具体查看哨兵的FlowRule线程控制

  • 自动降级: 当方法执行时间>3s时,通过响应时间3s,阻塞2s的窗口时间。

  • 是否自动打断执行时间超过10s的线程,打断后加入黑名单三分钟。isAutoInterrupt = true

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].