Skip to content

gam6itko/go-musthave-metrics

Repository files navigation

go-musthave-metrics

server

env

Значения по-умолчанию

ADDRESS=localhost:8080
STORE_INTERVAL=300
FILE_STORAGE_PATH=/tmp/metrics-db.json
RESTORE=true
DATABASE_DSN=postgres://postgres:password@172.22.0.2:5432/yp_metrics
KEY=key
CRYPTO_KEY=/tmp/go-musthave-metrics/private.pem
TRUSTED_SUBNET=192.168.0.0/24
GRPC_ADDRESS=localhost:3200

get docker ip

docker-compose up -d
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' yp-musthave-metrics-postgres

agent

ADDRESS=localhost:8080
REPORT_INTERVAL=10
POLL_INTERVAL=2
KEY="abc"
RATE_LIMIT=4
CRYPTO_KEY=/tmp/go-musthave-metrics/public.key
X_REAL_IP=192.168.1.1
USE_GRPC=true

sprint

iter7

update

POST localhost:8080/update/
Content-Type: application/json

{
  "id": "PollCount",
  "type": "counter",
  "delta": 1
}

get value

POST localhost:8080/value/
Content-Type: application/json

{
  "id": "PollCount", 
  "type": "counter", 
}

iter12

POST localhost:8080/updates/
Content-Type: application/json

[
  {
    "id": "PollCount",
    "type": "counter",
    "delta": 1
  },
  {
    "id": "GaugeABC",
    "type": "gauge",
    "value": 19.17
  }
]

iter16

Сохраните профиль потребления памяти.

Запустим 2 сервиса и дадим им чуток поработать.

server

mkdir -p ./profiles/server
mkdir -p ./profiles/client
curl http://localhost:8080/debug/pprof/allocs > ./profiles/server/allocs.base.pprof
# go tool pprof -http=":9090" -seconds=30 http://localhost:8080/debug/pprof/allocs
go tool pprof -http=":9090" -seconds=30 ./profiles/server/allocs.base.pprof

Тут видно что больше всего памяти потребляет compress/flate.NewWriter.

client

mkdir -p ./profiles/client
curl http://localhost:8081/debug/pprof/allocs > ./profiles/client/allocs.base.pprof
# go tool pprof -http=":9090" -seconds=30 http://localhost:8081/debug/pprof/allocs
go tool pprof -http=":9090" -seconds=30 ./profiles/client/allocs.base.pprof

Тут видно что больше всего памяти потребляет compress/flate.NewWriter.

iter18

swag init --dir=./cmd/agent --output ./swagger/agent
swag init --dir=./cmd/server --output ./swagger/server

iter20

Проверить код своим родным линтером

go build -o staticlint ./cmd/staticlint/
./staticlint ./internal/server/...

iter21

Сгенерировать ключи командой

go build -o keygen ./cmd/keygen 
./keygen -path .

iter25

protoc --go_out=. --go_opt=paths=source_relative \
  --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/message.proto

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages