一 PushGateway说明
Prometheus Pushgateway 是为了允许临时和批处理作业向 Prometheus 公开其指标。由于这些类型的作业可能存在的时间不够长而无法被抓取,因此他们可以将指标推送到 Pushgateway。然后 Pushgateway 将这些指标公开给 Prometheus。
pushgateway的GitHub地址:https://github.com/prometheus/pushgateway
二 在K8S中安装Pushgateway
通过以下yaml文件安装,kubectl apply -f pushgateway-deployment.yaml
pushgateway-deployment.yaml1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
name: pushgateway-deployment
name: pushgateway
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: pushgateway
template:
metadata:
labels:
app: pushgateway
spec:
nodeSelector:
zone: system
containers:
- image: prom/pushgateway:v1.4.2
name: pushgateway
livenessProbe:
failureThreshold: 1
httpGet:
path: /-/healthy
port: 9091
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 9
readinessProbe:
failureThreshold: 1
httpGet:
path: /-/ready
port: 9091
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 15
successThreshold: 1
timeoutSeconds: 9
ports:
- containerPort: 9091
protocol: TCP
resources:
requests:
cpu: 10m
memory: 100Mi
limits:
cpu: 100m
memory: 2000Mi
kind: Service
apiVersion: v1
metadata:
labels:
app: pushgateway
name: pushgateway
namespace: kube-system
spec:
ports:
- port: 9091
targetPort: 9091
selector:
app: pushgateway
在 Prometheus 中的configmap中添加配置如下:1
2
3
4
5
6
7- job_name: pushgateway
honor_labels: true
static_configs:
- targets: ['pushgateway:9091']
labels:
instance: pushgateway
service: pushgatewayservice
再通过命令 curl -XPOST http://[prometheus-host]:9090/-/reload
刷新Prometheus配置。