下载镜像
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
安装node-export
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter
查看端口:
[root@dev-002 ~]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1080/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 1880/docker-proxy
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1240/master
tcp 0 52 192.168.0.152:22 192.168.2.192:59308 ESTABLISHED 1811/sshd: root@pts
tcp6 0 0 :::9100 :::* LISTEN 2180/node_exporter
tcp6 0 0 :::22 :::* LISTEN 1080/sshd
tcp6 0 0 :::3000 :::* LISTEN 1886/docker-proxy
tcp6 0 0 ::1:25 :::* LISTEN 1240/master
tcp6 0 0 192.168.0.152:9100 172.17.0.3:54128 ESTABLISHED 2180/node_exporter
访问url
http://192.168.0.152:9100/metrics
新建Prometheus文件夹:
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml
编辑配置文件prometheus.yml:
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.0.152:9100']
labels:
instance: localhost
启动prometheus
docker run -d \
-p 9090:9090 \
-v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
[root@dev-002 ~]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 2013/docker-proxy
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1080/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 1880/docker-proxy
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1240/master
tcp 0 52 192.168.0.152:22 192.168.2.192:59308 ESTABLISHED 1811/sshd: root@pts
tcp6 0 0 :::9090 :::* LISTEN 2020/docker-proxy
tcp6 0 0 :::9100 :::* LISTEN 2180/node_exporter
tcp6 0 0 :::22 :::* LISTEN 1080/sshd
tcp6 0 0 :::3000 :::* LISTEN 1886/docker-proxy
tcp6 0 0 ::1:25 :::* LISTEN 1240/master
tcp6 0 0 192.168.0.152:9100 172.17.0.3:54128 ESTABLISHED 2180/node_exporter
访问url
http://192.168.0.152:9090/graph
启动grafana
新建空文件夹grafana-storage,用来存储数据
mkdir /opt/grafana-storage
设置权限
chmod 777 -R /opt/grafana-storage
因为grafana用户会在这个目录写入文件,直接设置777
启动grafana
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \
grafana/grafana
查看端口状态
[root@dev-002 ~]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 2013/docker-proxy
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1080/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 1880/docker-proxy
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1240/master
tcp 0 52 192.168.0.152:22 192.168.2.192:59308 ESTABLISHED 1811/sshd: root@pts
tcp6 0 0 :::9090 :::* LISTEN 2020/docker-proxy
tcp6 0 0 :::9100 :::* LISTEN 2180/node_exporter
tcp6 0 0 :::22 :::* LISTEN 1080/sshd
tcp6 0 0 :::3000 :::* LISTEN 1886/docker-proxy
tcp6 0 0 ::1:25 :::* LISTEN 1240/master
tcp6 0 0 192.168.0.152:9100 172.17.0.3:54128 ESTABLISHED 2180/node_exporter
访问url:
http://192.168.91.132:3000/
配置:Grafana
配置数据源
配置:dashboards
UID:11074