热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Prometheus监控PHP应用

文章目录1、配置PHP-FPM,暴露php-fpm状态信息2、bakinsphp-fpm-exporter监控PHP应用2.1、配置php状态页的http访问2.2、


文章目录

    • 1、配置PHP-FPM,暴露php-fpm状态信息
    • 2、bakins/php-fpm-exporter监控PHP应用
      • 2.1、配置php状态页的http访问
      • 2.2、下载bakins/php-fpm-exporter
      • 2.3、配置为系统服务
      • 2.4、配置防火墙
      • 2.5、与Prometheus集成
      • 2.6、与Grafana集成
    • 3、hipages/php-fpm_exporter监控php应用
      • 3.1、下载
      • 3.2、配置为系统服务
      • 3.3、与Prometheus集成
      • 3.4、与Grafana集成

要监控PHP状态信息,必须先配置显示PHP状态页,这样Prometheus才能通过Exporter进行监控。


1、配置PHP-FPM,暴露php-fpm状态信息

官方参考:https://easyengine.io/tutorials/php/fpm-status-page/
修改/usr/local/php/etc/php-fpm.conf,增加以下内容

pm.status_path = /status
ping.path = /ping

目前可用于监控PHP的Exporter有三个:


  • https://github.com/bakins/php-fpm-exporter
  • https://github.com/hipages/php-fpm_exporter
  • https://github.com/Lusitaniae/phpfpm_exporter

本文只介绍前边两个


2、bakins/php-fpm-exporter监控PHP应用

bakins/php-fpm-exporter只能通过http读取PHP状态页信息,需要借助nginx来提供PHP状态页数据


2.1、配置php状态页的http访问

nginx.conf

