zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Docker-安装Prometheus、grafana

Docker安装 Prometheus Grafana
2023-09-11 14:14:34 时间

1.拉取镜像包

docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
 

2.启动node-exporter[方便测试Prometheus]

docker run -d -p 9100:9100 \
  -v "/home/fz/docker/node-exporter/proc:/host/proc:ro" \
  -v "/home/fz/docker/node-exporter/sys:/host/sys:ro" \
  -v "/home/fz/docker/node-exporter/:/rootfs:ro" \
  --net="host" \
  prom/node-exporter
 
http://localhost:9100/metrics
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 0
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.16.7"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.346552e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.346552e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.445106e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 730
# HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started.
# TYPE go_memstats_gc_cpu_fraction gauge
go_memstats_gc_cpu_fraction 0
 

3.启动prometheus

mkdir /home/fz/docker/prometheus
cd /home/fz/docker/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: ['localhost:9100']
          labels:
            instance: localhost
    - job_name: clickhouse-1
      static_configs:
        - targets: ['xx1:9363','xx2:9363','xx3:9363']
          labels:
            instance: localhost

此处配置了一个clickhouse集群,如有没有直接删掉相关配置即可。

 
启动
docker run  -d  -p 9090:9090 -v /home/fz/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
 
http://localhost:9090/graph
 

4.启动grafana

创建映射的数据卷 
mkdir /home/fz/docker/grafana-storage
chmod 777 -R /home/fz/docker/grafana-storage

 启动

docker run -d -p 3000:3000 --name=grafana  -v /home/fz/docker/grafana-storage:/var/lib/grafana grafana/grafana
http://localhost:3000/login
默认用户名密码:admin/admin