@@ -12,26 +12,29 @@ import (
1212 "time"
1313
1414 "github.com/ethersphere/bee/v2/pkg/jsonhttp"
15+ "github.com/ethersphere/bee/v2/pkg/status"
1516 "github.com/ethersphere/bee/v2/pkg/swarm"
1617 "github.com/ethersphere/bee/v2/pkg/topology"
1718)
1819
1920type statusSnapshotResponse struct {
20- Overlay string `json:"overlay"`
21- Proximity uint `json:"proximity"`
22- BeeMode string `json:"beeMode"`
23- ReserveSize uint64 `json:"reserveSize"`
24- ReserveSizeWithinRadius uint64 `json:"reserveSizeWithinRadius"`
25- PullsyncRate float64 `json:"pullsyncRate"`
26- StorageRadius uint8 `json:"storageRadius"`
27- ConnectedPeers uint64 `json:"connectedPeers"`
28- NeighborhoodSize uint64 `json:"neighborhoodSize"`
29- RequestFailed bool `json:"requestFailed,omitempty"`
30- BatchCommitment uint64 `json:"batchCommitment"`
31- IsReachable bool `json:"isReachable"`
32- LastSyncedBlock uint64 `json:"lastSyncedBlock"`
33- CommittedDepth uint8 `json:"committedDepth"`
34- IsWarmingUp bool `json:"isWarmingUp"`
21+ Overlay string `json:"overlay"`
22+ Proximity uint `json:"proximity"`
23+ BeeMode string `json:"beeMode"`
24+ ReserveSize uint64 `json:"reserveSize"`
25+ ReserveSizeWithinRadius uint64 `json:"reserveSizeWithinRadius"`
26+ PullsyncRate float64 `json:"pullsyncRate"`
27+ StorageRadius uint8 `json:"storageRadius"`
28+ ConnectedPeers uint64 `json:"connectedPeers"`
29+ NeighborhoodSize uint64 `json:"neighborhoodSize"`
30+ RequestFailed bool `json:"requestFailed,omitempty"`
31+ BatchCommitment uint64 `json:"batchCommitment"`
32+ IsReachable bool `json:"isReachable"`
33+ LastSyncedBlock uint64 `json:"lastSyncedBlock"`
34+ CommittedDepth uint8 `json:"committedDepth"`
35+ IsWarmingUp bool `json:"isWarmingUp"`
36+ UploadSpeed * statusHistogramResponse `json:"uploadSpeed,omitempty"`
37+ DownloadSpeed * statusHistogramResponse `json:"downloadSpeed,omitempty"`
3538}
3639
3740type statusResponse struct {
@@ -48,6 +51,51 @@ type neighborhoodsResponse struct {
4851 Neighborhoods []statusNeighborhoodResponse `json:"neighborhoods"`
4952}
5053
54+ func newStatusHistogramResponse (h * status.Histogram ) * statusHistogramResponse {
55+ if h == nil {
56+ return nil
57+ }
58+ labels := make ([]statusLabelResponse , 0 , len (h .Labels ))
59+ for _ , l := range h .Labels {
60+ labels = append (labels , statusLabelResponse {
61+ Name : l .Name ,
62+ Value : l .Value ,
63+ })
64+ }
65+
66+ buckets := make ([]statusHistogramBucketResponse , 0 , len (h .Buckets ))
67+ for _ , b := range h .Buckets {
68+ buckets = append (buckets , statusHistogramBucketResponse {
69+ CumulativeCount : b .CumulativeCount ,
70+ UpperBound : b .UpperBound ,
71+ })
72+ }
73+
74+ return & statusHistogramResponse {
75+ Labels : labels ,
76+ SampleSum : h .SampleSum ,
77+ SampleCount : h .SampleCount ,
78+ Buckets : buckets ,
79+ }
80+ }
81+
82+ type statusHistogramResponse struct {
83+ Labels []statusLabelResponse `json:"labels,omitempty"`
84+ SampleSum float64 `json:"sampleSum,omitempty"`
85+ SampleCount uint64 `json:"sampleCount,omitempty"`
86+ Buckets []statusHistogramBucketResponse `json:"buckets,omitempty"`
87+ }
88+
89+ type statusLabelResponse struct {
90+ Name string `json:"name,omitempty"`
91+ Value string `json:"value,omitempty"`
92+ }
93+
94+ type statusHistogramBucketResponse struct {
95+ CumulativeCount uint64 `json:"cumulativeCount,omitempty"`
96+ UpperBound float64 `json:"upperBound,omitempty"`
97+ }
98+
5199// statusAccessHandler is a middleware that limits the number of simultaneous
52100// status requests.
53101func (s * Service ) statusAccessHandler (h http.Handler ) http.Handler {
@@ -98,6 +146,8 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) {
98146 LastSyncedBlock : ss .LastSyncedBlock ,
99147 CommittedDepth : uint8 (ss .CommittedDepth ),
100148 IsWarmingUp : s .isWarmingUp ,
149+ UploadSpeed : newStatusHistogramResponse (ss .UploadSpeed ),
150+ DownloadSpeed : newStatusHistogramResponse (ss .DownloadSpeed ),
101151 })
102152}
103153
0 commit comments