initial import
This commit is contained in:
26
example/load/simulate/cpu/Dockerfile
Normal file
26
example/load/simulate/cpu/Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM golang:alpine AS builder
|
||||
|
||||
LABEL stage=gobuilder
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOOS linux
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
WORKDIR $GOPATH/src/zero
|
||||
COPY . .
|
||||
RUN go build -ldflags="-s -w" -o /app/main example/load/simulate/cpu/main.go
|
||||
|
||||
|
||||
FROM alpine
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
RUN apk add git
|
||||
RUN go get github.com/vikyd/go-cpu-load
|
||||
|
||||
RUN mkdir /app
|
||||
COPY --from=builder /app/main /app/main
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["/app/main"]
|
||||
13
example/load/simulate/cpu/Makefile
Normal file
13
example/load/simulate/cpu/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
version := v1
|
||||
|
||||
build:
|
||||
cd $(GOPATH)/src/zero && docker build -t registry.cn-hangzhou.aliyuncs.com/xapp/shedding:$(version) . -f example/load/simulate/cpu/Dockerfile
|
||||
|
||||
push: build
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/xapp/shedding:$(version)
|
||||
|
||||
deploy: push
|
||||
kubectl apply -f shedding.yaml
|
||||
|
||||
clean:
|
||||
kubectl delete -f shedding.yaml
|
||||
28
example/load/simulate/cpu/cpu-accuracy.md
Normal file
28
example/load/simulate/cpu/cpu-accuracy.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# cpu监控准确度测试
|
||||
|
||||
1. 启动测试pod
|
||||
|
||||
`make deploy`
|
||||
|
||||
2. 通过`kubectl get po -n adhoc`确认`sheeding` pod已经成功运行,通过如下命令进入pod
|
||||
|
||||
`kubectl exec -it -n adhoc shedding -- sh`
|
||||
|
||||
3. 启动负载
|
||||
|
||||
`/app # go-cpu-load -p 50 -c 1`
|
||||
|
||||
默认`go-cpu-load`是对每个core加上负载的,所以测试里指定了`1000m`,等同于1 core,我们指定`-c 1`让测试更具有可读性
|
||||
|
||||
`-p`可以多换几个值测试
|
||||
|
||||
4. 验证测试准确性
|
||||
|
||||
`kubectl logs -f -n adhoc shedding`
|
||||
|
||||
可以看到日志中的`CPU`报告,`1000m`表示`100%`,如果看到`500m`则表示`50%`,每分钟输出一次
|
||||
|
||||
`watch -n 5 kubectl top pod -n adhoc`
|
||||
|
||||
可以看到`kubectl`报告的`CPU`使用率,两者进行对比,即可知道是否准确
|
||||
|
||||
7
example/load/simulate/cpu/main.go
Normal file
7
example/load/simulate/cpu/main.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import _ "zero/core/stat"
|
||||
|
||||
func main() {
|
||||
select {}
|
||||
}
|
||||
17
example/load/simulate/cpu/shedding.yaml
Normal file
17
example/load/simulate/cpu/shedding.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: shedding
|
||||
namespace: adhoc
|
||||
spec:
|
||||
containers:
|
||||
- name: shedding
|
||||
image: registry-vpc.cn-hangzhou.aliyuncs.com/xapp/shedding:v1
|
||||
imagePullPolicy: Always
|
||||
resources:
|
||||
requests:
|
||||
cpu: 1000m
|
||||
limits:
|
||||
cpu: 1000m
|
||||
imagePullSecrets:
|
||||
- name: aliyun
|
||||
Reference in New Issue
Block a user