Kube-Prometheus修改拉取时间

时间:2023-02-17 11:26:33

1.修改globle 全局拉取时间,修改prometheus-prometheus.yaml文件

添加以下三个参数

刮擦间隔:5s 刮擦超时:30秒 评价间隔:15s

[root@k8s-master kube-prometheus]# vim manifests/prometheus-prometheus.yaml

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
app.kubernetes.io/component: prometheus
app.kubernetes.io/instance: k8s
app.kubernetes.io/name: prometheus
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: 2.36.0
name: k8s
namespace: monitoring
spec:
alerting:
alertmanagers:
- apiVersion: v2
name: alertmanager-main
namespace: monitoring
port: web
retention: 7d

scrapeInterval: 5s
scrapeTimeout: 30s
evaluationInterval: 15s
storage:
volumeClaimTemplate:
spec:
storageClassName: prometheus-data-db
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 100Gi

enableFeatures: []
externalLabels: {}


[root@k8s-master kube-prometheus]# kubectl apply -f manifests/prometheus-prometheus.yaml
prometheus.monitoring.coreos.com/k8s unchanged

2.修改prometheus-podmonitor.yaml配置文件由15s变为5s

prometheus-podmonitor.yaml这个用于pod自动发现的。

[root@k8s-master kube-prometheus]# vim manifests/prometheus-podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
labels:
jmeter_mode: base
name: jmeter # 最终显示在promtheus中的job名称
namespace: monitoring
spec:
podMetricsEndpoints:
- interval: 5s
path: /metrics
targetPort: 9270
namespaceSelector:
matchNames:
- jmeter
selector:
matchLabels:
jmeter_mode: base

[root@k8s-master kube-prometheus]# kubectl apply -f manifests/prometheus-podmonitor.yaml
podmonitor.monitoring.coreos.com/jmeter configured

3.添加物理机监控的target目标服务器监控

[root@k8s-master kube-prometheus]# cat  prometheus-additional.yaml
- job_name: jmeter-base-test20220611
scrape_interval: 5s
scrape_timeout: 15s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- 10.244.1.25:9270


4.修改Blackbox出口商、舱单/blackboxExporter-serviceMonitor.yaml

[root@k8s-master kube-prometheus]# cat  manifests/blackboxExporter-serviceMonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: blackbox-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: 0.21.0
name: blackbox-exporter
namespace: monitoring
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
interval: 5s
path: /metrics
port: https
scheme: https
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: blackbox-exporter
app.kubernetes.io/part-of: kube-prometheus
[root@k8s-master kube-prometheus]# kubectl apply -f manifests/blackboxExporter-serviceMonitor.yaml
Warning: resource servicemonitors/blackbox-exporter is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
servicemonitor.monitoring.coreos.com/blackbox-exporter configured

5.node-exporter修改

[root@k8s-master kube-prometheus]# kubectl apply -f  manifests/nodeExporter-serviceMonitor.yaml
Warning: resource servicemonitors/node-exporter is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
servicemonitor.monitoring.coreos.com/node-exporter configured
[root@k8s-master kube-prometheus]# cat manifests/nodeExporter-serviceMonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: node-exporter
app.kubernetes.io/part-of: kube-prometheus
app.kubernetes.io/version: 1.3.1
name: node-exporter
namespace: monitoring
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
interval: 5s
port: https
relabelings:
- action: replace
regex: (.*)
replacement: $1
sourceLabels:
- __meta_kubernetes_pod_node_name
targetLabel: instance
scheme: https
tlsConfig:
insecureSkipVerify: true
jobLabel: app.kubernetes.io/name
selector:
matchLabels:
app.kubernetes.io/component: exporter
app.kubernetes.io/name: node-exporter
app.kubernetes.io/part-of: kube-prometheus