3.3. Cryostat エージェントと JMX 接続を使用したアプリケーションの設定
Cryostat エージェントと Java Management Extensions (JMX) 接続を組み合わせて使用してターゲットアプリケーションを検出および通信するように、Java 仮想マシン (JVM) 上で実行されるターゲットアプリケーションを設定できます。
Cryostat エージェントを使用してターゲットアプリケーションを検出および通信し、JMX を使用して Java Flight Recorder (JFR) データを公開します。
Cryostat エージェント自体について Cryostat と通信し、HTTP 経由ではなく JMX 経由でエージェントに到達できるように、Cryostat エージェントを設定する必要があります。
前提条件
- Cryostat Web コンソールにログインしている。
- プロジェクトに Cryostat インスタンスを作成している。
手順
Cryostat エージェントをインストールします。Maven を使用するアプリケーションビルドの場合は、Cryostat エージェントの JAR ファイルの情報を使用してアプリケーションの
pom.xmlファイルを更新します。pom.xmlファイルの例<project> ... <repositories> <repository> <id>redhat-maven-repository</id> <url>https://maven.repository.redhat.com/earlyaccess/all/</url> </repository> </repositories> ... <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>io.cryostat</groupId> <artifactId>cryostat-agent</artifactId> <version>0.3.0.redhat-00001</version> <classifier>shaded</classifier> </artifactItem> </artifactItems> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin> </plugins> ... </build> ... </project>アプリケーションのデプロイメントを変更します。
例
apiVersion: apps/v1 kind: Deployment ... spec: ... template: ... spec: containers: - name: sample-app image: docker.io/myorg/myapp:latest env: - name: CRYOSTAT_AGENT_APP_NAME value: "myapp" # Replace this with the Kubernetes DNS record # for the Cryostat Service - name: CRYOSTAT_AGENT_BASEURI value: "http://cryostat.mynamespace.mycluster.svc:8181" - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - name: CRYOSTAT_AGENT_CALLBACK value: "http://$(POD_IP):9977" - name: CRYOSTAT_AGENT_AUTHORIZATION # Replace "abcd1234" with a base64-encoded authentication token value: "Bearer abcd1234" # This environment variable is key to the Cryostat agent # and JMX "hybrid" setup. # Set the Cryostat agent to register itself with Cryostat # as reachable through JMX, rather than reachable through HTTP. - name: CRYOSTAT_AGENT_REGISTRATION_PREFER_JMX value: "true" # Configure the application to load the agent JAR file and # to enable JMX, so that the Cryostat agent can register # itself as reachable through JMX. # To configure authentication and SSL/TLS for the JMX # connections, see <1>. - name: JAVA_OPTS value: >- -javaagent:/deployments/app/cryostat-agent-shaded.jar -Dcom.sun.management.jmxremote.port=90911 ports: - containerPort: 9977 protocol: TCP resources: {} restartPolicy: Always status: {}<1>: JMX 接続の認証と SSL/TLS を設定し、その他の設定オプションを表示するには、JMX 接続を使用したアプリケーションの設定 を参照してください。
Cryostat がターゲットアプリケーションを検出し、Cryostat エージェントに接続できるようにするために、アプリケーション
Serviceを設定します。例
apiVersion: v1 kind: Service ... spec: ports: - name: "jfr-jmx" port: 9091 targetPort: 9091 - name: "cryostat-agent" port: 9977 targetPort: 9977 ...