电商压测实战(二)

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 ↩︎