@@ -78,6 +78,9 @@ type Config struct {
7878 // should be created.
7979 SocketPath string
8080
81+ // LogPath defines the file path where the Firecracker log is located.
82+ LogPath string
83+
8184 // LogFifo defines the file path where the Firecracker log named-pipe should
8285 // be located.
8386 LogFifo string
@@ -86,6 +89,10 @@ type Config struct {
8689 // "Error", "Warning", "Info", and "Debug", and are case-sensitive.
8790 LogLevel string
8891
92+ // MetricsPath defines the file path where the Firecracker metrics
93+ // is located.
94+ MetricsPath string
95+
8996 // MetricsFifo defines the file path where the Firecracker metrics
9097 // named-pipe should be located.
9198 MetricsFifo string
@@ -585,29 +592,29 @@ func (m *Machine) stopVMM() error {
585592 return nil
586593}
587594
588- // createFifos sets up the firecracker logging and metrics FIFOs
589- func createFifos ( logFifo , metricsFifo string ) error {
590- log .Debugf ("Creating FIFO %s" , logFifo )
591- if err := syscall .Mkfifo (logFifo , 0700 ); err != nil {
595+ // createFifo sets up a FIFOs
596+ func createFifo ( path string ) error {
597+ log .Debugf ("Creating FIFO %s" , path )
598+ if err := syscall .Mkfifo (path , 0700 ); err != nil {
592599 return fmt .Errorf ("Failed to create log fifo: %v" , err )
593600 }
594-
595- log .Debugf ("Creating metric FIFO %s" , metricsFifo )
596- if err := syscall .Mkfifo (metricsFifo , 0700 ); err != nil {
597- return fmt .Errorf ("Failed to create metric fifo: %v" , err )
598- }
599601 return nil
600602}
601603
602604func (m * Machine ) setupLogging (ctx context.Context ) error {
603- if len (m .Cfg .LogFifo ) == 0 || len (m .Cfg .MetricsFifo ) == 0 {
605+ path := m .Cfg .LogPath
606+ if len (m .Cfg .LogFifo ) > 0 {
607+ path = m .Cfg .LogFifo
608+ }
609+
610+ if len (path ) == 0 {
604611 // No logging configured
605- m .logger .Printf ("VMM logging and metrics disabled." )
612+ m .logger .Printf ("VMM logging disabled." )
606613 return nil
607614 }
608615
609616 l := models.Logger {
610- LogPath : String (m . Cfg . LogFifo ),
617+ LogPath : String (path ),
611618 Level : String (m .Cfg .LogLevel ),
612619 ShowLevel : Bool (true ),
613620 ShowLogOrigin : Bool (false ),
@@ -618,10 +625,31 @@ func (m *Machine) setupLogging(ctx context.Context) error {
618625 return err
619626 }
620627
621- m .logger .Debugf ("Configured VMM logging to %s, metrics to %s" ,
622- m .Cfg .LogFifo ,
623- m .Cfg .MetricsFifo ,
624- )
628+ m .logger .Debugf ("Configured VMM logging to %s" , path )
629+
630+ return nil
631+ }
632+
633+ func (m * Machine ) setupMetrics (ctx context.Context ) error {
634+ path := m .Cfg .MetricsPath
635+ if len (m .Cfg .MetricsFifo ) > 0 {
636+ path = m .Cfg .MetricsFifo
637+ }
638+
639+ if len (path ) == 0 {
640+ // No logging configured
641+ m .logger .Printf ("VMM metrics disabled." )
642+ return nil
643+ }
644+
645+ _ , err := m .client .PutMetrics (ctx , & models.Metrics {
646+ MetricsPath : String (path ),
647+ })
648+ if err != nil {
649+ return err
650+ }
651+
652+ m .logger .Debugf ("Configured VMM metrics to %s" , path )
625653
626654 return nil
627655}
0 commit comments