mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
add storage API
This commit is contained in:
@@ -57,6 +57,7 @@ func parseEscapedPath(path string) string {
|
||||
// @Tags Publish
|
||||
// @Produce json
|
||||
// @Success 200 {array} deb.PublishedRepo
|
||||
// @Failure 500 {object} Error "Internal Error"
|
||||
// @Router /api/publish [get]
|
||||
func apiPublishList(c *gin.Context) {
|
||||
collectionFactory := context.NewCollectionFactory()
|
||||
|
||||
@@ -125,6 +125,7 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
||||
api.GET("/metrics", apiMetricsGet())
|
||||
}
|
||||
api.GET("/version", apiVersion)
|
||||
api.GET("/storage", apiDiskFree)
|
||||
|
||||
isReady := &atomic.Value{}
|
||||
isReady.Store(false)
|
||||
|
||||
38
api/storage.go
Normal file
38
api/storage.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Summary Get Storage Utilization
|
||||
// @Description Get disk free information of aptly storage
|
||||
// @Tags Status
|
||||
// @Produce json
|
||||
// @Success 200 {object} string "usage information"
|
||||
// @Failure 400 {object} Error "Internal Error"
|
||||
// @Router /api/storage [get]
|
||||
func apiDiskFree(c *gin.Context) {
|
||||
var df struct {
|
||||
Total uint64
|
||||
Free uint64
|
||||
PercentUsed float32
|
||||
}
|
||||
|
||||
fs := context.Config().GetRootDir()
|
||||
|
||||
var stat syscall.Statfs_t
|
||||
err := syscall.Statfs(fs, &stat)
|
||||
if err != nil {
|
||||
AbortWithJSONError(c, 400, fmt.Errorf("Error getting storage info on %s: %s", fs, err))
|
||||
return
|
||||
}
|
||||
|
||||
df.Total = uint64(stat.Blocks) * uint64(stat.Bsize) / 1048576
|
||||
df.Free = uint64(stat.Bavail) * uint64(stat.Bsize) / 1048576
|
||||
df.PercentUsed = 100.0 - float32(stat.Bavail)/float32(stat.Blocks)*100.0
|
||||
|
||||
c.JSON(200, df)
|
||||
}
|
||||
Reference in New Issue
Block a user