From d195cecfdf310a6ea1a18916cd36c6e29e9172d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=B8=90=E7=A6=BB?= Date: Tue, 14 Jan 2025 18:15:51 +0000 Subject: [PATCH] finish doc about metrics and code clean --- biz/handler/announce.go | 3 ++- main.go | 18 ------------------ readme.md | 21 +++++++++++++-------- router.go | 18 ------------------ service/database/init.go | 16 ---------------- 5 files changed, 15 insertions(+), 61 deletions(-) diff --git a/biz/handler/announce.go b/biz/handler/announce.go index 9b8aa91..ba27092 100644 --- a/biz/handler/announce.go +++ b/biz/handler/announce.go @@ -14,6 +14,7 @@ import ( "github.com/PBH-BTN/trunker/utils/http" "github.com/cloudwego/hertz/pkg/app" "github.com/thinkeridea/go-extend/exstrings" + hertz "github.com/cloudwego/hertz/pkg/common/utils" ) func Announce(ctx context.Context, c *app.RequestContext) { @@ -48,7 +49,7 @@ func Announce(ctx context.Context, c *app.RequestContext) { Complete: scrape.Complete, }) } else { - resp := map[string]any{ + resp := hertz.H{ "interval": config.AppConfig.Tracker.TTL + int64(rand.Intn(201)-100), "external ip": req.ClientIP.String(), "incomplete": scrape.Incomplete, diff --git a/main.go b/main.go index 44b48f2..2dee5f1 100755 --- a/main.go +++ b/main.go @@ -1,21 +1,3 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Code generated by hertz generator. - package main import ( diff --git a/readme.md b/readme.md index 0dd85a2..3e73c8c 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ ## Introduction -A high-performance BitTorrent Tracker implemented in Go. Using [Hertz](https://github.com/cloudwego/hertz) from cloudwego. +A high-performance BitTorrent Tracker implemented in Go. Using [Hertz](https://github.com/cloudwego/hertz) from cloudwego, with observability. This tracker is hosted as https://btn-prod.ghostchu-services.top/announce @@ -26,13 +26,13 @@ docker pull gaojianli2333/trunker:latest ``` ## Features -- [x] BEP-0003 -- [x] BEP-0007 -- [x] BEP-0023 -- [x] BEP-0024 -- [x] BEP-0031 -- [x] BEP-0048 -- [X] LT-Extension(complete,incomplete) +- [x] [BEP-0003](https://www.bittorrent.org/beps/bep_0003.html) +- [x] [BEP-0007](https://www.bittorrent.org/beps/bep_0007.html) (IPv6 Tracker Extension) +- [x] [BEP-0023](https://www.bittorrent.org/beps/bep_0023.html) (Compact Peer Lists) +- [x] [BEP-0024](https://www.bittorrent.org/beps/bep_0024.html) (External IP) +- [x] [BEP-0031](https://www.bittorrent.org/beps/bep_0031.html) (Failure Retry Extension) +- [x] [BEP-0048](https://www.bittorrent.org/beps/bep_0048.html) (Scrape) +- [X] LT-Extension (complete,incomplete) - [x] Full-Memory Mode - [x] Load from Persist - [ ] MySQL Mode @@ -85,6 +85,11 @@ You can ban some torrent or peer by using the following endpoints. | GET | `/admin/info_hash/:infoHash/peers` | Get all peers of a info_hash. **The response may be very large** | | DELETE | `/admin/info_hash/:infoHash` | Delete a info_hash | +## Metrics +Currently trunker is serving a prometheus handler at `:9091` by default. With 2 paths: +- `/metrics` Providing metrics about http request, including latency and QPS. +- `/pprof` Providing golang runtime pprof info. + ## Benchmark CPU: 4 Cores ARM64 Oracle Cloud diff --git a/router.go b/router.go index 28666d3..6c05443 100755 --- a/router.go +++ b/router.go @@ -1,21 +1,3 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Code generated by hertz generator. - package main import ( diff --git a/service/database/init.go b/service/database/init.go index 1914828..aea2736 100644 --- a/service/database/init.go +++ b/service/database/init.go @@ -1,19 +1,3 @@ -/* - * Copyright 2022 CloudWeGo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package database import (