Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 7f2fc6d

Browse filesBrowse files
committed
add supernode piece downloaded bytes
Signed-off-by: yeya24 <yb532204897@gmail.com>
1 parent 536bc97 commit 7f2fc6d
Copy full SHA for 7f2fc6d

File tree

Expand file treeCollapse file tree

5 files changed

+79
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+79
-5
lines changed
Open diff view settings
Collapse file

‎docs/user_guide/metrics.md‎

Copy file name to clipboardExpand all lines: docs/user_guide/metrics.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This doc contains all the metrics that Dragonfly components currently support. N
2121
- dragonfly_supernode_cdn_cache_hit_total{} - total times of hitting cdn cache. counter type.
2222
- dragonfly_supernode_cdn_download_total{} - total times of cdn downloading. counter type.
2323
- dragonfly_supernode_cdn_download_failed_total{} - total failure times of cdn downloading. counter type.
24+
- dragonfly_supernode_pieces_downloaded_size_bytes{} - total size of pieces downloaded from supernode in bytes. counter type.
2425

2526
## Dfdaemon
2627

Collapse file

‎supernode/server/0.3_bridge.go‎

Copy file name to clipboardExpand all lines: supernode/server/0.3_bridge.go
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func (s *Server) reportPiece(ctx context.Context, rw http.ResponseWriter, req *h
209209
return err
210210
}
211211

212+
// If piece is downloaded from supernode, add metrics.
213+
if s.Config.IsSuperCID(dstCID) {
214+
m.pieceDownloadedBytes.WithLabelValues().Add(float64(sutil.CalculatePieceSize(pieceRange)))
215+
}
216+
212217
request := &types.PieceUpdateRequest{
213218
ClientID: srcCID,
214219
DstPID: dstDfgetTask.PeerID,
Collapse file

‎supernode/server/metrics.go‎

Copy file name to clipboardExpand all lines: supernode/server/metrics.go
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ import (
2828

2929
// metrics defines some prometheus metrics for monitoring supernode
3030
type metrics struct {
31-
requestCounter *prometheus.CounterVec
32-
requestDuration *prometheus.HistogramVec
33-
requestSize *prometheus.HistogramVec
34-
responseSize *prometheus.HistogramVec
31+
requestCounter *prometheus.CounterVec
32+
requestDuration *prometheus.HistogramVec
33+
requestSize *prometheus.HistogramVec
34+
responseSize *prometheus.HistogramVec
35+
pieceDownloadedBytes *prometheus.CounterVec
3536
}
3637

3738
func newMetrics(register prometheus.Registerer) *metrics {
@@ -51,6 +52,9 @@ func newMetrics(register prometheus.Registerer) *metrics {
5152
"Histogram of response size for HTTP requests.", []string{"handler"},
5253
prometheus.ExponentialBuckets(100, 10, 8), register,
5354
),
55+
pieceDownloadedBytes: metricsutils.NewCounter(config.SubsystemSupernode, "pieces_downloaded_size_bytes",
56+
"total bytes of pieces downloaded from supernode", []string{}, register,
57+
),
5458
}
5559
}
5660

Collapse file

‎supernode/util/range_util.go‎

Copy file name to clipboardExpand all lines: supernode/util/range_util.go
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ const (
2626
separator = "-"
2727
)
2828

29+
// CalculatePieceSize calculates the size of piece
30+
// according to the parameter range.
31+
func CalculatePieceSize(rangeStr string) int64 {
32+
ranges := strings.Split(rangeStr, separator)
33+
if len(ranges) != 2 {
34+
return 0
35+
}
36+
37+
startIndex, err := strconv.ParseInt(ranges[0], 10, 64)
38+
if err != nil {
39+
return 0
40+
}
41+
endIndex, err := strconv.ParseInt(ranges[1], 10, 64)
42+
if err != nil {
43+
return 0
44+
}
45+
if endIndex < startIndex {
46+
return 0
47+
}
48+
49+
pieceSize := endIndex - startIndex + 1
50+
return pieceSize
51+
}
52+
2953
// CalculatePieceNum calculates the number of piece
3054
// according to the parameter range.
3155
func CalculatePieceNum(rangeStr string) int {
@@ -47,7 +71,6 @@ func CalculatePieceNum(rangeStr string) int {
4771
}
4872

4973
pieceSize := endIndex - startIndex + 1
50-
5174
return int(startIndex / pieceSize)
5275
}
5376

Collapse file

‎supernode/util/range_util_test.go‎

Copy file name to clipboardExpand all lines: supernode/util/range_util_test.go
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ func init() {
3232
check.Suite(&RangeUtilSuite{})
3333
}
3434

35+
func (suite *RangeUtilSuite) TestCalculatePieceSize(c *check.C) {
36+
var cases = []struct {
37+
rangeStr string
38+
expected int64
39+
}{
40+
{
41+
rangeStr: "foo",
42+
expected: 0,
43+
},
44+
{
45+
rangeStr: "aaa-bbb",
46+
expected: 0,
47+
},
48+
{
49+
rangeStr: "3-2",
50+
expected: 0,
51+
},
52+
{
53+
rangeStr: "1 -3",
54+
expected: 0,
55+
},
56+
{
57+
rangeStr: "0-0",
58+
expected: 1,
59+
},
60+
{
61+
rangeStr: "6-8",
62+
expected: 3,
63+
},
64+
{
65+
rangeStr: "0-40000",
66+
expected: 40001,
67+
},
68+
}
69+
70+
for _, v := range cases {
71+
result := CalculatePieceSize(v.rangeStr)
72+
c.Assert(result, check.Equals, v.expected)
73+
}
74+
}
75+
3576
func (suite *RangeUtilSuite) TestCalculatePieceNum(c *check.C) {
3677
var cases = []struct {
3778
rangeStr string

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.