应朋友们要求,介绍上Linux系统下的实时监控平台,在上次提到了glances,它提供了较多的监控指标,那如果我们要看历史数据呢?某一时间段的回放呢?显然glances是做不到的。因此,实时监控平台就应运而生了。
平台采用Grafana+ Prometheus 构建,Grafana 是炫丽的可视化框架,Prometheus 是在监控方面较为流行的时序数据库,采用GO语言开发,我们知道,监控平台大部分是在不断产生时间序列数据,进而进行监控回放,实时更新数据等。此外,Prometheus 提供了强大的导出器功能,支持常见业务系统的监控,如InfluxDB,PostgreSQL,Kafka,服务器监控等。
下面,我们来看看软件在Ubuntu Server 16.04 系统下的安装:
- Grafana安装
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana
修改配置文件/etc/grafana//grafana.ini
.........
[server]
http_addr:监听的ip地址,,默认是0.0.0.0,即所有IP
http_port:监听的端口,默认是3000
安装后,会自动新建systemd服务,可通过以下命令启动服务:
systemctl start grafana-server
2.Prometheus
新建prometheus用户
sudo useradd --no-create-home --shell /bin/false prometheus
新建 /etc/prometheus(存放配置文件)和/var/lib/prometheus(存放数据文件)目录,并更改属主为prometheus。
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
下载Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz --no-check-certificate
解压Prometheus
tar -zxvf prometheus-2.10.0.linux-amd64.tar.gz
创建软连接
ln -s /usr/local/prometheus-2.11.0-rc.0.linux-amd64 /usr/local/prometheus
将两个执行脚本复制到该/usr/local/bin目录,并更改属主为prometheus。
sudo cp /usr/local/prometheus/prometheus /usr/local/bin/
sudo cp /usr/local/prometheus/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
将consoles和console_libraries目录复制到/etc/prometheus,并更改属主为prometheus。
sudo cp -r /usr/local/prometheus/consoles /etc/prometheus
sudo cp -r /usr/local/prometheus/console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
修改prometheus的配置文件prometheus.yml
vim /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['127.0.0.1:9090']
- job_name: 'node_exporter'
scrape_interval: 5s
static_configs:
#--storage.tsdb.path: /etc/prometheus/data
#--storage.tsdb.retention.time: 15d
#--storage.tsdb.retention.size: 1GB
scrape_interval——指标更新时间间隔
job_name——为实例服务的配置,包括prometheus和各种导出器
配置systemd服务:
sudo vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus
--config.file /etc/prometheus/prometheus.yml
--storage.tsdb.path /var/lib/prometheus/
--web.console.templates=/etc/prometheus/consoles
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
重载systemd
systemctl daemon-reload
启动Prometheus
systemctl start prometheus
访问Grafana
http://127.0.0.1:3000/
访问prometheus
http://127.0.0.1:9090/
到此,我们就完成了Grafana和Prometheus的安装,下期会介绍常用导出器的配置,如node_exporter,bind_exporter和redis_exporter,下期见。