mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 01:13:02 +00:00 
			
		
		
		
	kata-runtime: add metrics command
				
					
				
			For easier debug, let's add subcommand to kata-runtime for gathering metrics associated with a given sandbox. kata-runtime metrics --sandbox-id foobar Fixes: #1815 Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
		
							
								
								
									
										38
									
								
								src/runtime/cli/kata-metrics.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/runtime/cli/kata-metrics.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | // Copyright (c) 2021 Apple Inc. | ||||||
|  | // | ||||||
|  | // SPDX-License-Identifier: Apache-2.0 | ||||||
|  | // | ||||||
|  |  | ||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
|  | 	kataMonitor "github.com/kata-containers/kata-containers/src/runtime/pkg/kata-monitor" | ||||||
|  | 	"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils" | ||||||
|  | 	"github.com/urfave/cli" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var kataMetricsCLICommand = cli.Command{ | ||||||
|  | 	Name:      "metrics", | ||||||
|  | 	Usage:     "gather metrics associated with infrastructure used to run a sandbox", | ||||||
|  | 	UsageText: "metrics <sandbox id>", | ||||||
|  | 	Action: func(context *cli.Context) error { | ||||||
|  |  | ||||||
|  | 		sandboxID := context.Args().Get(0) | ||||||
|  |  | ||||||
|  | 		if err := katautils.VerifyContainerID(sandboxID); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		// Get the metrics! | ||||||
|  | 		metrics, err := kataMonitor.GetSandboxMetrics(sandboxID) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		fmt.Printf("%s\n", metrics) | ||||||
|  |  | ||||||
|  | 		return nil | ||||||
|  | 	}, | ||||||
|  | } | ||||||
| @@ -122,6 +122,7 @@ var runtimeCommands = []cli.Command{ | |||||||
| 	kataCheckCLICommand, | 	kataCheckCLICommand, | ||||||
| 	kataEnvCLICommand, | 	kataEnvCLICommand, | ||||||
| 	kataExecCLICommand, | 	kataExecCLICommand, | ||||||
|  | 	kataMetricsCLICommand, | ||||||
| 	factoryCLICommand, | 	factoryCLICommand, | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user