Prometheus+Grafana监控安装及使用
前言:Prometheus Server: Prometheus服务端,由于存储及收集数据,提供相关api对外查询用。Exporter: 类似传统意义上的被监控端的agent,有区别的是,它不会主动推送监控数据到server端,而是等待server端定时来手机数据,即所谓的主动监控。Pushagateway: 用于网络不可直达而居于exporter与server端的中转站。Alertmanager
前言:
Prometheus Server: Prometheus服务端,由于存储及收集数据,提供相关api对外查询用。
Exporter: 类似传统意义上的被监控端的agent,有区别的是,它不会主动推送监控数据到server端,而是等待server端定时来手机数据,即所谓的主动监控。
Pushagateway: 用于网络不可直达而居于exporter与server端的中转站。
Alertmanager: 报警组件,将报警的功能单独剥离出来放在alertmanager。
Web UI: Prometheus的web接口,可用于简单可视化,及语句执行或者服务状态监控。
一、实验所需包
1.prometheus-2.20.1.linux-amd64.tar 【提取码:mgnf 】
2.node_exporter-1.0.1.linux-amd64.tar【提取码:opue 】
3.nginx-vts-exporter-0.10.3.linux-amd64.tar【提取码:v3rd 】
4.grafana-7.1.4-1.x86_64 【提取码:7cjb 】
二、安装Prometheus
#确保selinux和firewalld关闭
[root@node-3 ~]# getenforce
Disabled
[root@node-3 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@node-3 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@node-3 ~]# tar -xvf prometheus-2.20.1.linux-amd64.tar.gz
[root@node-3 ~]# cd prometheus-2.20.1.linux-amd64
[root@node-3 prometheus-2.20.1.linux-amd64]# vim prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
#添加prometheus端口
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.200.223:9090']
#添加所需要监控的linux主机端口
- job_name: 'linux'
static_configs:
- targets: ['192.168.200.223:9100']
- targets: ['192.168.200.221:9101'] #根据实际情况添加监控主机ip
- targets: ['192.168.200.222:9101']
- job_name: 'pushgateway'
static_configs:
- targets: ['192.168.200.223:9091']
honor_labels: true
#添加nginx监控
- job_name: 'nginx'
static_configs:
- targets: ['192.168.200.223:9913']
labels:
instance: web1
:wq #保存并退出
[root@node-3 ~]# ll /usr/local/prometheus #利用ln -s做一个软连接相当于快捷方式吧,个人习惯
lrwxrwxrwx 1 root root 42 8月 24 16:02 /usr/local/prometheus -> /srv/program/prometheus-2.20.1.linux-amd64
[root@node-3 ~]# nohup /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data &
访问测试prometheus:
http://192.168.200.223:9090/graph
通过点击下拉栏选取指标,点击”Excute” 我们能够看到Prometheus的性能指标。
成功!
二、安装Grafana以及node_exporter
######node_exporter安装######
[root@node-3 soft]# tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz
[root@node-3 soft]# cd node_exporter-1.0.1.linux-amd64
#默认端口9100,如果被占用可以指定端口nohup /srv/soft/node_exporter-1.0.1.linux-amd64/node_exporter --web.listen-address=":9101"&
[root@node-3 node_exporter-1.0.1.linux-amd64]# nohup /srv/soft/node_exporter-1.0.1.linux-amd64/node_exporter &
#验证node_exporter是否安装成功
[root@node-3 node_exporter-1.0.1.linux-amd64]# curl 127.0.0.1:9100
<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>[root@node-3 node_exporter-1.0.1.linux-amd64]#
#使用以下命令会返回一堆性能指标则表明安装ojbk
[root@node-3 node_exporter-1.0.1.linux-amd64]# curl 127.0.0.1:9100/metrics
#####Grafana安装#####
[root@node-3 soft]# yum -y install grafana-7.1.4-1.x86_64.rpm
#编辑配置文件/etc/grafana/grafana.ini ,修改dashboards.json段落下两个参数的值:
[root@node-3 ~]# vim /etc/grafana/grafana.ini
#################################### Dashboards History ##################
[dashboards]
# Number dashboard versions to keep (per dashboard). Default: 20, Minimum: 1
;versions_to_keep = 20
enabled = true
# Minimum dashboard refresh interval. When set, this will restrict users to set the refresh interval of a dashboard lower than given interval. Per default this is 5 seconds.
# The interval string is a possibly signed sequence of decimal numbers, followed by a unit suffix (ms, s, m, h, d), e.g. 30s or 1m.
;min_refresh_interval = 5s
# Path to the default home dashboard. If this value is empty, then Grafana uses StaticRootPath + "dashboards/home.json"
#default_home_dashboard_path = /var/lib/grafana/dashboards/Home_Dashboard.json
path = /var/lib/grafana/dashboards
[root@node-3 soft]# git clone https://github.com/percona/grafana-dashboards.git
[root@node-3 soft]# cp -r grafana-dashboards/dashboards /var/lib/grafana/
[root@node-3 soft]# cd /var/lib/grafana/
[root@node-3 grafana]# chown -R grafana.grafana dashboards
[root@node-3 grafana]# ll
总用量 736
drwxr-xr-x 2 grafana grafana 4096 8月 24 15:57 dashboards
-rw-r--r-- 1 grafana grafana 749568 10月 12 11:30 grafana.db
drwxr-xr-x 2 grafana grafana 6 8月 24 16:51 plugins
drwx------ 2 grafana grafana 6 8月 24 16:51 png
[root@node-3 grafana]# systemctl start grafana-server
[root@node-3 grafana]# netstat -ntlupa |grep 3000
tcp6 0 0 :::3000 :::* LISTEN 12633/grafana-serve
三、链接Grafana+Prometheus
访问:http://192.168.200.223:3000/
设置数据源
数据源配置如下图
保存并测试
四、结果验收
访问:http://192.168.200.223:3000/
总结
本次将把nginx-vts-exporter-0.10.3.linux-amd64.tar包的使用留到下篇博客,此包是用于监控Nginx服务基本状况。
更多推荐
所有评论(0)