首页
运维
编程

小布江

首页
运维
编程
  • Kubernetes

  • 日常

  • Prometheus

    • Alertmanager报警历史持久化
    • blackbox-exporter监测站点
    • 监控kafka小tips
    • 常用Exporter
      • 一 Mysql-exporter监控多实例mysql,看板ID:17320
        • 1.1 前置条件,给mysql授权监控账号
        • 1.2 安装Exporter
        • 1.3 Prometheus 端点配置
      • 二 Redis-exporter实例监控,看版ID:17507
        • 2.1 安装Exporter
        • 2.2 Prometheus 端点配置
      • 三 Minio监控,MinIO 指标,看板: 13502
        • 3.1 MinIO给Prometheus提供了两种访问策略:
        • 3.2 部署minio,开启Metrics,基于kubernetessdconfigs自动发现,
    • 远程存储之VictoriaMetrics
    • Nginx-vts模块
    • alertmanager
    • VMagent
    • VMalert
    • Grafana匿名登录查看
  • Cl

  • 运维
  • Prometheus
小布江
2024-07-31
目录

常用Exporter


小记一下.常见的exporter (opens new window),参考 (opens new window)


# 一 Mysql-exporter监控多实例mysql (opens new window),看板ID (opens new window):17320


# 1.1 前置条件,给mysql授权监控账号

CREATE USER 'exporter'@'%' IDENTIFIED BY 'exporter_2024' WITH MAX_USER_CONNECTIONS 10;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
FLUSH PRIVILEGES;
1
2
3

# 1.2 安装Exporter

[root@prod-manage exporter]# cat mysql-exporter.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysqld-exporter
  namespace: kube-mon
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysqld-exporter
  template:
    metadata:
      labels:
        app: mysqld-exporter
    spec:
      containers:
        - name: mysqld-exporter
          image: swr.cn-south-1.myhuaweicloud.com/starsl.cn/mysqld_exporter:latest
          ports:
            - containerPort: 9104
          volumeMounts:
            - name: localtime-volume
              mountPath: /etc/localtime
          env:
            - name: MYSQLD_EXPORTER_PASSWORD
              value: "exporter_2024"
          args:
            - --collect.info_schema.innodb_metrics
            - --collect.info_schema.tables
            - --collect.info_schema.processlist
            - --collect.info_schema.tables.databases=*
            - --mysqld.username=exporter  
      volumes:
        - name: localtime-volume
          hostPath:
            path: /usr/share/zoneinfo/PRC
1
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

# 1.3 Prometheus 端点配置

    - job_name: mysqld
      scrape_interval: 30s
      metrics_path: /probe
      static_configs:
        - targets:
          - rm-x1.mysql.rds.aliyuncs.com:3306
          - rm-x2.mysql.rds.aliyuncs.com:3306
      relabel_configs:
        - source_labels: [__address__]
          target_label: __param_target
        - source_labels: [__param_target]
          target_label: instance
        - target_label: __address__
          replacement: mysqld-exporter:9104
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 二 Redis-exporter实例监控,看版ID (opens new window):17507


# 2.1 安装Exporter

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-exporter
  namespace: kube-mon
  labels:
    app.kubernetes.io/name: redis-exporter
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: redis-exporter
  template:
    metadata:
      labels:
        app.kubernetes.io/name: redis-exporter
    spec:
      containers:
      - name: redis-exporter
        image: oliver006/redis_exporter:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        env:
          - name: REDIS_ADDR
            value: "10.0.200.22:6379"
          - name: REDIS_PASSWORD
            value: "123456"
        ports:
        - containerPort: 9121
          name: redis-exporter
1
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

# 2.2 Prometheus 端点配置

    - job_name: 'redis'
      scrape_interval: 30s
      metrics_path: /scrape
      static_configs:
        - targets:
           - '10.0.200.22:6379'
           - '10.0.200.36:6379'
          labels:
            name: 'prod'
      relabel_configs:
        - source_labels: [__address__]
          target_label: __param_target
        - source_labels: [__param_target]
          target_label: instance
        - target_label: __address__
          replacement: redis-exporter:9121
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 三 Minio监控 (opens new window),MinIO 指标 (opens new window),看板: 13502


# 3.1 MinIO给Prometheus提供了两种访问策略:

1)public方式:
给MinIO集群设置环境变量export MINIO_PROMETHEUS_AUTH_TYPE=public,Prometheus可以不通过验证访问MinIO集群; 这种方式方便简洁,本文采用这种方式。
2)访问验证token方式:
通过客户端命令mc使用命令mc admin prometheus generate <ALIAS>生成验证token,将token配置到Prometheus,Prometheus根据token信息访问集群,具体方法可参考官网。
修改MinIO集群的minio.yaml文件,修改环境变量env部分,新增Prometheus访问权限:

# 本次采用public方式
1
2
3
4
5
6
7

# 3.2 部署minio,开启Metrics,基于kubernetes_sd_configs自动发现,

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: minio
spec:
  serviceName: "minio-headless"
  replicas: 4
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
      annotations:        # 增加注解信息
        prometheus.io/scrape: "true"
        prometheus.io/port: "9000"
        prometheus.io/path: "/minio/v2/metrics/cluster"
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - minio
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: minio
        env:
        - name: MINIO_ROOT_USER
          value: "admin"
        - name: MINIO_ROOT_PASSWORD
          value: "minioadmin"
        - name: MINIO_ERASURE_CODING
          value: "on"
        - name: MINIO_DATA_SHARDS # 数据将被分割成2个数据碎片
          value: "2"
        - name: MINIO_PARITY_SHARDS # 系统将创建2个校验碎片
          value: "2"
        - name: MINIO_PROMETHEUS_AUTH_TYPE
          value: "public"   # 允许Prometheus访问minio的配置
        - name: MINIO_PROMETHEUS_URL  # Prometheus
          value: "http://prometheus.kube-mon.svc.cluster.local:9090"
        - name: MINIO_PROMETHEUS_JOB_ID
          value: "kubernetes-pod" # MINIO_PROMETHEUS_JOB_ID的值是Prometheus target界面标签中的job名
        image: minio:RELEASE.2023-08-09T23-30-22Z
        imagePullPolicy: IfNotPresent
        command:
          - /bin/sh
          - -c
          - minio server --console-address ":5000" http://minio-{0...3}.minio-headless.default.svc.cluster.local:9000/data
        ports:
        - name: data
          containerPort: 9000
          protocol: "TCP"
        - name: console
          containerPort: 5000
          protocol: "TCP"
        volumeMounts:
        - name: minio-data
          mountPath: /data
        - name: time-mount
          mountPath: /etc/localtime
      volumes:
      - name: time-mount
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
  - metadata:
      name: minio-data
    spec:
      storageClassName: "minio-cluster"
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Gi
1
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#Prometheus
上次更新: 2026/05/31, 03:30:34
监控kafka小tips
远程存储之VictoriaMetrics

← 监控kafka小tips 远程存储之VictoriaMetrics→

最近更新
01
Coredns自定义参数
05-18
02
Docker Mirrors
04-24
03
SSL自签证书管理
02-10
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式