forked from sylabs/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: start of work to add instance stats
This commit includes adding the singularity stats command group (and docs) and the start of the function that retrieves the instance to interact with. Next I will need to figure out enabling cgroups to instantiate a manager and get stats for the instance from it Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
313 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2022, Sylabs Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package cli | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/sylabs/singularity/docs" | ||
"github.com/sylabs/singularity/internal/app/singularity" | ||
"github.com/sylabs/singularity/pkg/cmdline" | ||
"github.com/sylabs/singularity/pkg/sylog" | ||
) | ||
|
||
// Basic Design | ||
// singularity instance stats <name> | ||
// singularity instance stats --json <name> | ||
|
||
func init() { | ||
addCmdInit(func(cmdManager *cmdline.CommandManager) { | ||
cmdManager.RegisterFlagForCmd(&instanceStatsUserFlag, instanceStatsCmd) | ||
cmdManager.RegisterFlagForCmd(&instanceStatsJSONFlag, instanceStatsCmd) | ||
}) | ||
} | ||
|
||
// -u|--user | ||
var instanceStatsUser string | ||
|
||
var instanceStatsUserFlag = cmdline.Flag{ | ||
ID: "instanceStatsUserFlag", | ||
Value: &instanceStatsUser, | ||
DefaultValue: "", | ||
Name: "user", | ||
ShortHand: "u", | ||
Usage: "view stats for an instance belonging to a user (root only)", | ||
Tag: "<username>", | ||
EnvKeys: []string{"USER"}, | ||
} | ||
|
||
// -j|--json | ||
var instanceStatsJSON bool | ||
|
||
var instanceStatsJSONFlag = cmdline.Flag{ | ||
ID: "instanceStatsJSONFlag", | ||
Value: &instanceStatsJSON, | ||
DefaultValue: false, | ||
Name: "json", | ||
ShortHand: "j", | ||
Usage: "output stats in json", | ||
} | ||
|
||
// singularity instance stats | ||
var instanceStatsCmd = &cobra.Command{ | ||
Args: cobra.RangeArgs(0, 1), | ||
DisableFlagsInUseLine: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// An instance name is required | ||
if len(args) == 0 { | ||
return errors.New("invalid command") | ||
} | ||
|
||
uid := os.Getuid() | ||
|
||
// Root is required to look at stats for another user | ||
if instanceStatsUser != "" && uid != 0 { | ||
sylog.Fatalf("Only the root user can look at stats of a user instance") | ||
} | ||
|
||
// Instance name is the only arg | ||
name := args[0] | ||
return singularity.InstanceStats(name, instanceStatsUser, instanceStatsJSON) | ||
}, | ||
|
||
Use: docs.InstanceStatsUse, | ||
Short: docs.InstanceStatsShort, | ||
Long: docs.InstanceStatsLong, | ||
Example: docs.InstanceStatsExample, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters