zoukankan      html  css  js  c++  java
  • Day6-01 如何监控K8S容器中的PHP进程

    一、概述

    在生产环境中我们希望能够通过prometheus监控容器中php进程的状态,刚好看到一个比较好的解决办法,利用php-fpm-exporter对php-fpm进行监控,但想实现该需求需要具备以下条件:

    • php-fpm开启status接口
    • nginx代理php-fpm接口
    • 使用php-fpm-exporter暴露指标给prometheus

    官方GitHub:
    https://github.com/bakins/php-fpm-exporter
    https://rtcamp.com/tutorials/php/fpm-status-page/

    二、php-fpm开启status接口

    • 编辑 php-fpm.conf 配置文件,在其中增加以下两行配置项
    ...
    pm.status_path = /php_status
    ping.path = /ping
    ...
    
    • 配置 nginx
      server {
          server_name 127.0.0.1;
          location ~ ^/(php_status|ping)$ {
              include fastcgi_params;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          }
      }
    
    • 检查status是否可以访问
    shell> curl http://127.0.0.1/php_status
    

    三、使用php-fpm-exporter暴露指标

    • 下载二进制文件
    shell> wget https://github.com/bakins/php-fpm-exporter/releases/download/v0.6.1/php-fpm-exporter.linux.amd64
    shell> chmod +x php-fpm-exporter.linux.amd64
    
    • 封装到底包镜像中
    shell> cat Dockerfile
    ...此处省略...
    ADD php-fpm-exporter.linux.amd64 /php-fpm-exporter
    RUN chmod 755 /php-fpm-exporter
    ENTRYPOINT ["/php-fpm-exporter","--addr","0.0.0.0:9190","--endpoint","http://127.0.0.1/php_status"]
    
    • 检查metrics是否可以访问
    shell> curl http://127.0.0.1:9190/metrics
    

    • 浏览器访问

    四、配置prometheus,采集php-fpm数据

    动态发现和静态配置规则根据喜好二选一即可

    • 编辑prometheus.yml,增加php-fpm任务(动态发现)
      - job_name: 'php-fpm'
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - source_labels: [__meta_kubernetes_namespace]
            action: replace
            target_label: kubernetes_namespace
          - source_labels: [__meta_kubernetes_pod_name]
            action: keep
            regex: .*php.*
          - source_labels: [__meta_kubernetes_pod_ip]
            action: replace
            regex: (.+)
            target_label: __address__
            replacement: ${1}:9190
    
    • 编辑prometheus.yml,增加php-fpm任务(静态配置)
      - job_name: 'php-fpm'
        static_configs:
          - targets:
            - 172.24.101.6:9190
    
    • 附配置生效后的 prometheus 截图
  • 相关阅读:
    Redis事务和锁
    11/6笔记 补充(Redis持久化,RDB&&AOF)
    11/6随笔
    Redis 安装教程
    Redis通用指令和第一个Jedis程序的实现
    Redis学习第二天
    SpringBoot学习笔记
    1000行代码手写服务器
    log4j创建实例异常
    寒假阅读人月神话3
  • 原文地址:https://www.cnblogs.com/91donkey/p/14035441.html
Copyright © 2011-2022 走看看