Apache Server采集

王玉松@快猫星云 2024-09-23 10:06:10

apache开启模块/添加模块都需要重新编译, 我们首先做一些准备工作。

测试环境

  • 操作系统: Centos 8.2

安装依赖

这些依赖是我这个环境下的,你可以根据自己的环境安装对应的依赖 在基于 RHEL 的发行版中,Apache 软件包和服务被称为httpd。想要安装 Apache,使用 root 或者其他有 sudo 权限的用户身份,运行下面的命令:

yum install -y httpd httpd-devel
yum install -y openssl openssl-devel
yum install -y gcc gcc-c++

安装遇到问题

如若安装yum会报错:

  • 段错误,
  • cachce错误
  • Repository AppStream is listed more than once in the configuration
  • Repository extras is listed more than once in the configuration
  • Repository PowerTools is listed more than once in the configuration
  • Repository centosplus is listed more than once in the configuration

请参考原文链接进行查错修复.

stub status配置

编辑 Apache 的配置文件(通常位于 /etc/httpd/conf/httpd.conf 或 /etc/apache2/apache2.conf)并确保包含以下内容:

<Location "/server-status">
    SetHandler server-status
</Location>
  • <Location “/server-status”>:Location 指令用于匹配客户端请求的 URL 路径。在这个例子中,/server-status 是客户端请求的路径。例如,如果你访问 http://your-server-ip/server-status,这个配置块就会生效。

  • SetHandler server-status:SetHandler 指令告诉 Apache 对该路径使用 server-status 处理程序。server-status 是 Apache 提供的一个内置处理程序,负责输出服务器的状态信息。这些信息包括当前的请求处理情况、工作线程状态、系统性能等。

启动apache

sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl status httpd - 检查其是否运行

![Apache stub staus] https://statuslist.app/apache/apache-status-page-simple-setup-guide/

categraf input.apache插件

配置 conf/input.apache/apache.toml 内容如下

[[instances]]
scrape_uri = "http://localhost/server-status/?auto"
host_override = ""
insecure = false
custom_headers = {}
log_level = "info"

启动categraf 测试,可以看到已经可以采集到指标了 Apache stub status指标

指标包含了请求链接、读写等简单的指标。

关于作者

本文作者王玉松,快猫星云技术实习生,文章内容是快猫技术团队共同沉淀的结晶。我们会持续输出监控、稳定性保障相关的技术文章,文章可转载,转载请注明出处,尊重技术人员的成果。

快猫星云 联系方式 快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云
OpenSource
开源版
Flashcat
Flashcat
FlashDuty
Flashduty