Skip to content

Commit

Permalink
add worker routes
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Sep 12, 2024
1 parent 8a5f9d8 commit e14e7a6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions api/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,66 @@ func (txn Transaction) PrometheusMetric() (metrics []prometheus.Metric) {
return
}

func (m MemoryResponse) PrometheusMetric() (metrics []prometheus.Metric) {
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_memory_download_available",
Value: float64(m.Download.Available),
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_memory_download_total",
Value: float64(m.Download.Total),
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_memory_upload_available",
Value: float64(m.Upload.Available),
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_memory_upload_total",
Value: float64(m.Upload.Total),
})
return
}

func (m DownloadStatsResponse) PrometheusMetric() (metrics []prometheus.Metric) {
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_avgdownloadspeedmbps",
Value: m.AvgDownloadSpeedMBPS,
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_avgoverdrivepct_download",
Value: m.AvgOverdrivePct,
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_healthydownloaders",
Value: float64(m.HealthyDownloaders),
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_numdownloaders",
Value: float64(m.NumDownloaders),
})
return
}

func (m UploadStatsResponse) PrometheusMetric() (metrics []prometheus.Metric) {
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_avgslabuploadspeedmbps",
Value: m.AvgSlabUploadSpeedMBPS,
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_avgoverdrivepct_upload",
Value: m.AvgOverdrivePct,
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_healthyuploaders",
Value: float64(m.HealthyUploaders),
})
metrics = append(metrics, prometheus.Metric{
Name: "renterd_worker_stats_numuploaders",
Value: float64(m.NumUploaders),
})
return
}

type AllowListResp []types.PublicKey

func (a AllowListResp) PrometheusMetric() (metrics []prometheus.Metric) {
Expand Down
6 changes: 3 additions & 3 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (w *Worker) downloadsStatsHandlerGET(jc jape.Context) {
})

// encode response
jc.Encode(api.DownloadStatsResponse{
api.WriteResponse(jc, http.StatusOK, api.DownloadStatsResponse{
AvgDownloadSpeedMBPS: math.Ceil(stats.avgDownloadSpeedMBPS*100) / 100,
AvgOverdrivePct: math.Floor(stats.avgOverdrivePct*100*100) / 100,
HealthyDownloaders: healthy,
Expand All @@ -478,7 +478,7 @@ func (w *Worker) uploadsStatsHandlerGET(jc jape.Context) {
})

// encode response
jc.Encode(api.UploadStatsResponse{
api.WriteResponse(jc, http.StatusOK, api.UploadStatsResponse{
AvgSlabUploadSpeedMBPS: math.Ceil(stats.avgSlabUploadSpeedMBPS*100) / 100,
AvgOverdrivePct: math.Floor(stats.avgOverdrivePct*100*100) / 100,
HealthyUploaders: stats.healthyUploaders,
Expand Down Expand Up @@ -856,7 +856,7 @@ func (w *Worker) idHandlerGET(jc jape.Context) {
}

func (w *Worker) memoryGET(jc jape.Context) {
jc.Encode(api.MemoryResponse{
api.WriteResponse(jc, http.StatusOK, api.MemoryResponse{
Download: w.downloadManager.mm.Status(),
Upload: w.uploadManager.mm.Status(),
})
Expand Down

0 comments on commit e14e7a6

Please sign in to comment.