首页 > 其他分享 >使用docker-compose快速部署Prometheus+grafana环境

使用docker-compose快速部署Prometheus+grafana环境

时间:2023-02-25 01:33:20浏览次数:52  
标签:grafana0 compose lib prometheus grafana Prometheus var docker

由于最近公司服务频繁出问题,老板很生气,下面的人都很不好过,于是老大让加一下业务监控,来观察线上数据状态。
但是由于qa环境数据量太少,所以自己搭建了一套环境做相关监控,并且写了个脚本模仿生产上的数据,并且做了很多指标,写了一些Grafana的PromQL语法,网上的资料也很少,我就来补充一下,这个下一章再讲。

注意:
docker和docker-compose请自行下载安装

创建相关目录并给予权限,持久化目录需要给777权限,否则容器启动失败

cd ~ && mkdir prometheus && chmod 777 prometheus
cd prometheus && mkdir grafana_data prometheus_data && chmod 777 grafana_data prometheus_data

vim docker-compose.yml

version: "3.7"
services:
  node-exporter:
    image: prom/node-exporter:latest
    container_name: "node-exporter0"
    ports:
      - "9100:9100"
    restart: always
  prometheus:
    image: prom/prometheus:latest
    container_name: "prometheus0"
    restart: always
    ports:
      - "9090:9090"
    volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"
      - "./prometheus_data:/prometheus"
  grafana:
    image: grafana/grafana
    container_name: "grafana0"
    ports:
      - "3000:3000"
    restart: always
    volumes:
      - "./grafana_data:/var/lib/grafana"

注:prometheus主机需要部署以上容器,其他被监控主机只需要部署node-exporter

3.prometheus配置文件(根据自己的服务器ip进行修改targets内容)

vim prometheus.yml

global:
  scrape_interval:     15s # 默认抓取周期
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
  - job_name: 'node-exporter' #服务的名称
    scrape_interval: 5s
    metrics_path: /metrics  #获取指标的url
    static_configs:
      - targets: ['139.224.224.229:9100'] # 这个为监听指定服务服务的ip和port,需要修改为自己的ip,貌似云服务必须用公网ip

4.docker-compose启动

docker-compose up -d         # 挂载目录给权限,不然会启动失败

如果启动报如下的"没有权限"错误:

grafana0         | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana0         | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
grafana0         | GF_PATHS_DATA='/var/lib/grafana' is not writable.
grafana0         | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana0         | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
grafana0         | GF_PATHS_DATA='/var/lib/grafana' is not writable.
grafana0         | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana0         | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
grafana0         | GF_PATHS_DATA='/var/lib/grafana' is not writable.
grafana0         | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana0         | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
grafana0         | GF_PATHS_DATA='/var/lib/grafana' is not writable.
grafana0         | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana0         | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied

则需要将挂载目录赋予权限,即:
chmod 777 grafana_data/ prometheus_data/ #个人根据配置文件中具体的挂在目录进行权限修改

5.访问主机的9090端口可以查到Prometheus监控到的数据,访问3000端口是grafana的界面,账密admin/admin

6.配置监控,点击齿轮,选择Data Sources
image

7.点击Add data source
image

8.填写prometheus地址 ip+端口或者主机名+端口(需要配置hosts)
image

9.点击save&test
image

10.点击+号,选择import
image

11.输入模板号9276,点击load。    8919
image
image

11.导入模板完成
image

  标签: GolangGrafanaPrometheus监控

标签:grafana0,compose,lib,prometheus,grafana,Prometheus,var,docker
From: https://www.cnblogs.com/exmyth/p/17153658.html

相关文章

  • 性能测试-grafana + prometheus + node_exporter
    1、grafana安装下载网址:https://grafana.com/grafana/download/7.4.3?platform=linux#下载wgethttps://dl.grafana.com/enterprise/release/grafana-enterprise-7.4.3......
  • grafana展示的CPU利用率与实际不符的问题探究
    问题描述最近看了一个虚机的CPU使用情况,使用mpstat-PALL命令查看系统的CPU情况(该系统只有一个CPUcore),发现该CPU的%usr长期维持在70%左右,且%sys也长期维持在20%左右:0......
  • 最易懂的Prometheus告警原理详解
    通俗易懂的一篇文章,主要介绍了Prometheus什么时候告警,什么时候不会告警。同时介绍了Prometheus告警原理。 警报是监控系统中必不可少的一块,当然了,也是最难......
  • Prometheus安装部署(主体)
    Prometheus安装部署一,下载安装包并解压下载地址:https://github.com/prometheus/prometheus/releases因为服务器上下载速度太慢,所以可以提前在物理机上下载上传到服务器,......
  • <<运维监控系统实战笔记>> 小记随笔 —— Prometheus 初识
    Prometheus简介Prometheusserver包含时序库、告警引擎、数据展示三大块,体系中最核心的组件Exporters采集数据的客户端,负载采集数据存在内存中,提供http接口,让......
  • Prometheus监控各类程序
    一、Prometheus安装github:https://github.com/prometheus/prometheus官网: https://prometheus.io#1下载prometheus-v2.40.7镜像https://hub.docker.com/r/prom/pro......
  • Prometheus&Alertmanager告警推送
    前言尽管可以通过可视化数据监控系统运行状态,但我们无法时刻关注系统运行,因此需要一些实时运行的工具能够辅助监控系统运行,当系统出现运行问题时,能够通知我们,以此确保系统......
  • Prometheus学习笔记之设置存储时间为30天不生效
    0x00概述Prometheus升级到2.23进行测试发现,设置存储时间为30天未生效,根据官方说明手册,实际运行后发现数据只能存储几个小时。。。。--storage.tsdb.retention.time=30d......
  • prometheus监控平台学习
    架构图PrometheusServer:收集指标和存储时间序列数据,并提供查询接口ClientLibrary:客户端库PushGateway:短期存储指标数据。主要用于临时性的任务Exporters:采......
  • Java编写监控指标并集成Prometheus、Grafana
    一、Pushgateway1、上传pushgateway-1.4.3.linux-amd64.tar.gz至/opt/soft/下载地址:https://github.com/prometheus/pushgateway/releases/download/v1.4.3/pushgate......