在 CentOS 7 上为 Nagios Core 安装 PNP4Nagios 插件

安装和配置 PNP4Nagios查看之前的教程 :在 CentOS 7 上为 Nagios Core安装 PNP4Nagios插件

在 CentOS 7 上安装带有 PNP4Nagios插件 的 Grafana

Grafana 是一个免费的开源软件,用于创建数字时间序列数据的图形,例如计算机系统的性能数据。

Grafana 是当今最大的 Graphite 替代可视化工具。
Grafana 可以从 Elastic Search、InfluxDB、CloudWatch 等各种数据源收集数据。
Grafana 支持不同类型的图形面板,包括 Graphs、Heatmaps 和 Tables。

在本文中,我们将在 CentOS 7 上安装 Grafana,并通过 PNP4Nagios 插件将 Grafana 与 Nagios Core 集成。

为了简单起见,我们将 Nagios Core 和 Grafana 安装在同一台机器上,但是,如果需要,Nagios Core 和 Grafana 可以安装在单独的机器上。

在 CentOS 7 上安装 Nagios Core

首先,我们需要配置一个 Nagios Core 服务器来收集网络和计算机的性能数据。

安装过程查看我们之前的教程 在 CentOS 7 上安装和配置 Nagios Core 4.4

更多: zhilu jiaocheng

在 CentOS 7 上安装 Grafana

浏览 URL http://docs.grafana.org/installation/rpm/ 并根据操作系统和平台下载 Grafana。

[root@nagios-01 ~]# wget https://dl.grafana.com/oss/release/grafana-5.4.3-1.x86_64.rpm

使用 yum 命令安装 Grafana。

[root@nagios-01 ~]# yum install -y grafana-5.4.3-1.x86_64.rpm

启动并启用 Grafana 服务。

[root@nagios-01 ~]# systemctl daemon-reload
[root@nagios-01 ~]# systemctl enable grafana-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
[root@nagios-01 ~]# systemctl start grafana-server.service

在 Linux 防火墙中允许 Grafana 服务端口。

[root@nagios-01 ~]# firewall-cmd --permanent --add-port=3000/tcp
success
[root@nagios-01 ~]# firewall-cmd --reload
success

为 Grafana 安装 PNP 插件。

[root@nagios-01 ~]# grafana-cli plugins install sni-pnp-datasource
installing sni-pnp-datasource @ 1.0.5
from url: https://grafana.com/api/plugins/sni-pnp-datasource/versions/1.0.5/download
into: /var/lib/grafana/plugins
-> Installed sni-pnp-datasource successfully
Restart grafana after installing plugins . <service grafana-server restart>

下载 Grafana API。

[root@nagios-01 ~]# cd /usr/local/pnp4nagios/share/application/controllers/
[root@nagios-01 controllers]# wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

重启 Grafana 服务。

[root@nagios-01 ~]# systemctl restart grafana-server.service

允许 Grafana 访问 PNP4Nagios Web 服务,执行以下操作或者手动编辑 /etc/httpd/conf.d/pnp4nagios.conf 文件。

[root@nagios-01 ~]# sed -i '/Allow from all/a\        Allow from 127.0.0.1 ::1' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i '/Require valid-user/a\        Require all granted' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i 's/Allow from all/#&/' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i 's/AuthName/#&/' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i 's/AuthType Basic/#&/' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i 's/AuthUserFile/#&/' /etc/httpd/conf.d/pnp4nagios.conf
[root@nagios-01 ~]# sed -i 's/Require valid-user/#&/' /etc/httpd/conf.d/pnp4nagios.conf

重启 Apache 服务。

[root@nagios-01 ~]# systemctl restart httpd.service

测试 PNP4Nagios Web 服务无需身份验证即可在本地访问。

[root@nagios-01 ~]# curl http://localhost/pnp4nagios
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://localhost/pnp4nagios/">here</a>.</p>
</body></html>

我们得到了一个 301 重定向错误,这意味着我们的配置没有问题。

将 PNP4Nagios 配置为 Grafana 的数据源

浏览 URL https://nagios-01.onitroad.com:3000 。

使用默认用户名 admin 和密码 admin 登录。

由于我们是第一次登录 Grafana,因此它会要求我们更改管理员用户的密码。

设置一个新密码,然后单击“保存”。

我们现在位于 Grafana 仪表板。

单击添加数据源。

在此处选择数据源类型为 PNP。

如上输入配置,然后单击“保存并测试”。

如果配置正确,Grafana 将显示“数据源正在工作”。

我们已经定义了一个数据源 PNP-1 ,现在我们必须为来自我们数据源的数据创建一个仪表板。

单击左侧工具列上的 以创建仪表板。

单击仪表板时,它会询问我们要添加到仪表板中的面板类型。

让我们通过单击 Graph 添加一个图表面板。

单击编辑以添加数据查询。

我们在上面定义了一个示例数据查询。

单击顶部工具列上的保存图标。

输入仪表板名称并单击保存。

Grafana 一直通过 PNP 从 Nagios Core 收集数据并将其显示在我们的面板中。

日期:2020-09-17 00:16:43 来源:oir作者:oir