pinpoint中agent加载初始化

pinpoint中agent加载初始化

1、程序的入口是在PinpointBootStrap文件的permain函数
pinpoint中agent加载初始化
2、在permain函数中定义了一个classPathResolver,这是一个类路径解析类,从该类中可以读取Java类路径(java.class.path)、pinpoint-bootstrap-1.6.1.jar、pinpoint-commons-1.6.1.jar、pinpoint-bootstrap-core-1.6.1.jar、pinpoint-bootstrap-core-optional-1.6.1.jar、pinpoint-annotations-1.6.1.jar以及文件后缀属性,这几个文件都是BootstrapJarFile,最后都加入到instrumentation中,最后执行newPinpointStarter(agentArgsMap,bootstrapJarFile,classPathResolver,instrumentation)实例化PinpointStarter,之后启动Agent开始监控。

3、在PinpointStarter类中的start函数中,首先获取agentId、applicationName,然后解析插件路径,config文件路径、lib文件库,最后设置实例化启动类,初始化类参数,最后启动类,这个启动类就是DefaultAgent类。

4、在DefaultAgent类中,主要是定义this.applicationContext = newApplicationContext(agentOption,interceptorRegistryBinder);这句实例化应用内容,在start函数中启动applicationContext,实际上时调用了DefaultApplicationContext的start函数,这个start函数中有两句话this.agentInfoSender.start() 启动Agent信息发送;this.agentStatMonitor.start(); 启动Agent状态监控。

5、agentInfoSender类中定义了一个scheduleWithFixedDelay线程池,handel内容主要是AgentInfoSender.this.dataSender.request(this.agentInfo, this.agentInfoSenderListener);这句话,其中AgentInfo是通过createTAgentInfo获取的监控数据,包括createTServiceInfo还有createTJvmInfo,agentInfoSenderListener是一个发送监听器。具体的通讯过程是通过netty Thrift实现的。agentStatMonitor类中定义了一个scheduleAtFixedRate线程池,处理的内容主要是发送状态信息。

链接:https://www.jianshu.com/p/9e6f1b97d041