hincky的主页 hincky的主页
  • 2023

    • nginx
    • prometheus
    • 小工具
    • 部署
  • 数据库

    • MySQL是怎么使用/运行的
    • Redis核心技术与实战
  • 极客时间

    • Web协议详解与抓包实战
    • SQL必知必会
    • MySQL45讲
个人日常
  • 分类
  • 标签
  • 归档
  • 随笔
GitHub (opens new window)

Hincky

当有趣的人,做想做的事
  • 2023

    • nginx
    • prometheus
    • 小工具
    • 部署
  • 数据库

    • MySQL是怎么使用/运行的
    • Redis核心技术与实战
  • 极客时间

    • Web协议详解与抓包实战
    • SQL必知必会
    • MySQL45讲
个人日常
  • 分类
  • 标签
  • 归档
  • 随笔
GitHub (opens new window)
  • 2022

  • 2023

    • 一月

    • 五月

    • nginx

    • prometheus

      • prometheus架构介绍
        • Prometheus工作流程
        • Prometheus组件介绍
          • job/exporter
          • pushgateway
        • 配置告警
      • 安装方式
        • Kube-Prometheus Stack
        • Prometheus Operator
        • 二进制安装
        • 容器安装
          • 挂载配置文件数据卷
          • Dockerfile
        • Helm安装
      • 数据来源与监控配置
        • 云原生应用
        • 非云原生应用
        • 监控
          • ServiceMonitor监控配置
          • ServiceMonitor模板
          • 监控流程
      • PromQL
        • 选择器
        • 标签匹配器
    • tools

    • http状态码

    • 监控

    • Go

    • python

    • linux性能优化

    • PHP

    • elastic

    • chatgpt

    • 小工具

    • js

    • django

    • centos7.6配置

    • 部署

    • 部署资源整理

    • MySQL数据库

  • 工作记录
  • 2023
  • prometheus
hincky
2022-11-17
目录

数据来源与监控配置

# 云原生应用

因为很多云原生应用都原生支持对外暴露/metrics监控信息的接口

可以先通过ps aux | grep node找出node_exporter相关的监控进程

再利用netstat -lntp | grep 9100 9100是上面查出来的端口信息

最后访问 127.0.0.1:9100/metrics 去查看监控代理所暴露的监控信息

# 非云原生应用

对于非云原生应用,由于没有自带的/metrics,所以要通过按照exporter作为监控代理

查看宿主机所有链接信息 netstat -lantup

获取监控信息的方法与上面类似

# 监控

两种配置方式

  • prometheus.yaml:
    • 二进制安装
    • 容器安装
    • helm
  • ServiceMonitor:
    • helm
    • Prometheus Operator
    • Kube-Prometheus

# ServiceMonitor监控配置

提示

前提:安装方式是 Kube-Prometheus

声明ip,port,还有监控指标之类的配置,但是监控目标增多之后管理就十分困难

所以Prometheus通过ServiceMonitor来管理

k8s查看ServiceMonitor配置项

kubectl get servicemonitor -n monitoring
1

以yaml格式输出具体某个配置项

kubectl get servicemonitor -n monitoring node-exporter -o yaml
1

留意好标签匹配器selector里面的标签匹配规则

通过标签查询监控的负载均衡

kubectl get svc -n monitoring -l app.kubernetes.io/component=exporter
1

# ServiceMonitor模板

Prometheus通过这个监控配置去发现监控目标

apiVersion: monitoring.cores.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: elasticsearch-exporter
    release: es-exporter
  name: es-exporter-elasticsearch-exporter
  namespace: monitoring
spec:
  endpoints:
  - honorLabels: true   # 是否保留目标标签
    interval: 10s       # 抓取间隔
    path: /metrics
    port: http          
    scheme: http        # 接口的协议
  jobLabels: es-exporter
  namespaceSelector:    # 监控目标Service所在的命名空间
    matchNames:
    - monitoring
  selector:             # 监控目标Service的标签
    matchLabels:
      k8s-app: elasticsearch-exporter
      release: es-exporter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# 监控流程

编辑 (opens new window)
安装方式
PromQL

← 安装方式 PromQL→

最近更新
01
集成chatgpt的工具
05-24
02
修改服务器ssh默认连接端口
05-22
03
阿里云免费证书
05-15
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Hincky | MIT License | 粤ICP备2022120427号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式