Docker部署sock shop
Docker
安装
Ubuntu安装Docker https://docs.docker.com/engine/install/ubuntu/
docker info
container
查看运行的container
docker ps
查看所有container
docker ps -a
关闭container
docker stop name
查看容器占用的端口
netstat -antp
docker stats 'commandname' /--help
关闭所有容器
docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
删除所有容器
docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
image
查看所有image
docker images
删除image
docker rmi REPOSITORY:TAG
Sock Shop
Sock Shop官网 https://microservices-demo.github.io/
git clone https://github.com/microservices-demo/microservices-demo
cd microservices-demo
docker-compose -f deploy/docker-compose/docker-compose.yml up -d
# 访问http://localhost/
docker-compose -f deploy/docker-compose/docker-compose.yml down
Locust负载测试库
学习资料
B站教学 https://www.bilibili.com/video/BV16441157rv
博客资料 https://dandelioncloud.cn/article/details/1441332087940042754
Locust官网 https://locust.io/
官方使用文档 https://docs.locust.io/en/stable/what-is-locust.html
使用代码示例
- 访问百度
from locust import HttpUser, TaskSet, task
class TestIndex(TaskSet):
@task
def getIndex(self):
abstract = True
self.client.get('/')
class WebSite(HttpUser):
tasks = [TestIndex]
min_wait = 1000
max_wait = 2000
# 进入到程序文件所在目录,运行以下命令
# locust -f test.py --host=http://www.baidu.com
通过浏览器访问 http://localhost:8089 进行模拟访问设置
- 访问系统接口
import random
from locust import HttpUser, TaskSet, task
class Testlogin(TaskSet):
# 初始化方法
def on_start(self):
self.loginData = [
{'username': 'admin1', 'pwd': 123},
{'username': 'admin2', 'pwd': 123},
{'username': 'admin3', 'pwd': 123}
]
@task
def doLogin(self):
# 1000以内的数对3取余,0 1 2
idx = random.randint(1, 1000) % len(self.loginData)
# 请求正文接受的是字典
body = {'username': 'admin', 'pwd': 123}
# 发送post请求并得到相应
response = self.client.post('/W/user/login'
, data=self.loginData[idx]
, catch_response=True
)
# 断言(检查点) 必须设置catch_response=True
# 这样会把登录失败记录为failure
if 'login-pass' in response.text:
response.success()
else:
response.failure('Can not login')
print(response.text) # 包含成功与否的信息
class WebSite(HttpUser):
tasks = [Testlogin]
min_wait = 1000
max_wait = 2000
Prometheus
CAdvisor监听容器
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8082:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
docker start cadvisor
192.168.118.128:8082
查看这些指标
curl http://localhost:9100/metrics | grep "node_"
curl localhost:9100/metrics | grep -i node_cpu | head