为nagios添加性能图表展示-influxDB+Nagflux+Grafana+Histou

组件介绍

InfluxDB:时序数据库保存性能数据

Nagflux:将性能数据从nagios导入到InfluxDB的程序

Grafana:基于web的分析平台,可以将性能数据库从InfluxDB展示到web,实现数据可视化

Histou:为Grafana添加上Nagios性能数据创建的图表

为nagios添加性能图表展示-influxDB+Nagflux+Grafana+Histou


influxDB安装

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.4.x86_64.rpm

yum localinstall influxdb-1.5.4.x86_64.rpm

为nagios添加性能图表展示-influxDB+Nagflux+Grafana+Histou

设置开机启动并启动服务:

systemctl enable influxdb.service

systemctl start influxdb.service


创建数据库

influx

>create database nagflux

#验证数据库是否创建成功

curl -G "http://localhost:8086/query?pretty=true" --data-urlencode "q=show databases"


nagflux(需要go环境)

安装go环境:

yum install -y golang git

通过github下载安装:

export GOPATH=$HOME/gorepo

mkdir $GOPATH

go get -v -u github.com/griesbacher/nagflux

go build github.com/griesbacher/nagflux

mkdir -p /opt/nagflux

cp $GOPATH/bin/nagflux /opt/nagflux/

mkdir -p /usr/local/nagios/var/spool/nagfluxperfdata

chown nagios:nagios /usr/local/nagios/var/spool/nagfluxperfdata

安装启动脚本并设置开机启动:

cp $GOPATH/src/github.com/griesbacher/nagflux/nagflux.service /usr/lib/systemd/system/

chmod +x /usr/lib/systemd/system/nagflux.service

systemctl daemon-reload

systemctl enable nagflux.service

配置nagflux:

vim /opt/nagflux/config.gcfg

[main]

NagiosSpoolfileFolder = "/usr/local/nagios/var/spool/nagfluxperfdata"

NagiosSpoolfileWorker = 1

InfluxWorker = 2

MaxInfluxWorker = 5

DumpFile = "nagflux.dump"

NagfluxSpoolfileFolder = "/usr/local/nagios/var/nagflux"

FieldSeparator = "&"

BufferSize = 10000

FileBufferSize = 65536

DefaultTarget = "all"

[Log]

LogFile = ""

MinSeverity = "INFO"

[InfluxDBGlobal]

CreateDatabaseIfNotExists = true

NastyString = ""

NastyStringToReplace = ""

HostcheckAlias = "hostcheck"

[InfluxDB "nagflux"]

Enabled = true

Version = 1.0

Address = "http://127.0.0.1:8086"

Arguments = "precision=ms&u=root&p=root&db=nagflux"

StopPullingDataIfDown = true

[InfluxDB "fast"]

Enabled = false

Version = 1.0

Address = "http://127.0.0.1:8086"

Arguments = "precision=ms&u=root&p=root&db=fast"

StopPullingDataIfDown = false


Grafana

yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.4-1.x86_64.rpm

设置开机启动并启动服务:

systemctl enable grafana-server.service

systemctl start grafana-server.service

默认的用户名密码:admin/admin

为nagios添加性能图表展示-influxDB+Nagflux+Grafana+Histou


histou

cd /tmp

wget -O histou.tar.gz https://github.com/Griesbacher/histou/archive/v0.4.3.tar.gz

mkdir -p /var/www/html/histou

cd /var/www/html/histou

tar xzf /tmp/histou.tar.gz --strip-components 1

cp histou.ini.example histou.ini

cp histou.js /usr/share/grafana/public/dashboards/


Nagios 配置

vim /usr/local/nagios/etc/nagios.conf

#添加下面内容

process_performance_data=1

host_perfdata_file=/usr/local/nagios/var/host-perfdata

host_perfdata_file_template=DATATYPE::HOSTPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ HOSTPERFDATA::$HOSTPERFDATA$ HOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$

host_perfdata_file_mode=a

host_perfdata_file_processing_interval=15

host_perfdata_file_processing_command=process-host-perfdata-file-nagflux

service_perfdata_file=/usr/local/nagios/var/service-perfdata

service_perfdata_file_template=DATATYPE::SERVICEPERFDATA TIMET::$TIMET$ HOSTNAME::$HOSTNAME$ SERVICEDESC::$SERVICEDESC$ SERVICEPERFDATA::$SERVICEPERFDATA$ SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$

service_perfdata_file_mode=a

service_perfdata_file_processing_interval=15

service_perfdata_file_processing_command=process-service-perfdata-file-nagflux

vim /usr/local/nagios/etc/objects/commands.cfg

#添加下面内容

define command {

command_name process-host-perfdata-file-nagflux

command_line /bin/mv /usr/local/nagios/var/host-perfdata /usr/local/nagios/var/spool/nagfluxperfdata/$TIMET$.perfdata.host

}

define command {

command_name process-service-perfdata-file-nagflux

command_line /bin/mv /usr/local/nagios/var/service-perfdata /usr/local/nagios/var/spool/nagfluxperfdata/$TIMET$.perfdata.service

}


重启nagios服务

mkdir -p /usr/local/nagios/var /usr/local/nagios/var/nagflux /usr/local/nagios/var/spool/nagfluxperfdata

systemctl reload nagios

验证nagflux是否导入数据成功

curl -G "http://localhost:8086/query?db=nagflux&pretty=true" --data-urlencode "q=show series"


设置grafana数据源

1、add data source

2、设置数据源信息

Name: nagflux

Type: InfluxDB

HTTP

URL: http://localhost:8086

Access: proxy

Auth: Leave settings as default

InfluxDB Details

Database: nagflux

User & Password: 为空

3、Save & Test


Histou 配置

grafana调用的js文件/usr/share/grafana/public/dashboards/histou.js找到

var url = 'http://localhost/histou/';

将localhost换成浏览器能访问到histou的地址

sed -i 's/localhost/192.168.4.22/g' /usr/share/grafana/public/dashboards/histou.js

验证histou是否可以获取到数据

curl -G "http://localhost/histou/?host=localhost&service=PING"

验证grafana是否可以取到数据

http://nagios_server:3000/dashboard/script/histou.js?host=host_object&service=service_object

nagios_server = grafana的地址

3000 = grafana的端口

host_object = 主机对象

service_object = 服务名称

修改nagios的模板,加入图形链接

define host {

name host-grafana

action_url http://nagios_server:3000/dashboard/script/histou.js?host=$HOSTNAME$

register 0

}

define service {

name service-grafana

action_url http://nagios_server:3000/dashboard/script/histou.js?host=$HOSTNAME$&service=$SERVICEDESC$

register 0

}

相关推荐