本文基於 Pinpoint 2.1.0 版本, 本文 的agent 是已經更改過的源碼后編譯的,具體改動的部分就是: agentID 長度 和 name 的限制。
- 更改后: agentID 和Name 支持 48位字符,默認只支持 24位
場景: 我們的場景是部署在容器中
實現: 我們通過在所有的容器所在的宿主機進行存放 agent 包,然后 容器進行掛載目錄,掛載完目錄后通過更改 啟動命令來進行加載。
一、配置文件修改
配置文件 pinpoint-root.config
配置中profiler.collector.ip
和 profiler.transport.grpc.collector.ip
文件所有使用到這個配置的,都需要更改為我們的 collector 的IP。
采樣率更改 profiler.sampling.rate
# 1 out of n transactions will be sampled where n is the rate. (1: 100%, 20: 5%)
profiler.sampling.rate=10
設置為 10 表示采樣 10%(1/10)
。
二、啟動命令設置
涉及到以下幾個配置
-javaagent:$AGENT_PATH/pinpoint-bootstrap-$VERSION.jar
Additionally, Pinpoint Agent requires 2 command-line arguments in order to identify itself in the distributed system:
-Dpinpoint.agentId
- uniquely identifies the application instance in which the agent is running on-Dpinpoint.applicationName
- groups a number of identical application instances as a single service-Dpinpoint.container
in addition to the 2 required command-line arguments above when launching the agent.
示例:
注意同一個應用的多個實例,遵循,applicationName 要一致, agentId 要區分。
將下面的命令配置到 JAVA_OPTS
或者直接加到啟動命令。
-javaagent:/opt/pinpoint/pinpoint-agent/pinpoint-bootstrap.jar -Dpinpoint.agentId=${SERVICE_NAME} -Dpinpoint.applicationName=${CONTAINER_NAME%_*} -Dpinpoint.container=${SERVICE_NAME}
需要注意的是我上面的配置不是通用了,因為我是獲取了環境變量的值然后進行切割 , ${SERVICE_NAME}
{CONTAINER_NAME%_*}