Skip to content

Commit

Permalink
feat: use Cloud API access scopes instead of Service Account by defau…
Browse files Browse the repository at this point in the history
…lt auth

Signed-off-by: Valentin Pichard <7628998+w3st3ry@users.noreply.github.com>
  • Loading branch information
w3st3ry committed Jan 5, 2021
1 parent 3c198d3 commit e0f576d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tiny Go binary that aims to export Nvidia GPU metrics to GCP monitoring, based o
## Requirements ⚓

* Your machine must be a GCE (Google Compute Engine) instance.
* Your Service Account must have the `Monitoring Metric Writer` permission.
* The `Cloud API access scopes` of the instance or `Service Account` must have the `Monitoring Metric Writer` permission.
* You need the `nvidia-smi` binary installed on your GCE instance.


Expand All @@ -17,7 +17,7 @@ Protip: You can use a [machine learning image](https://cloud.google.com/ai-platf

If you're root, you can install the latest binary version using the following script:
```bash
$ bash -e < <(curl -sSL https://raw.githubusercontent.com/instadeepai/gcp-gpu-metrics/master/install-latest.sh)
$ bash < <(curl -sSL https://raw.githubusercontent.com/instadeepai/gcp-gpu-metrics/master/install-latest.sh)
```

Or, you can download a [release/binary from this page](https://github.com/instadeepai/gcp-gpu-metrics/releases) and install it manually.
Expand All @@ -32,7 +32,7 @@ $ gcp-gpu-metrics

Available flags:

* `--service-account-path string` | GCP service account path. (default "./service-account.json")
* `--service-account-path string` | GCP service account path. (default "")
* `--metrics-interval uint` | Fetch metrics interval in seconds. (default 10)
* `--enable-nvidiasmi-pm` | Enable persistence mod for nvidia-smi. (default false)
* `--version` | Display current version/release and commit hash.
Expand Down
2 changes: 1 addition & 1 deletion hack/gcp-gpu-metrics.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ StartLimitInterval=3
Type=simple
Restart=on-failure
RestartSec=10s
ExecStart=/usr/local/bin/gcp-gpu-metrics --enable-nvidiasmi-pm --service-account-path /root/service-account.json
ExecStart=/usr/local/bin/gcp-gpu-metrics --enable-nvidiasmi-pm

[Install]
WantedBy=multi-user.target
4 changes: 3 additions & 1 deletion install-latest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -e
#!/bin/bash

set -e

pushd /tmp/

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
var (
// flags related

flagDisplayVersion bool
flagServiceAccountPath string = "./service-account.json"
flagDisplayVersion bool = false
flagServiceAccountPath string = ""
flagFetchMetricsInterval uint64 = 10
flagEnableNvidiasmipm bool = false

Expand Down Expand Up @@ -54,7 +54,7 @@ func evaluateEnvVars() {
func main() {
evaluateEnvVars()

flag.BoolVar(&flagDisplayVersion, "version", false, "Display current version/release and commit hash.")
flag.BoolVar(&flagDisplayVersion, "version", flagDisplayVersion, "Display current version/release and commit hash.")
flag.StringVar(&flagServiceAccountPath, "service-account-path", flagServiceAccountPath, "GCP service account path.")
flag.Uint64Var(&flagFetchMetricsInterval, "metrics-interval", flagFetchMetricsInterval, "Fetch metrics interval in seconds.")
flag.BoolVar(&flagEnableNvidiasmipm, "enable-nvidiasmi-pm", flagEnableNvidiasmipm, "Enable persistant mod for nvidia-smi.")
Expand Down
10 changes: 9 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ type service struct {

func newService(slog *syslog.Writer) (*service, error) {
ctx := context.Background()
client, err := monitoring.NewMetricClient(ctx, option.WithCredentialsFile(flagServiceAccountPath))

var client *monitoring.MetricClient
var err error

if flagServiceAccountPath == "" {
client, err = monitoring.NewMetricClient(ctx)
} else {
client, err = monitoring.NewMetricClient(ctx, option.WithCredentialsFile(flagServiceAccountPath))
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e0f576d

Please sign in to comment.