本文整理汇总了Golang中github.com/docker/go-units.HumanSize函数的典型用法代码示例。如果您正苦于以下问题:Golang HumanSize函数的具体用法?Golang HumanSize怎么用?Golang HumanSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HumanSize函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Reclaimable
func (c *diskUsageImagesContext) Reclaimable() string {
var used int64
c.AddHeader(reclaimableHeader)
for _, i := range c.images {
if i.Containers != 0 {
used += i.Size
}
}
reclaimable := c.totalSize - used
if c.totalSize > 0 {
return fmt.Sprintf("%s (%v%%)", units.HumanSize(float64(reclaimable)), (reclaimable*100)/c.totalSize)
}
return fmt.Sprintf("%s", units.HumanSize(float64(reclaimable)))
}
开发者ID:jfrazelle,项目名称:docker,代码行数:16,代码来源:disk_usage.go
示例2: Size
func (c *volumeContext) Size() string {
c.AddHeader(sizeHeader)
if c.v.Size == -1 {
return "N/A"
}
return units.HumanSize(float64(c.v.Size))
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:7,代码来源:volume.go
示例3: NewPruneCommand
// NewPruneCommand returns a new cobra prune command for images
func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
opts := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "prune [OPTIONS]",
Short: "Remove unused images",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(dockerCli, opts)
if err != nil {
return err
}
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
},
Tags: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation")
flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images, not just dangling ones")
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')")
return cmd
}
开发者ID:docker,项目名称:docker,代码行数:29,代码来源:prune.go
示例4: UniqueSize
func (c *imageContext) UniqueSize() string {
c.AddHeader(uniqueSizeHeader)
if c.i.Size == -1 {
return "N/A"
}
return units.HumanSize(float64(c.i.Size))
}
开发者ID:Mic92,项目名称:docker,代码行数:7,代码来源:image.go
示例5: NewPruneCommand
// NewPruneCommand returns a new cobra prune command for volumes
func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
var opts pruneOptions
cmd := &cobra.Command{
Use: "prune [OPTIONS]",
Short: "Remove all unused volumes",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(dockerCli, opts)
if err != nil {
return err
}
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation")
return cmd
}
开发者ID:Mic92,项目名称:docker,代码行数:26,代码来源:prune.go
示例6: Size
func (c *volumeContext) Size() string {
c.AddHeader(sizeHeader)
if c.v.UsageData == nil {
return "N/A"
}
return units.HumanSize(float64(c.v.UsageData.Size))
}
开发者ID:Mic92,项目名称:docker,代码行数:7,代码来源:volume.go
示例7: serveTemplate
func (h *handler) serveTemplate(w http.ResponseWriter, r *http.Request) {
templateDir := path.Join("/src", "templates")
lp := path.Join(templateDir, "layout.html")
// set up custom functions
funcMap := template.FuncMap{
"ext": func(name string) string {
return strings.TrimPrefix(filepath.Ext(name), ".")
},
"base": func(name string) string {
parts := strings.Split(name, "/")
return parts[len(parts)-1]
},
"size": func(s int64) string {
return units.HumanSize(float64(s))
},
}
// parse & execute the template
tmpl := template.Must(template.New("").Funcs(funcMap).ParseFiles(lp))
if err := tmpl.ExecuteTemplate(w, "layout", h.Files); err != nil {
writeError(w, fmt.Sprintf("Execute template failed: %v", err))
return
}
}
开发者ID:jfrazelle,项目名称:s3server,代码行数:25,代码来源:main.go
示例8: convertBasesize
func convertBasesize(basesizeBytes int64) (int64, error) {
basesize := units.HumanSize(float64(basesizeBytes))
basesize = strings.Trim(basesize, " ")[:len(basesize)-3]
basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64)
if err != nil {
return 0, err
}
return int64(basesizeFloat) * 1024 * 1024 * 1024, nil
}
开发者ID:shakamunyi,项目名称:docker,代码行数:9,代码来源:docker_utils.go
示例9: Size
func (c *diskUsageContainersContext) Size() string {
var size int64
c.AddHeader(sizeHeader)
for _, container := range c.containers {
size += container.SizeRw
}
return units.HumanSize(float64(size))
}
开发者ID:jfrazelle,项目名称:docker,代码行数:10,代码来源:disk_usage.go
示例10: createIndexFile
// create the index.html file
func createIndexFile(bucket *s3.Bucket, bucketpath string) error {
// list all the files
files, err := listFiles(bucketpath, bucketpath, "", 2000, bucket)
if err != nil {
return fmt.Errorf("Listing all files in bucket failed: %v", err)
}
// create a temp file for the index
tmp, err := ioutil.TempFile("", "index.html")
if err != nil {
return fmt.Errorf("Creating temp file failed: %v", err)
}
defer os.RemoveAll(tmp.Name())
// set up custom functions
funcMap := template.FuncMap{
"ext": func(name string) string {
if strings.HasSuffix(name, ".sha256") || strings.HasSuffix(name, ".md5") {
return "text"
}
return "default"
},
"size": func(s int64) string {
return units.HumanSize(float64(s))
},
}
// parse & execute the template
tmpl, err := template.New("").Funcs(funcMap).Parse(index)
if err != nil {
return fmt.Errorf("Parsing template failed: %v", err)
}
if err := tmpl.Execute(tmp, files); err != nil {
return fmt.Errorf("Execute template failed: %v", err)
}
// push the file to s3
if err = uploadFileToS3(bucket, tmp.Name(), path.Join(bucketpath, "index.html"), "text/html"); err != nil {
return fmt.Errorf("Uploading %s to s3 failed: %v", tmp.Name(), err)
}
return nil
}
开发者ID:carriercomm,项目名称:docker-bb,代码行数:45,代码来源:static.go
示例11: runPrune
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) error {
var message string
if opts.all {
message = fmt.Sprintf(warning, allImageDesc)
} else {
message = fmt.Sprintf(warning, danglingImageDesc)
}
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), message) {
return nil
}
var spaceReclaimed uint64
for _, pruneFn := range []func(dockerCli *command.DockerCli) (uint64, string, error){
prune.RunContainerPrune,
prune.RunVolumePrune,
prune.RunNetworkPrune,
} {
spc, output, err := pruneFn(dockerCli)
if err != nil {
return err
}
spaceReclaimed += spc
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
}
}
spc, output, err := prune.RunImagePrune(dockerCli, opts.all)
if err != nil {
return err
}
if spc > 0 {
spaceReclaimed += spc
fmt.Fprintln(dockerCli.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
}
开发者ID:harche,项目名称:docker,代码行数:43,代码来源:prune.go
示例12: housekeeping
// TODO(vmarmol): Implement stats collecting as a custom collector.
func (c *containerData) housekeeping() {
// Start any background goroutines - must be cleaned up in c.handler.Cleanup().
c.handler.Start()
// Long housekeeping is either 100ms or half of the housekeeping interval.
longHousekeeping := 100 * time.Millisecond
if *HousekeepingInterval/2 < longHousekeeping {
longHousekeeping = *HousekeepingInterval / 2
}
// Housekeep every second.
glog.V(3).Infof("Start housekeeping for container %q\n", c.info.Name)
lastHousekeeping := time.Now()
for {
select {
case <-c.stop:
// Cleanup container resources before stopping housekeeping.
c.handler.Cleanup()
// Stop housekeeping when signaled.
return
default:
// Perform housekeeping.
start := time.Now()
c.housekeepingTick()
// Log if housekeeping took too long.
duration := time.Since(start)
if duration >= longHousekeeping {
glog.V(3).Infof("[%s] Housekeeping took %s", c.info.Name, duration)
}
}
// Log usage if asked to do so.
if c.logUsage {
const numSamples = 60
var empty time.Time
stats, err := c.memoryCache.RecentStats(c.info.Name, empty, empty, numSamples)
if err != nil {
if c.allowErrorLogging() {
glog.Infof("[%s] Failed to get recent stats for logging usage: %v", c.info.Name, err)
}
} else if len(stats) < numSamples {
// Ignore, not enough stats yet.
} else {
usageCpuNs := uint64(0)
for i := range stats {
if i > 0 {
usageCpuNs += (stats[i].Cpu.Usage.Total - stats[i-1].Cpu.Usage.Total)
}
}
usageMemory := stats[numSamples-1].Memory.Usage
instantUsageInCores := float64(stats[numSamples-1].Cpu.Usage.Total-stats[numSamples-2].Cpu.Usage.Total) / float64(stats[numSamples-1].Timestamp.Sub(stats[numSamples-2].Timestamp).Nanoseconds())
usageInCores := float64(usageCpuNs) / float64(stats[numSamples-1].Timestamp.Sub(stats[0].Timestamp).Nanoseconds())
usageInHuman := units.HumanSize(float64(usageMemory))
glog.Infof("[%s] %.3f cores (average: %.3f cores), %s of memory", c.info.Name, instantUsageInCores, usageInCores, usageInHuman)
}
}
next := c.nextHousekeeping(lastHousekeeping)
// Schedule the next housekeeping. Sleep until that time.
if time.Now().Before(next) {
time.Sleep(next.Sub(time.Now()))
} else {
next = time.Now()
}
lastHousekeeping = next
}
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:71,代码来源:container.go
示例13: VirtualSize
func (c *imageContext) VirtualSize() string {
c.AddHeader(sizeHeader)
return units.HumanSize(float64(c.i.VirtualSize))
}
开发者ID:Mic92,项目名称:docker,代码行数:4,代码来源:image.go
注:本文中的github.com/docker/go-units.HumanSize函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论