github.com/cilium/cilium@v1.16.2/pkg/health/server/health_linux.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package server
     5  
     6  import (
     7  	"strconv"
     8  
     9  	"golang.org/x/sys/unix"
    10  
    11  	healthModels "github.com/cilium/cilium/api/v1/health/models"
    12  )
    13  
    14  func dumpLoad() (*healthModels.LoadResponse, error) {
    15  	var info unix.Sysinfo_t
    16  	err := unix.Sysinfo(&info)
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  
    21  	scale := float64(1 << unix.SI_LOAD_SHIFT)
    22  	return &healthModels.LoadResponse{
    23  		Last1min:  strconv.FormatFloat(float64(info.Loads[0])/scale, 'f', 2, 64),
    24  		Last5min:  strconv.FormatFloat(float64(info.Loads[1])/scale, 'f', 2, 64),
    25  		Last15min: strconv.FormatFloat(float64(info.Loads[2])/scale, 'f', 2, 64),
    26  	}, nil
    27  }