「电商测试实战第二课 」

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-oss-7.5.1-darwin-x86_64.tar.gz --no-check-certificate

docker run -e ES_JAVA_OPTS=“-Xms256m -Xmx256m” -idt -p 9202:9200 -p 5602:5601 nshou/elasticsearch-kibana

ctx :http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
vars :JMeterVariables (Apache JMeter dist API)
prev:SampleResult (Apache JMeter dist API)

filebeat.yml

  • type: log

    Change to true to enable this input configuration.

    enabled: true

    Paths that should be crawled and fetched. Glob based paths.

    paths:

    • /Users/xs/Desktop/hgwz/Class1/*.log
      multiline.pattern: [1]{4}-[0-9]{2}-[0-9]{2}
      multiline.negate: true
      multiline.match: after
      include_lines: [‘ERROR’]

#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:

Array of hosts to connect to.

hosts: [“47.93.32.161:9202”]

Promethues 安装

Docker Pull prom/prometheus

docker run --name prometheus -d -p 9090:9090 --privileged=true -v /home/hogwarts/mydata/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

NodeExporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz --no-check-certificate

docker cp …/node_exporter-0.18.1.linux-amd64 :confused:

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: [‘47.93.32.161:9100’]
      labels:
      instance: node

application_prod.yml

management:
endpoints:
web:
exposure:
include: info, health, beans, env, metrics, mappings, scheduledtasks, sessions, threaddump, docs, logfile, jolokia,prometheus
base-path: /actuator #默认/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 #默认8080

address: 127.0.0.1 #配置此项表示不允许远程连接

#监测
metrics:
export:
datadog:
application-key: ${spring.application.name}
web:
server:
auto-time-requests: true

docker run -p 9100:9100 -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 /mydata/app/portal/logs:/var/logs -d mall/mall-portal:1.0-SNAPSHOT

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

docker run -d --restart=always --name mysqld-exporter -p 9104:9104 -e DATA_SOURCE_NAME=“exporter:exporter@(47.93.32.161:8306)/” prom/mysqld-exporter

consul 服务发现
docker run --restart=always --name consul -d -p 8500:8500 consul

curl -X PUT -d ‘{“id”: “mysql01”,“name”: “mysql01”,“address”: “47.93.32.161”,“port”: 9104,“tags”: [“mall”],“checks”: [{“http”: “http://47.93.32.161:9104/","interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/register
curl -X PUT -d ‘{“id”: “redis01”,“name”: “redis01”,“address”: “47.93.32.161”,“port”: 9121,“tags”: [“mall”],“checks”: [{“http”: “http://47.93.32.161:9121/","interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/registercurl -X PUT -d ‘{“id”: “mongo01”,“name”: “mongo01”,“address”: “47.93.32.161”,“port”: 9001,“tags”: [“mall”],“checks”: [{“http”: “http://47.93.32.161:9001/","interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/register
curl -X PUT -d ‘{“id”: “node01”,“name”: “node01”,“address”: “47.93.32.161”,“port”: 9100,“tags”: [“mall”],“checks”: [{“http”: “http://47.93.32.161:9100/","interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/register
curl -X PUT -d ‘{“id”: “spring01”,“name”: “spring01”,“address”: “47.93.32.161”,“port”: 8001,“tags”: [“mall”],“checks”: [{“http”: “http://47.93.32.161:8001/actuator/prometheus","interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/register

mongodb / redis
./redis_exporter -redis.addr 47.93.32.161:6379 & -web.listenaddress 0.0.0.0:9122
./mongodb_exporter-linux-amd64 -mongodb.uri mongodb://47.93.32.161:27017/admin

https://github.com/prometheus/mysqld_exporter/releases
https://github.com/oliver006/redis_exporter/releases
https://github.com/percona/mongodb_exporter/releases


  1. 0-9 ↩︎

按贴子的步骤,

  1. mall-portal目录下
    在pom.xml中添加了micrometer-registry-prometheus ,
    在application中添加了 application name,management ,
  2. 打包,把生成的jar包传到服务器上,制作镜像文件,docker 地址私有仓库:
    “insecure-registries”: [“120.24.35.145:5001”]
    镜像文件名:mall/mall-portal:v1.1
  3. docker-compose-app.yml 文件内容:
    version: ‘3’
    services:
    mall-portal:
    image: mall/mall-portal:v1.1
    container_name: mall-portal-new
    ports:
    • 8085:8085
    • 9100:9100
    • 8001:8001
      volumes:
    • /mydata/app/mall-portal/logs:/var/logs
    • /etc/localtime:/etc/localtime
      environment:
    • ‘TZ=“Asia/Shanghai”’
      external_links:
    • redis:redis #可以用redis这个域名访问redis服务
    • mongo:mongo #可以用mongo这个域名访问mongo服务
    • mysql:db #可以用db这个域名访问mysql服务
    • rabbitmq:rabbit #可以用rabbit这个域名访问rabbitmq服务
  4. 用docker-compose启容器起来:docker-compose -f ./docker-compose-app.yml up -d
    访问 8085/swagger-ui.html ,容器会停止
  5. 查看容器日志:文件1见附件mall-portal问题日志.txt (26.2 KB)

查看了日志,里面有提到Message: Error creating bean with name ‘webMvcMetricsFilter’ defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]
是与metrics 有关系,还有哪里配制不对吗?

直接运行java项目的时候能用吗?不打包成jar 试下

mall-portal直接运行.txt (38.6 KB) [quote=“Leon2020, post:2, topic:5287”]
webMvcMetricsFilter
[/quote]

直接运行java项目,我把application-dev.yml也加了application name 和 management 运行也是出错的

我在以前没有改过的源码上重新改了application-dev.yml和pom.xml,现在运行没有报错,访问是这样的,应该是成功了吧

能访问,就ok了!

谢谢老师了。
还有一个问题,我在idea里面构建镜像时,是使用的哪个application.yml,就决定了我是要开发环境,还是生产环境
源码里面哪里是这种配置的吗?
我看到根目录下pom.xml里有一个
[“java”, “-jar”, “-Dspring.profiles.active=prod”,"/${project.build.finalName}.jar"]

是这个Dspring.profiles.active参数吗?

问题3:构建镜像时报错误“Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (build-image) on project mall-portal: Exception caught”

步骤:
把pom.xml的这个生成镜像的放开后,
image
执行clean install
总是出现错误:


这几天尝试过程中,只成功构建过一次,那一次是需要把子系统mall-portal这个目录的源码都删除,复制一个新的过来,又可以build成功。
百度换过com.spotify:docker-maven-plugin:1.2.2插件 的版本1.2.0,也是这个错误

助教回复,需要看根节点日志,有更多错误信息,最后发现镜像的推送地位配置有误

我查了一下,这样也是有问题的。看不到应用的一些 metrics 信息


是因为prometheus连不上 Endpoints?
查了官网上说明需要公开节点: The endpoint is not available by default and must be exposed
image
但是访问这个路径http://localhost:8001/actuator/prometheus
仍是404

网上有与我同样的问题,:https://stackoverflow.com/questions/51829253/actuator-exposing-endpoints-not-working
没有有效的解决方法

第二天重新运行有数据过来,有可能 是缓存的问题,电脑重启后会好
以上的配置是有效的