@Summary Get Storage Utilization @Description **Get disk free information of aptly storage** @Description @Description Units in MiB. @Tags Status @Produce json @Success 200 {object} diskFree "Storage information" @Failure 400 {object} Error "Internal Error" @Router /api/storage [get]
(c *gin.Context)
| 26 | // @Failure 400 {object} Error "Internal Error" |
| 27 | // @Router /api/storage [get] |
| 28 | func apiDiskFree(c *gin.Context) { |
| 29 | var df diskFree |
| 30 | |
| 31 | fs := context.Config().GetRootDir() |
| 32 | |
| 33 | var stat syscall.Statfs_t |
| 34 | err := syscall.Statfs(fs, &stat) |
| 35 | if err != nil { |
| 36 | AbortWithJSONError(c, 400, fmt.Errorf("Error getting storage info on %s: %s", fs, err)) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | df.Total = uint64(stat.Blocks) * uint64(stat.Bsize) / 1048576 |
| 41 | df.Free = uint64(stat.Bavail) * uint64(stat.Bsize) / 1048576 |
| 42 | df.PercentFull = 100.0 - float32(stat.Bavail)/float32(stat.Blocks)*100.0 |
| 43 | |
| 44 | c.JSON(200, df) |
| 45 | } |
nothing calls this directly
no test coverage detected