码迷,mamicode.com
首页 > 数据库 > 详细

prometheus系列监控:jvm,mongodb,mysql,redis

时间:2020-03-05 22:09:12      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:har   tar   artifact   yml   enc   响应   inter   arp   clu   

jvm:

maven添加dependence

<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.3.5</version>
</dependency>

 

编辑springboot项目的yml文件

yml配置参考https://blog.csdn.net/u014401141/article/details/84784422

 

server:
  port: 8085


spring:
  #for monitor
  application:
    name: mall_prometheus






management:
  #TODO endpoint 解释查询
  endpoints:
    web:
      exposure:
        #include: "*"
        include: info, health, beans, env, metrics, mappings, scheduledtasks, sessions, threaddump, docs, logfile, jolokia, prometheus
      base-path: /actuator #默认该路径,不更改可不用配置
      #cors跨域支持
      cors:
        allowed-origins: http://example.com
        allowed-methods: GET,PUT,POST,DELETE
    prometheus:
      id: springmetrics
  endpoint:
    beans:
      cache:
        time-to-live: 10s #端点缓存响应的时间量
    health:
      show-details: always #详细信息显示给所有用户
  server:
    port: 8001 #默认8888
    #address: 127.0.0.1 #配置此项表示不允许远程连接
  #monitor
  metrics:
    export:
      datadog:
        application-key: ${spring.application.name}
    web:
      server:
        auto-time-requests: true

  

配置prometheus.yml

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

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: [‘localhost:9090‘]
        labels:
          instance: prometheus
  - job_name: linux
    static_configs:
      - targets: [‘47.112.188.174:9100‘]
        labels:
          instance: node
  - job_name: ‘spring‘
    metrics_path: ‘/actuator/prometheus‘
    static_configs:
      - targets: [‘47.112.188.174:8001‘]

  

docker 启动服务时,开放8001端口

# 9100是exporter的端口
docker run -p 8001:8001 -p 8085:8085 --name mall-portal  --link mall-mysql:db  --link mall-redis:redis  --link mongo:mongo  --link rabbitmq:rabbit  -v /etc/localtime:/etc/localtime  -v/usr/local/dockerdata/mall-project/mall-port/logs:/var/logs  -d mall/mall-portal:1.0-SNAPSHOT

  

启动prometheus时加载配置

docker run --name prometheus -d -p 9090:9090 --privileged=true -v /usr/local/dockerdata/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

  

grafana添加对应dashboard:4701

https://grafana.com/grafana/dashboards/4701

 技术图片

 

 mysql

 

启动mysql的时候

数据库内执行:

use mall;
GRANT REPLICATION CLIENT, PROCESS ON *.* to ‘exporter‘@‘%‘ identified by ‘exporter‘;
GRANT SELECT ON performance_schema.* TO ‘exporter‘@‘%‘;
flush privileges;

  

docker 启动 mysqld_exporter

docker run -d --restart=always --name mysqld-exporter -p 9104:9104 -e DATA_SOURCE_NAME=‘exporter:exporter@(47.112.188.174:3306)/‘ prom/mysqld-exporter

  

 

curl 验证一下

curl localhost:9104/metrics

process_virtual_memory_bytes 1.16281344e+08
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes -1
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 0
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0


 

然后修改一下prometheus的yaml。。。。。。具体编写和运行不再赘述。。。

 

上面这种方式太过繁琐,几乎每次加一个exporter,都要修改prometheus.yml,并重启。可以使用consul来自动搜寻服务。

  

 

  - job_name: consul
    consul_sd_configs:
      - server: ‘47.112.188.174:8500‘
        services: []
    relabel_configs:
      - source_labels: [__meta_consul_tags]
        regex: .*mall.*
        action: keep

  

prometheus系列监控:jvm,mongodb,mysql,redis

标签:har   tar   artifact   yml   enc   响应   inter   arp   clu   

原文地址:https://www.cnblogs.com/zhizhiyin/p/12418671.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!