0

我搜索了大部分文章,但没有找到我预期的解决方案。我是普罗米修斯的新手。我需要让我的 java 程序收集 Prometheus 指标。因此,需要帮助才能通过我的 java 程序读取或获取 Prometheus 指标。

任何帮助或建议都会有所帮助。

谢谢

4

2 回答 2

1

如果您使用的是 Spring boot 2.1.5.RELEASE 那么

  1. 添加依赖执行器和 micrometer-prometheus
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
 <dependency> 
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
 </dependency>
  1. 添加配置以启用对端点 /actuator/prometheus 的访问
management:
  endpoints:
    web:
      exposure:
       include: '*'
  1. 尝试请求http://domain:port/actuator/prometheus

编辑对于 kubernetes 即时使用 kind 部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myAppName
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myAppName
  template:
    metadata:
      labels:
        app: myAppName
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8091"
        prometheus.io/path: "/actuator/prometheus"
    spec:
      containers:
        - name: myAppName
          image: images.com/app-service:master
          imagePullPolicy: Always
          ports:
            - containerPort: 8091
          env:
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: CONFIG_SERVER_ADDRESS
              value: "http://config-server:8888"
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 45
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 5
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
      nodeSelector:
        servicetype: mvp-cluster
于 2020-07-10T10:40:40.243 回答
0

有很多方法可以做到这一点请参考这个https://github.com/prometheus/client_java

于 2020-07-10T10:17:24.217 回答