camilb / prometheus-kubernetes

Monitoring Kubernetes clusters on AWS, GCP and Azure using Prometheus Operator and Grafana
Apache License 2.0
672 stars 300 forks source link

How to get jmx metrics in prometheus-kubernetes project? #91

Open andrvin opened 6 years ago

andrvin commented 6 years ago

Hi guys! Thank you for your job! Everything is good, but I just don't know how to get metrics from prometheus jmx exporter agent. The agent is installed in app container and listen on 9090 port:

spec:
      containers:
      - image: registry/image:version
        imagePullPolicy: Always
        name: app-name
        env:
        - name: JAVA_CUSTOM_OPTS
          value: "-Xms256m -Xmx512m -javaagent:./jmx_prometheus_javaagent.jar=9090:jmx/prom-jmx-agent-config.yml"
        ports:
        - name: app
          containerPort: 8080
        - name: monitoring
          containerPort: 9090 

How I can add this new target into prometheus configuration? Usually I just have to edit prometheus.yml config file, but I don't understand how to add it into your configuration.

camilb commented 6 years ago

Hi @andrvin this should work, you have to replace the selector label and the namespace.

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: jmx
  namespace: monitoring
  labels:
    k8s-app: jmx
spec:
  selector:
    matchLabels:
      your_label_key: your_label_value
  endpoints:
  - port: monitoring
    interval: 10s
  namespaceSelector:
    matchNames:
    - your_app_namespace

Save it to a file and kubectl create -f file.yaml

dberardo-com commented 1 year ago

how does the attribute "port" work in prometheus ? i cant use integers there, so what is the convention being used ?

camilb commented 1 year ago

@dberardo-com You can see an example here. The port should match the service port name.