我搜索了大部分文章,但没有找到我期望的解决方案。我是普罗米修斯的新手。我需要通过我的java程序收集Prometheus度量。因此,需要帮助通过我的java程序读取或获取Prometheus度量。
任何帮助或建议都会有帮助。
感谢
如果使用Spring boot 2.1.5.RELEASE,则
- 添加相关性执行器和测微计普罗米修斯
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
- 添加配置以启用对端点/执行器/普罗米修斯的访问
management: endpoints: web: exposure: include: '*'
- 尝试请求
http://domain:port/actuator/prometheus
编辑对于kubernetes im使用种类部署:
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
有很多方法可以做到这一点请参考https://github.com/prometheus/client_java