首页 > 其他分享 >使用docker安装prometeus和grafana

使用docker安装prometeus和grafana

时间:2023-03-15 14:45:44浏览次数:57  
标签:job scrape grafana prometheus docker prometeus localhost

1.拉取镜像

docker pull prom/prometheus
docker pull prom/pushgateway
docker pull grafana/grafana

2.部署prometheus

2.1创建 prometheus.yaml

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# 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.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

2.2 启动prometheus.yaml

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

启动后,可以localhost:9090 查看页面

3.启动pushgateway

3.1 启动

docker run -d -p 9091:9091 prom/pushgateway

启动后,可以localhost:9091 查看页面

3.2 测试数据

推送pushgateway

echo "word_count 1" | curl --data-binary @- http://localhost:9091/metrics/job/wdx_job
echo "word_count 1" | curl --data-binary @- http://localhost:9091/metrics/job/wdx_job/instance/wdx_instance1

测试推送更为复杂的数据

cat <<EOF | curl --data-binary @- http://localhost:9091/metrics/job/wdx_job/instance/wdx_instance1
  # TYPE word_count counter
  word_count{label="tag1"} 42
  # TYPE another_metric gauge
  # HELP another_metric Just an example.
  another_metric 2398.283
  EOF

删除指标

curl -X DELETE http://localhost:9091/metrics/job/wdx_job
curl -X DELETE http://localhost:9091/metrics/job/wdx_job/instance/wdx_instance1

3.3 在prometheus上增加Job

编辑prometheus.yaml,添加Job

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# 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.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']
config.
  - job_name: 'wdx_job'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['host.docker.internal:9091']  #docker容器间可以借助host.docker.internal,但是线上环境应该使用可访问的ip + 端口

4.启动grafana

docker run -d --name=grafana -p 3000:3000 grafana/grafana

启动后,可以localhost:3000 查看页面

grafana的操作,可以参考文档:https://blog.csdn.net/weixin_52270081/article/details/125845193

5.注意问题

使用docker部署,三个服务启动以后,容器之间无法互通,需要借助 宿主机host:端口进行访问

host.docker.internal:端口

标签:job,scrape,grafana,prometheus,docker,prometeus,localhost
From: https://www.cnblogs.com/hbuwdx/p/17218448.html

相关文章

  • docker-compose一键部署fastdfs6.0.9
    通过docker部署fastdfs版本号:6.0.9目录规划如下:应用目录:/usr/local/fdfs/docker-compose/数据目录:/data/fdfs/docker-compose.yaml示例文件如下version:'3'ser......
  • docker-compose报错解决
    文章目录docker-compose报错解决情景解决方法情景在使用docker-compose进行环境搭建的时候,出现以下报错   errorgettingcredentials-err:exitstatus1,out:......
  • docker stop 容器,连接被拒绝
    dockerstop容器ID报错,无法kill,连接被拒绝经过网上查找以及实际情况,发现原因为:服务器重启时,正在运行的docker内的容器正在进行处理,因为docker没有提前关闭,导致docker......
  • Docker CLI docker checkpoint常用命令
    Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。Doc......
  • docker及docker-compose命令大全
    dockerstart容器id或容器名 启动容器dockerstop容器id/容器名 停止容器dockerrestart容器id/容器名 重启容器dockerrm容器id/容器名  删除容器docker......
  • docker-compose 部署单节点mysql8
    docker-compose部署单节点mysql81.docker-compose文件准备docker-compose-kpi.ymlversion:"3.2"services:mysql:image:mysql:8.0restart:alway......
  • docker-compose 部署单节点redis
    docker-compose部署单节点redis1.docker-compose文件准备docker-compose-kpi.ymlversion:"3.2"services:redis:image:redis:6container_name:r......
  • Docker搭建Mysql集群
    Docker搭建Mysql集群前言:使用PXC集群方案搭建集群安装PXC镜像dockerpullpercona/percona-xtradb-cluster:5.7.21改名dockertagpercona/percona-xtradb-clus......
  • Docker学习
    阿里云镜像获取地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors  docker启动命令1启动dockersystemctlstartdocker2关闭dockersystemc......
  • Docker - 部署抓包/host代理工具 Whistle
    编写DockerfileFROMalpineEXPOSE8899RUNapkadd--no-cachenodejsnpm\&&npminstallwhistle-g\&&apkdelnpm\&&mkdir/whistleENTRYPOI......