GithubHelp home page GithubHelp logo

byte-buddy-agent-example's Introduction

这个项目是使用byte buddy项目来做的一个简单的agent项目,方便了解byte buddy的一些基本使用方法

Demo的目的:

这个项目目的是来完成对于用springboot启动的项目进行一些监控,主要是通过在一些常用包的关键方法前后加入一些统计代码,这样可以无侵入式的进行监控。

目前尝试修改的包:

  • redis
  • mysql
  • okhttp
  • jersey
  • thrift
  • 自定注解

使用的方式

  • byte buddy包中的 build.method(...).intercept(...)
  • byte buddy包中的 advice注解

对于上面的两种方式,项目都有个简单的代码来展示一些基本的用法。(目前代码还有待整理)

区别

  • build.method(...).intercept(...) 这种方式其实是对真实的方法做了一层代理, 这种方式会影响代码的执行流。但是使用起来相对比advice注解更加直接和方便。 并且这种方式可以很方便的进行调试,方便于代码的开发

  • advice注解 这种方式是在启动的时候,通过asm来注入字节码,这种方式是不会影响和改变原始代码的执行流, 并且在初始化的时候就把相关注解的代码植入到字节码中。

性能

上面两种方法性能方面具byte buddy的作者说应该是差不多的。但是我本人还是建议使用advice注解的方式来进行开发。

启动方式

  • 使用-javaagent:/path/to/myagent.jar 通过premain来修改字节码(完全不侵入代码)
  • 使用byte buddy agent这个包, 在程序启动以后动态的修改字节码(基于统一的框架,在框架内部无痕启动)

byte-buddy-agent-example's People

Contributors

dragontree101 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.