Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start java application with jmx-exporter with a problem #884

Closed
lvdb-wuzihong opened this issue Oct 27, 2023 · 2 comments
Closed

start java application with jmx-exporter with a problem #884

lvdb-wuzihong opened this issue Oct 27, 2023 · 2 comments

Comments

@lvdb-wuzihong
Copy link

When my Java application uses jmx-exporter as the javaagent, the Java application starts normally, but the javaagent's interface does not take effect. That is, jmx-exporter does not appear to be started properly. My jmx-exporter config file is as follows:

startDelaySeconds: 0
ssl: false
username:
password:
lowercaseOutputName: false
lowercaseOutputLabelNames: false
rules: 
  - pattern: ".*"
@lvdb-wuzihong
Copy link
Author

my Dockerfile write as follows(created from Jenkins pipeline):

script{
                        jar_name = sh (returnStdout: true, script: 'ls service/target/ | grep \'.jar\' | grep -v \'sources\' | head -n 1').trim()
                        sh """
                        rm Dockerfile -rf
                        JAR_NAME=${jar_name}
                        echo 'FROM ubuntu:16.04 as jar' >> Dockerfile
                        echo 'WORKDIR /' >> Dockerfile
                        echo 'RUN apt-get update -y'  >> Dockerfile
                        echo 'RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget' >> Dockerfile
                        echo 'RUN wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.20.0/jmx_prometheus_javaagent-0.20.0.jar' >> Dockerfile
                        echo 'FROM openjdk:11' >> Dockerfile
                        echo \"ADD service/target/\${JAR_NAME} /app/\${JAR_NAME}\" >> Dockerfile
                        echo 'COPY --from=jar /jmx_prometheus_javaagent-0.20.0.jar /app/jmx_prometheus_javaagent-0.20.0.jar' >> Dockerfile
                        echo 'ENV TZ=Asia/Shanghai' >> Dockerfile
                        echo 'EXPOSE 8088' >> Dockerfile
                        echo 'EXPOSE 8910' >> Dockerfile
                        echo 'ENTRYPOINT ["java", "-jar", "/app/${jar_name}"]' >> Dockerfile
                        """
                        sh '''
                        tag=`date +%s`;docker build -t harbor.xxx.com/develop/app:${tag} .
                        docker push harbor.xxx.com/develop/app:${tag}
                        kubectl set image deployment/app app=harbor.xxx.com/develop/app:$tag -n develop
                        '''
                    }

And my deployment.yaml's template as follows:

  template:
    metadata:
      labels:
        app: app
    spec:
      volumes:
        - name: config
          configMap:
            name: app-cm
            defaultMode: 420
        - name: log
          emptyDir: {}
        - name: jmx-exporter
          configMap:
            name: jmx-exporter
            items:
              - key: jmx_exporter.yaml
                path: jmx_exporter.yaml
            defaultMode: 420
      containers:
        - name: promtail
          image: 'docker.io/bitnami/promtail:2.8.4-debian-11-r0'
          args:
            - '-config.file=/etc/promtail/promtail.yaml'
          resources: {}
          volumeMounts:
            - name: config
              mountPath: /etc/promtail/
            - name: log
              mountPath: /logs/
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
        - name: app
          image: 'harbor.xxx.com/develop/app:1698393685'
          args:
            - >-
              -javaagent:/app/jmx_prometheus_javaagent-0.20.0.jar=8088:/app/jmx_exporter.yaml
            - '--spring.config.location=/app/config/bootstrap.yml'
          ports:
            - containerPort: 8910
              protocol: TCP
            - containerPort: 8088
              protocol: TCP
          env:
            - name: PROPERTIES_PATH
              value: /app/config/tinyid_client.properties
          resources:
            limits:
              cpu: 500m
              memory: 800Mi
            requests:
              cpu: 100m
              memory: 400Mi
          volumeMounts:
            - name: config
              mountPath: /app/config
            - name: log
              mountPath: /logs/
            - name: jmx-exporter
              mountPath: /app/jmx_exporter.yaml
              subPath: jmx_exporter.yaml
          livenessProbe:
            tcpSocket:
              port: 8910
            initialDelaySeconds: 10
            timeoutSeconds: 5
            periodSeconds: 60
            successThreshold: 1
            failureThreshold: 5
          readinessProbe:
            tcpSocket:
              port: 8910
            initialDelaySeconds: 10
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 5
          imagePullPolicy: IfNotPresent

@dhoard
Copy link
Collaborator

dhoard commented Oct 27, 2023

The exporter YAML file does not need the following configuration when running as a Java agent.

ssl: false
username:
password:

Bash into the POD and check that...

  1. netstat shows a process listening on port 8080
  2. provide the actual command line of the process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants