Docker搭建prometheus

Reads: 18 Edit

启动premetheus

新建目录prometheus,编辑配置文件prometheus.yml

mkdir /opt/prometheus
cd /opt/prometheus/
vim 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.100.11:9187']
        labels:
          instance: localhost

注意:修改IP地址,这里的192.168.100.11 就是本机地址

启动prometheus

docker run  -d \
  -p 9090:9090 \
  -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
  prom/prometheus

等待几秒钟,查看端口状态

[root@bogon prometheus]# 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:3306            0.0.0.0:*               LISTEN      3649/docker-proxy   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1066/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1064/cupsd          
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      4009/docker-proxy   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1255/master         
tcp        0      0 0.0.0.0:9090            0.0.0.0:*               LISTEN      32233/docker-proxy  
tcp        0      0 192.168.100.11:22       192.168.100.1:55193     ESTABLISHED 8241/sshd: root@pts 
tcp        0     52 192.168.100.11:22       192.168.100.1:55192     ESTABLISHED 8239/sshd: root@pts 
tcp        0      0 192.168.100.11:22       192.168.100.1:55194     ESTABLISHED 8292/sshd: root@pts 
tcp        0      0 192.168.100.11:22       192.168.100.1:61217     ESTABLISHED 18279/sshd: root@no 
tcp6       0      0 :::3306                 :::*                    LISTEN      3655/docker-proxy   
tcp6       0      0 :::22                   :::*                    LISTEN      1066/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1064/cupsd          
tcp6       0      0 :::5432                 :::*                    LISTEN      4014/docker-proxy   
tcp6       0      0 ::1:25                  :::*                    LISTEN      1255/master         
tcp6       0      0 :::9090                 :::*                    LISTEN      32238/docker-proxy  
tcp6       0      0 :::9187                 :::*                    LISTEN      14032/./bin/opengau 

访问url:

http://192.168.100.11:9090/graph

访问targets,url如下:

http://192.168.100.11:9090/targets

启动grafana

新建空文件夹grafana-storage,用来存储数据

mkdir /opt/grafana-storage

设置权限

chmod 777 -R /opt/grafana-storage

启动grafana

docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -v /opt/grafana-storage:/var/lib/grafana \
  grafana/grafana

访问url:

http://192.168.100.11:3000/

默认会先跳转到登录页面,默认的用户名和密码都是admin

参考资料

https://www.cnblogs.com/xiao987334176/p/9930517.html#autoid-5-4-0

Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。