server {listen 9010; allow 127.0.0.1; #限制ipallow 192.168.28.131; #限制ipdeny all;location ~ ^/(status|ping)$ {fastcgi_pass unix:/tmp/php-cgi.sock; # unix socket#fastcgi_pass 127.0.0.1:9000; # tcpfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}

查看状态页数据

[root@ ~]# curl http://127.0.0.1:9010/status# php-fpm状态页的内容如下
pool: www
process manager: dynamic
start time: 24/Sep/2022:22:50:44 +0800
start since: 2219
accepted conn: 42
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 12
active processes: 1
total processes: 13
max active processes: 5
max children reached: 0
slow requests: 0

2.2、下载bakins/php-fpm-exporter

下载地址:https://github.com/bakins/php-fpm-exporter
下载文件:php-fpm-exporter.linux.amd64

mv php-fpm-exporter.linux.amd64 /usr/local/php-fpm-exporter
chmod u+x /usr/local/php-fpm-exporter# php-fpm-exporter命令参数
usage: php-fpm-exporter []Flags:-h, --help Show context-sensitive help (also try --help-long and --help-man).--addr="127.0.0.1:8080" listen address for metrics handler--endpoint="http://127.0.0.1:9000/status" url for php-fpm status--fastcgi=FASTCGI fastcgi url. If this is set, fastcgi will be used instead of HTTP--web.telemetry-path="/metrics"Path under which to expose metrics. Cannot be /# 运行
/usr/local/php-fpm-exporter --addr 0.0.0.0:9011 --endpoint="http://127.0.0.1:9010/status" --web.telemetry-path="/metrics"

查看转成Prometheus监控指标的状态页数据

[root@s2 ~]# curl http://127.0.0.1:9011/metrics

2.3、配置为系统服务

vi /usr/lib/systemd/system/php_exporter.service

[Unit]
Description=php_exporter
Wants=network-online.target
After=network-online.target[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/php-fpm-exporter \--addr=0.0.0.0:9011 \--endpoint=http://127.0.0.1:9010/status \--web.telemetry-path=/metrics[Install]
WantedBy=multi-user.target

php_exporter服务命令

systemctl daemon-reload # 通知systemd重新加载配置文件
systemctl enable php_exporter # 设置开机启动
systemctl disable php_exporter # 取消开机启动
systemctl start php_exporter # 启动服务
systemctl restart php_exporter # 重启服务
systemctl stop php_exporter # 关闭服务
systemctl status php_exporter # 查看状态

2.4、配置防火墙

如果端口未开启,需要开启相关端口

#启动防火墙
systemctl start firewalld.service
#开通端口
firewall-cmd --zone=public --add-port=9011/tcp --permanent
#重启防火墙
firewall-cmd --reload

2.5、与Prometheus集成

prometheus.yml

scrape_configs:- job_name: 'PHP-FPM'static_configs:- targets: ['192.168.28.132:9011','192.168.28.136:9011']

重新加载配置

curl -X POST http://127.0.0.1:9090/-/reload # prmetheus不需要登录
curl -X POST http://admin@123456:127.0.0.1:9090/-/reload # prmetheus需要登录

在这里插入图片描述

在这里插入图片描述


2.6、与Grafana集成

可视化模板:https://grafana.com/grafana/dashboards/3901-php-fpm/
在这里插入图片描述


3、hipages/php-fpm_exporter监控php应用


3.1、下载

下载:https://github.com/hipages/php-fpm_exporter
下载文件:php-fpm_exporter_2.2.0_linux_amd64

mv php-fpm_exporter_2.2.0_linux_amd64 /usr/local/php-fpm_exporter
chmod u+x /usr/local/php-fpm_exporter# 运行命令有两个
# get方式是在命令行下显示结果
sudo -u www /usr/local/php-fpm_exporter get --phpfpm.scrape-uri "unix:///tmp/php-cgi.sock;/status"# server方式是以web方式示结果
sudo -u www /usr/local/php-fpm_exporter server --web.listen-address ":9253" --phpfpm.scrape-uri "unix:///tmp/php-cgi.sock;/status"
# web方式示结果查看监控数据
curl http://127.0.0.1:9253/metrics

3.2、配置为系统服务

vi /usr/lib/systemd/system/php_exporter2.service

[Unit]
Description=php_exporter2
Wants=network-online.target
After=network-online.target[Service]
User=www
Group=www
Type=simple
ExecStart=/usr/local/php-fpm_exporter server \--web.listen-address ":9253" \--web.telemetry-path "/metrics" \--phpfpm.scrape-uri "unix:///tmp/php-cgi.sock;/status"
# --phpfpm.scrape-uri "tcp://127.0.0.1:9000/status"
[Install]
WantedBy=multi-user.target

php_exporter2服务命令

systemctl daemon-reload # 通知systemd重新加载配置文件
systemctl enable php_exporter2 # 设置开机启动
systemctl disable php_exporter2 # 取消开机启动
systemctl start php_exporter2 # 启动服务
systemctl restart php_exporter2 # 重启服务
systemctl stop php_exporter2 # 关闭服务
systemctl status php_exporter2 # 查看状态

vi /etc/passwd

www:x:1002:1002::/home/www:/sbin/nologin
# 修改为
www:x:1002:1002::/home/www:/bin/bash

3.3、与Prometheus集成

scrape_configs:- job_name: 'PHP-FPM2'static_configs:- targets: ['192.168.28.136:9253']labels:namespace: '192.168.28.136:9253'- targets: ['192.168.28.132:9253']labels:namespace: '192.168.28.132:9253'

在这里插入图片描述

在这里插入图片描述


3.4、与Grafana集成

可视化模板:https://grafana.com/grafana/dashboards/15796-php-fpm/
在这里插入图片描述


推荐阅读
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • Docker下Prometheus和Grafana三部曲之一:极速体验
    开源监控工具Prometheus目前广为使用,配合Grafana即可直观展现监控数据,但对于初学者来说搭建这样一个系统要花费些时间,或者有 ... [详细]
  • Centos7配置Grafana镜像
    varis_mobinavigator.userAgent.toLowerCase().match((ipod|iphone|android|coolpad|mmp|smartph ... [详细]
  • 在使用豆瓣OAuth登录接口时,我们需要发送这样的HTTPREQUEST请求:GETv2user~meHTTP1.1Host:https:api.douban.com ... [详细]
  • redis 端口_使用Prometheus和Grafana构建Redis实时监控平台
    Redis作为缓存系统,在整个后端体系中是较为重要的一环,需要实时监控运行状态。现在有各种各样的工具都可以对Redis进行监控,例如&#x ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • 本文介绍了如何使用vue-awesome-swiper组件,包括在main.js中引入和使用swiper和swiperSlide组件,以及设置options和ref属性。同时还介绍了如何在模板中使用swiper和swiperSlide组件,并展示了如何通过循环渲染swipes数组中的数据,并使用picUrl属性显示图片。最后还介绍了如何添加分页器。 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了软件测试知识点之数据库压力测试方法小结相关的知识,希望对你有一定的参考价值。 ... [详细]
  • node.jsrequire和ES6导入导出的区别原 ... [详细]
  • 本文讨论了在使用PHP cURL发送POST请求时,请求体在node.js中没有定义的问题。作者尝试了多种解决方案,但仍然无法解决该问题。同时提供了当前PHP代码示例。 ... [详细]
  • Python已成为全球最受欢迎的编程语言之一,然而Python程序的安全运行存在一定的风险。本文介绍了Python程序安全运行需要满足的三个条件,即系统路径上的每个条目都处于安全的位置、"主脚本"所在的目录始终位于系统路径中、若python命令使用-c和-m选项,调用程序的目录也必须是安全的。同时,文章还提出了一些预防措施,如避免将下载文件夹作为当前工作目录、使用pip所在路径而不是直接使用python命令等。对于初学Python的读者来说,这些内容将有所帮助。 ... [详细]
  • 其实之前也有下载过完整的android源码,但是从来没有对这个做过一些总结,在加上最近需要经常去看,索性就在从新下载,编译一下,其实这些东西官网上面都有。http:sou ... [详细]
  • 四行代码换国内源快速安装配置Rust
    四行代码快速安装Rust很多朋友苦恼官方给出的终端安装命令,太慢,有时候直接连接不上。接下来介绍四行代码快速换源安装配置RUST。#先配置国内源打开终端 ... [详细]
  • kubeadm构建k8s之Prometheusoperated监控(0.18.1)
       介绍:    大家好,k8s的搭建有许多方式,也有许多快速部署的,为了简化部署的复杂度,官方也提供了开源的kubeadm快速部署,最新1.10.x版本已经可以实现部署集群,  ... [详细]
author-avatar
枇杷语1314
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有