44 "context"
55 "errors"
66 "fmt"
7+ "io"
78 "net"
89 "net/http"
910 "runtime"
@@ -22,6 +23,7 @@ import (
2223 "github.com/lxc/incus/v6/internal/server/request"
2324 "github.com/lxc/incus/v6/internal/server/response"
2425 "github.com/lxc/incus/v6/internal/server/state"
26+ internalutil "github.com/lxc/incus/v6/internal/util"
2527 "github.com/lxc/incus/v6/shared/api"
2628 "github.com/lxc/incus/v6/shared/logger"
2729)
@@ -367,5 +369,28 @@ func internalMetrics(ctx context.Context, daemonStartTime time.Time, tx *db.Clus
367369 out .AddSamples (metrics .GoStackSysBytes , metrics.Sample {Value : float64 (ms .StackSys )})
368370 out .AddSamples (metrics .GoSysBytes , metrics.Sample {Value : float64 (ms .Sys )})
369371
372+ // If on Incus OS, include OS metrics.
373+ if internalutil .IsIncusOS () {
374+ client := http.Client {}
375+ client .Transport = & http.Transport {
376+ DialContext : func (_ context.Context , network , addr string ) (net.Conn , error ) {
377+ return net .DialTimeout ("tcp" , "127.0.0.1:9100" , 50 * time .Millisecond )
378+ },
379+ DisableKeepAlives : true ,
380+ ExpectContinueTimeout : time .Second * 3 ,
381+ ResponseHeaderTimeout : time .Second * 3 ,
382+ }
383+
384+ resp , err := client .Get ("http://incus-os/metrics" )
385+ if err == nil {
386+ defer resp .Body .Close ()
387+
388+ osMetrics , err := io .ReadAll (resp .Body )
389+ if err == nil {
390+ out .AddRaw (osMetrics )
391+ }
392+ }
393+ }
394+
370395 return out
371396}
0 commit comments