云原生监控系统Prometheus——Exporter(Redis-exporter)
Exporter(Redis-exporter)
在安装之前,首先在官方下载页面 https://github.com/prometheus/mysqld_exporter/releases/ 找到最新 redis_exporter 版本,下载最新版本中特定平台的二进制文件,如下:
一、部署 redis_exporter
我这里都是 kubernetes 环境,就不讲二进制部署了。以下是 StatefulSet 运行的 Reids server 服务,以及 redis_exporter 的配置清单 yaml 文件:
- redis server 版本号:redis:6.0.9-alpine
- redis server 的 statefulset 配置清单文件如下:
kind: StatefulSet apiVersion: apps/v1 metadata: name: redis-ke9owy namespace: devops-redis-test labels: app.kubernetes.io/instance: redis-ke9owy app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: redis app.kubernetes.io/version: 6.0.9 app.kubesphere.io/instance: redis-ke9owy helm.sh/chart: redis-0.3.5 annotations: kubesphere.io/creator: admin meta.helm.sh/release-name: redis-ke9owy meta.helm.sh/release-namespace: devops-redis-test spec: replicas: 1 selector: matchLabels: app.kubernetes.io/instance: redis-ke9owy app.kubernetes.io/name: redis template: metadata: creationTimestamp: null labels: app.kubernetes.io/instance: redis-ke9owy app.kubernetes.io/name: redis annotations: kubesphere.io/creator: admin spec: volumes: - name: configs configMap: name: redis-ke9owy defaultMode: 420 containers: - name: redis image: 'redis:6.0.9-alpine' command: - /bin/sh - '-c' - | rm -rf /redis/data/lost+found args=" --include /tmp/conf/default.conf --include /tmp/conf/user.conf " redis-server $args ports: - name: redis containerPort: 6379 protocol: TCP resources: {} volumeMounts: - name: configs mountPath: /tmp/conf - name: data mountPath: /data/redis terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: {} schedulerName: default-scheduler volumeClaimTemplates: - kind: PersistentVolumeClaim apiVersion: v1 metadata: name: data creationTimestamp: null labels: app.kubernetes.io/instance: redis-ke9owy app.kubernetes.io/name: redis spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi volumeMode: Filesystem status: phase: Pending serviceName: redis-ke9owy podManagementPolicy: OrderedReady updateStrategy: type: RollingUpdate rollingUpdate: partition: 0 revisionHistoryLimit: 10
- redis server 的 statefulset 配置清单文件如下:
- redis_exporter 版本号:oliver006/redis_exporter:v1.3.4
- redis_exporter 的 Deployment 配置清单 yaml 文件如下:
kind: Deployment apiVersion: apps/v1 metadata: name: redis-e-rhqcz7-redis-exporter namespace: devops-redis-test labels: app: redis-exporter app.kubernetes.io/managed-by: Helm app.kubesphere.io/instance: redis-e-rhqcz7 chart: redis-exporter-3.4.5 heritage: Helm release: redis-e-rhqcz7 annotations: deployment.kubernetes.io/revision: '1' kubesphere.io/creator: admin meta.helm.sh/release-name: redis-e-rhqcz7 meta.helm.sh/release-namespace: devops-redis-test spec: replicas: 1 selector: matchLabels: app: redis-exporter release: redis-e-rhqcz7 template: metadata: creationTimestamp: null labels: app: redis-exporter release: redis-e-rhqcz7 annotations: kubesphere.io/creator: admin spec: containers: - name: redis-exporter image: 'oliver006/redis_exporter:v1.3.4' ports: - name: exporter-port containerPort: 9121 protocol: TCP env: - name: REDIS_ADDR value: 'redis://myredis:6379' resources: {} livenessProbe: httpGet: path: / port: exporter-port scheme: HTTP timeoutSeconds: 1 periodSeconds: 10 successThreshold: 1 failureThreshold: 3 readinessProbe: httpGet: path: / port: exporter-port scheme: HTTP timeoutSeconds: 1 periodSeconds: 10 successThreshold: 1 failureThreshold: 3 terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst serviceAccountName: redis-e-rhqcz7-redis-exporter serviceAccount: redis-e-rhqcz7-redis-exporter securityContext: {} schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600
- redis_exporter 的 Deployment 配置清单 yaml 文件如下:
二、与 Prometheus 集成
与 Prometheus 的配置文件 prometheus.yaml 中的 static_configs 模块内,继续追加配置内容来采集 redis_exporter 提供的数据。添加的参考配置内容如下:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "node_exporter"
static_configs:
- targets: ["192.168.2.121:9100"]
- job_name: "mysqld_exporter"
scrape_interval: 10s
static_configs:
- targets: ["192.168.2.121:9104"]
- job_name: "redis_exporter"
scrape_interval: 10s
static_configs:
- targets: ["192.168.2.121:9121"]