? ? ? 綜合來看,pinpoint的源代碼主要由以下三部分組成:1宪哩、pinpoint Agent拾氓,這是數(shù)據(jù)的采集部分槐壳;2舶斧、pinpoint collector克滴,這是數(shù)據(jù)的額收集部分罐栈,并將數(shù)據(jù)存到Hbase中豪嗽;3媒役、pinpoint web祝谚,這是數(shù)據(jù)的圖像化展示部分,將結(jié)果數(shù)據(jù)展示到問界面以便監(jiān)控酣衷。
下面介紹 pinpoint-Agent部分:
1交惯、程序的入口是在PinpointBootStrap文件的permain函數(shù),這部分如果不懂得話可以查看java instrument部分穿仪,只要在監(jiān)控程序的VM option加入以下席爽,就可加入一個(gè)探針,探針的Agentid=pp20161122,applicationName=MyTestPP啊片。
-javaagent:E:/Java_Web/pinpoint-agent/target/pinpoint-bootstrap-1.6.1.jar -Dpinpoint.agentId=pp20161122 -Dpinpoint.applicationName=MyTestPP
2只锻、在permain函數(shù)中定義了一個(gè)classPathResolver,這是一個(gè)類路徑解析類紫谷,從該類中可以讀取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以及文件后綴屬性瞒窒,這幾個(gè)文件都是BootstrapJarFile捺僻,最后都加入到instrumentation中,最后執(zhí)行newPinpointStarter(agentArgsMap,bootstrapJarFile,classPathResolver,instrumentation)實(shí)例化PinpointStarter,之后啟動(dòng)Agent開始監(jiān)控匕坯。
3束昵、在PinpointStarter類中的start函數(shù)中,首先獲取agentId葛峻、applicationName锹雏,然后解析插件路徑,config文件路徑术奖、lib文件庫逼侦,最后設(shè)置實(shí)例化啟動(dòng)類,初始化類參數(shù)腰耙,最后啟動(dòng)類,這個(gè)啟動(dòng)類就是DefaultAgent類铲球。
4挺庞、在DefaultAgent類中,主要是定義this.applicationContext = newApplicationContext(agentOption,interceptorRegistryBinder);這句實(shí)例化應(yīng)用內(nèi)容稼病,在start函數(shù)中啟動(dòng)applicationContext选侨,實(shí)際上時(shí)調(diào)用了DefaultApplicationContext的start函數(shù),這個(gè)start函數(shù)中有兩句話this.agentInfoSender.start() 啟動(dòng)Agent信息發(fā)送;this.agentStatMonitor.start(); 啟動(dòng)Agent狀態(tài)監(jiān)控然走。
5援制、agentInfoSender類中定義了一個(gè)scheduleWithFixedDelay線程池,handel內(nèi)容主要是AgentInfoSender.this.dataSender.request(this.agentInfo, this.agentInfoSenderListener);這句話芍瑞,其中AgentInfo是通過createTAgentInfo獲取的監(jiān)控?cái)?shù)據(jù)晨仑,包括createTServiceInfo還有createTJvmInfo,agentInfoSenderListener是一個(gè)發(fā)送監(jiān)聽器拆檬。具體的通訊過程是通過netty Thrift實(shí)現(xiàn)的洪己。agentStatMonitor類中定義了一個(gè)scheduleAtFixedRate線程池,處理的內(nèi)容主要是發(fā)送狀態(tài)信息竟贯。