prometheus+Grafana监控(docker个人笔记)

下载镜像

# prometheus存储的是时序数据,即按相同时序(相同名称和标签),以时间维度存储连续的数据的集合。
docker pull prom/prometheus
# Grafana全面瓦解  美观、强大的可视化监控指标展示工具
docker pull grafana/grafana
# linux 信息导出
docker pull prom/node-exporter
# redis 信息导出
docker pull oliver006/redis_exporter

linuxl启动node-exporter

docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter

# 访问url查看收集的信息
http://localhost:9100/metrics

启动prometheus

# 创建文件存储配置文件
mkdir /data/prometheus
vim prometheus.yml

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: linux83
    static_configs:
      - targets: ['192.168.204.83:9100']
        labels:
          instance: linux83
# 启动prometheus
# 访问http://localhost:9090
docker run  -d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

查看开启的任务项 

prometheus+Grafana监控(docker个人笔记)_第1张图片

启动grafana

# 创建存储地址
mkdir /data/grafana/storage
chmod 777 /data/grafana/storage
# 启动 grafana
docker run -d -p 3000:3000 --name=grafana -v /data/grafana/storage:/var/lib/grafana grafana/grafana
# 访问网页 默认账号密码都是admin
http://localhost:3000/login

添加数据源  点击 Data Sources

prometheus+Grafana监控(docker个人笔记)_第2张图片

 选择Prometheus

prometheus+Grafana监控(docker个人笔记)_第3张图片

 prometheus+Grafana监控(docker个人笔记)_第4张图片

prometheus+Grafana监控(docker个人笔记)_第5张图片

监控模板下载地址

https://grafana.com/dashboards

linuxl 监控模板   导入node-exporter监控模板,选择import

prometheus+Grafana监控(docker个人笔记)_第6张图片

 在网页上查找想要的模板

prometheus+Grafana监控(docker个人笔记)_第7张图片

prometheus+Grafana监控(docker个人笔记)_第8张图片

 本地填入模板编号,load

prometheus+Grafana监控(docker个人笔记)_第9张图片

prometheus+Grafana监控(docker个人笔记)_第10张图片

我用的 8919

prometheus+Grafana监控(docker个人笔记)_第11张图片

SpringBoot 监控

pom依赖

    
            org.springframework.boot
            spring-boot-starter-actuator
        

        
        
            io.micrometer
            micrometer-registry-prometheus
            1.1.3
        

配置

spring.application.name=SpringBootPrometheus
# 监控端点配置
# 自定义端点路径  将  /actuator/{id}为/manage/{id}
#management.endpoints.web.base-path=/manage
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}

 启动类

@SpringBootApplication
public class FreemarkerApplication {
    @Value("${spring.application.name}")
    private  String application;
    
    public static void main(String[] args) {
        SpringApplication.run(FreemarkerApplication.class, args);
    }
    @Bean
    MeterRegistryCustomizer configurer() {
        return (registry) -> registry.config().commonTags("application", application);
    }
}

 访问url 查看获取的信息  http://localhost:8080/actuator/prometheus

修改prometheus 配置,添加springBoot信息。  vim /data/prometheus/prometheus.yml

global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['192.168.204.83:9090']
        labels:
          instance: prometheus

  - job_name: linux83
    static_configs:
      - targets: ['192.168.204.83:9100']
        labels:
          instance: linux83

  - job_name: SpringBoot8080
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['192.168.1.4:8080']
        labels:
          instance: java8080

重启prometheus

docker restart prom/prometheus

添加监控模板

prometheus+Grafana监控(docker个人笔记)_第12张图片

我用的 11378 

prometheus+Grafana监控(docker个人笔记)_第13张图片

redis 监控

数据源 

# 拉取镜像
docker pull oliver006/redis_exporter
# 启动容器
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter -redis.addr 192.168.204.83:6360 -redis.password 123456
# 访问url查看信息 localhost:9121/metrics

获取监控模板  2751

prometheus+Grafana监控(docker个人笔记)_第14张图片

prometheus+Grafana监控(docker个人笔记)_第15张图片 

你可能感兴趣的:(docker)