This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c5a89c
commit bc81529
Showing
24 changed files
with
533 additions
and
125 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,30 @@ | ||
# BatchInsights Configuration | ||
|
||
Batch Insights provides various configuration option(Version `1.2.0` and above). | ||
|
||
|
||
#### `--poolID <value>` | ||
Pool ID. Override pool ID provided by the `AZ_BATCH_POOL_ID` environment variable | ||
#### `--nodeID <value>` | ||
Node ID. Override node ID provided by the `AZ_BATCH_NODE_ID` environment variable | ||
#### `--instKey <value>` | ||
Instrumentation key. Application Insights instrumentation key to emit the metrics | ||
#### `--disable <value>` | ||
Comma separated list of metrics to disable. e.g. `--disable networkIO,diskUsage` | ||
|
||
Available metrics names: | ||
- diskIO | ||
- diskUsage | ||
- networkIO | ||
- memory | ||
- CPU | ||
- GPU | ||
|
||
* `--aggregation <value>` Number in minutes to aggregate the data locally. Defaults to 1 minute | ||
|
||
Example: `--agregation 5` to aggregate for 5 minutes | ||
|
||
#### `--processes <value>` | ||
Comma separated list of processes to monitor. | ||
|
||
Example: `--processes notepad.exe,explorer.exe` |
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 |
---|---|---|
@@ -1,48 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/Azure/batch-insights/pkg" | ||
log "github.com/sirupsen/logrus" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func parseListArgs(value string) []string { | ||
names := strings.Split(value, ",") | ||
for i := range names { | ||
names[i] = strings.TrimSpace(names[i]) | ||
} | ||
return names | ||
} | ||
|
||
func getenv(key string) *string { | ||
value := os.Getenv(key) | ||
if len(value) == 0 { | ||
return nil | ||
} | ||
return &value | ||
} | ||
|
||
func initLogger() { | ||
log.SetFormatter(&log.TextFormatter{ | ||
FullTimestamp: false, | ||
DisableTimestamp: true, | ||
ForceColors: true, | ||
}) | ||
} | ||
|
||
func main() { | ||
var appInsightsKey = os.Getenv("APP_INSIGHTS_INSTRUMENTATION_KEY") | ||
var poolId = os.Getenv("AZ_BATCH_POOL_ID") | ||
var nodeId = os.Getenv("AZ_BATCH_NODE_ID") | ||
var processNamesStr = os.Getenv("AZ_BATCH_MONITOR_PROCESSES") | ||
initLogger() | ||
disableArg := flag.String("disable", "", "List of metrics to disable") | ||
processArg := flag.String("processes", "", "List of process name to watch") | ||
|
||
if len(os.Args) > 2 { | ||
poolId = os.Args[1] | ||
nodeId = os.Args[2] | ||
envConfig := batchinsights.UserConfig{ | ||
InstrumentationKey: getenv("APP_INSIGHTS_INSTRUMENTATION_KEY"), | ||
PoolID: getenv("AZ_BATCH_POOL_ID"), | ||
NodeID: getenv("AZ_BATCH_NODE_ID"), | ||
} | ||
processEnv := getenv("AZ_BATCH_MONITOR_PROCESSES") | ||
if processEnv != nil { | ||
envConfig.Processes = parseListArgs(*processEnv) | ||
} | ||
argsConfig := batchinsights.UserConfig{ | ||
PoolID: flag.String("poolID", "", "Batch pool ID"), | ||
NodeID: flag.String("nodeID", "", "Batch node ID"), | ||
Aggregation: flag.Int("aggregation", 1, "Aggregation in minutes"), | ||
InstrumentationKey: flag.String("instKey", "", "Application Insights instrumentation KEY"), | ||
} | ||
|
||
version := flag.Bool("version", false, "Print current batch insights version") | ||
|
||
if len(os.Args) > 3 { | ||
appInsightsKey = os.Args[3] | ||
flag.Parse() | ||
|
||
if *version { | ||
fmt.Println(batchinsights.Version) | ||
os.Exit(0) | ||
} | ||
|
||
if len(os.Args) > 4 { | ||
processNamesStr = os.Args[4] | ||
if processArg != nil { | ||
argsConfig.Processes = parseListArgs(*processArg) | ||
} | ||
if disableArg != nil { | ||
argsConfig.Disable = parseListArgs(*disableArg) | ||
} | ||
|
||
processNames := strings.Split(processNamesStr, ",") | ||
for i := range processNames { | ||
processNames[i] = strings.TrimSpace(processNames[i]) | ||
config := envConfig.Merge(argsConfig) | ||
|
||
positionalArgs := flag.Args() | ||
if len(positionalArgs) > 0 { | ||
log.Warn("Using postional arguments for Node ID, PoolID, KEY and Process names is deprecated. Use --poolID, --nodeID, --instKey, --process") | ||
log.Warn("It will be removed in 2.0.0") | ||
config.PoolID = &positionalArgs[0] | ||
} | ||
|
||
batchinsights.PrintSystemInfo() | ||
fmt.Printf(" Pool ID: %s\n", poolId) | ||
fmt.Printf(" Node ID: %s\n", nodeId) | ||
if len(positionalArgs) > 1 { | ||
config.NodeID = &positionalArgs[1] | ||
} | ||
|
||
hiddenKey := "-" | ||
if appInsightsKey != "" { | ||
hiddenKey = "xxxxx" | ||
if len(positionalArgs) > 2 { | ||
config.InstrumentationKey = &positionalArgs[2] | ||
} | ||
|
||
fmt.Printf(" Instrumentation Key: %s\n", hiddenKey) | ||
if len(positionalArgs) > 3 { | ||
config.Processes = parseListArgs(positionalArgs[3]) | ||
} | ||
|
||
config.Print() | ||
|
||
fmt.Printf(" Monitoring processes: %s\n", strings.Join(processNames, ", ")) | ||
computedConfig, err := batchinsights.ValidateAndBuildConfig(config) | ||
|
||
batchinsights.ListenForStats(poolId, nodeId, appInsightsKey, processNames) | ||
if err != nil { | ||
log.Error("Invalid config", err) | ||
os.Exit(2) | ||
} | ||
|
||
computedConfig.Print() | ||
batchinsights.PrintSystemInfo() | ||
batchinsights.ListenForStats(computedConfig) | ||
} |
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
Oops, something went wrong.