Coder Social home page Coder Social logo

dy-agent's Introduction

dy-agent

  • 基于Bytebuddy字节码增强技术及Java Agent实现的无侵入式AOP框架
  • 借鉴skywalking的设计原理开发,只保留最基本的match功能
  • 代码简单,容易直接上手二次开发

架构设计

  • dy-agent-core:核心功能代码,代码量不大,有兴趣可以瞧一瞧。
  • dy-agent-log4j:为了不与目标应用的日志框架产生冲突,自己实现的log4j。

如何添加新的拦截器

  • 继承AbstractMethodInterceptor类,需要override两个方法: focusOn 以及 match

focusOn

在focusOn中定义需要拦截的特定类,目前的matcher有NameMatchMultiNameOrMatch。可自己实现更多Matcher。

match

对类中的相应方法进行拦截。也可直接返回true,表示拦截所有方法。

Demo

参考DemoInterceptor编写拦截器,该类拦截了JDBC的两个实现,可以拦截到Mysql连接数据库的操作,控制台打印出connection url。

使用

mvn clean package后,将release下打包好的dy-agent-release-1.0-SNAPSHOT.jar添加到目标java应用启动参数中:-javaagent:path/of/dy-agent-release-1.0-SNAPSHOT.jar。应用如果产生JDBC连接,控制台即会打印出url。

注意事项

若编写的Interceptor没有实现效果,可检查TypeMatcher里面的ignoreRule(启动优化,避免扫描所有类)是否已经排除了目标类,手动删除即可。

dy-agent's People

Contributors

dependabot[bot] avatar foolwc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.