mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	Implement loadavg on FreeBSD without cgo
The code may also work for other BSDs, but I don't have access to those for testing.
This commit is contained in:
		
							parent
							
								
									10e525ff02
								
							
						
					
					
						commit
						54c74923ee
					
				
							
								
								
									
										27
									
								
								collector/loadavg_freebsd.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								collector/loadavg_freebsd.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,27 @@
 | 
			
		|||
// +build !noloadavg
 | 
			
		||||
 | 
			
		||||
package collector
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func getLoad() ([]float64, error) {
 | 
			
		||||
	type loadavg struct {
 | 
			
		||||
		load  [3]uint32
 | 
			
		||||
		scale int
 | 
			
		||||
	}
 | 
			
		||||
	b, err := unix.SysctlRaw("vm.loadavg")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	load := *(*loadavg)(unsafe.Pointer((&b[0])))
 | 
			
		||||
	scale := float64(load.scale)
 | 
			
		||||
	return []float64{
 | 
			
		||||
		float64(load.load[0]) / scale,
 | 
			
		||||
		float64(load.load[1]) / scale,
 | 
			
		||||
		float64(load.load[2]) / scale,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +11,7 @@
 | 
			
		|||
// See the License for the specific language governing permissions and
 | 
			
		||||
// limitations under the License.
 | 
			
		||||
 | 
			
		||||
// +build darwin dragonfly freebsd netbsd openbsd solaris
 | 
			
		||||
// +build darwin dragonfly netbsd openbsd solaris
 | 
			
		||||
// +build !noloadavg
 | 
			
		||||
 | 
			
		||||
package collector
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue