Cloud Monitoring CLI
gmon is a command-line interface for Cloud Monitoring written in Python.
The CLI supports the following endpoints:
metrics(GA): Manage Cloud Monitoring metrics.accounts(EAP): Manage Cloud Monitoring accounts.services(ALPHA): Manage Cloud Monitoring services.slos(ALPHA): Manage Cloud Monitoring service level objectives.
Other endpoints are available directly in gcloud alpha monitoring, and won't
be added to gmon, in particular:
channel-descriptors: (ALPHA) Cloud Monitoring notification channel descriptors.channels: (ALPHA) Manage Cloud Monitoring notification channels.policies(ALPHA): Manage Cloud Monitoring alerting policies.dashboards(GA): Manage Cloud Monitoring dashboards.
The goal of this CLI is to fill the gap and simplify users life to query monitoring endpoints in a more friendly manner and troubleshoot their monitoring setups.
Installation
Clone the repository, then run:
cd tools/gmon
python3 setup.py install
Endpoints
Metrics
The gmon metrics command allow one to interact with Google Cloud Monitoring metrics.
You can get more information on the command by running gmon metrics --help, but
here is a cheatsheet:
# List all metrics in project
gmon metrics list -p <PROJECT_ID>
# List specific metrics in project (regex)
gmon metrics list custom. -p <PROJECT_ID>
gmon metrics list "(^custom.|^external.)" -p <PROJECT_ID>
# Get metric descriptor
gmon metrics get vpn.googleapis.com/gateway/connections -p <PROJECT_ID>
# Inspect metrics time series (shows last datapoints written)
gmon metrics inspect istio.io/service/client/request_count -p <PROJECT_ID>
gmon metrics inspect istio.io/service/client/request_count -p <PROJECT_ID> --window 600 # seconds
gmon metrics inspect istio.io/service/client/request_count -p <PROJECT_ID> --filter resource.labels.container_name="my_container"
gmon metrics inspect istio.io/service/client/request_count -p <PROJECT_ID> --filter metric.labels.env=prod metric.labels.period="monitoring.regex.full_match(\".*d\")" # remind yourself to escape the quotes containing the regex
# Create custom metric descriptor
gmon metrics create test/metric -p <PROJECT_ID> --value-type DOUBLE --metric-kind GAUGE --description "Test metric"
# Delete metric (descriptor + timeseries)
gmon metrics delete custom.googleapis.com/test/metric -p <PROJECT_ID>
# Delete all custom metric descriptors in project. Be careful !
gmon metrics list custom. -p <PROJECT_ID> | xargs -P8 -I {} gmon metrics delete {} -p <PROJECT_ID>
# Find and delete unused metrics descriptors (interactive)
gmon metrics delete_unused external.googleapis.com/prometheus -p <PROJECT_ID>
gmon metrics also supports partial queries, meaning if it doesn't find an exact match,
it will ask for your input. For instance:
# Get metric descriptor
gmon metrics get flask_app -p <PROJECT_ID>
gmon.clients.monitoring - INFO - Metric type "flask_app" not found (no exact match). Trying with regex ...
gmon.clients.monitoring - INFO - Found multiple metrics matching regex.
0. external.googleapis.com/prometheus/flask_app_gunicorn_request_duration
1. external.googleapis.com/prometheus/flask_app_gunicorn_request_duration_count
2. external.googleapis.com/prometheus/flask_app_gunicorn_request_duration_sum
3. external.googleapis.com/prometheus/flask_app_gunicorn_request_status_200
4. external.googleapis.com/prometheus/flask_app_gunicorn_request_status_404
5. external.googleapis.com/prometheus/flask_app_gunicorn_requests
6. external.googleapis.com/prometheus/flask_app_gunicorn_workers
7. external.googleapis.com/prometheus/flask_app_hello_requests
Enter your choice: 5
{'metric': {'type': 'external.googleapis.com/prometheus/flask_app_gunicorn_requests'},
'metricKind': 'CUMULATIVE',
'points': [{'interval': {'endTime': '2020-08-04T10:38:59.787Z',
'startTime': '2020-08-04T09:16:59.787Z'},
'value': {'doubleValue': 48710.0}},
{'interval': {'endTime': '2020-08-04T10:38:29.787Z',
'startTime': '2020-08-04T09:16:59.787Z'},
'value': {'doubleValue': 48412.0}}],
'resource': {'labels': {'cluster_name': 'demo-flask',
'container_name': 'statsd-exporter',
'location': 'europe-west1',
'namespace_name': 'default',
'pod_name': 'flask-app-tutorial-5ddd9bdc9-8xc82',
'project_id': 'rnm-datadog-sd'},
'type': 'k8s_container'},
'valueType': 'DOUBLE'}
Services
The gmon services command allow one to interact with Google Cloud Monitoring Services.
# List services
gmon services list -p <PROJECT_ID>
# Get service
gmon services get -p <PROJECT_ID> <SERVICE_ID>
# Create service
gmon services create -p <PROJECT_ID> <SERVICE_ID> <SERVICE_CONFIG_PATH>
# Delete service
gmon services delete -p <PROJECT_ID> <SERVICE_ID>
Service Level Objectives
The gmon slos command allow one to interact with Google Cloud Monitoring Service Level Objectives.
# List SLOs for a service
gmon slos list -p <PROJECT_ID> <SERVICE_ID>
# Get SLO
gmon slos get -p <PROJECT_ID> <SERVICE_ID> <SLO_ID>
# Create SLO
gmon slos create -p <PROJECT_ID> --config <SLO_CONFIG> <SERVICE_ID>
# Update SLO
gmon slos update -p <PROJECT_ID> --config <SLO_CONFIG> <SERVICE_ID>
# Delete SLO
gmon slos delete -p <PROJECT_ID> <SERVICE_ID> <SLO_ID>
Accounts
The gmon accounts command allow one to interact with Google Cloud Operations accounts (formerly Stackdriver workspaces).
To use the Cloud Operations Account client, you need to be whitelisted in the EAP program for the Accounts API. Once you are whitelisted, get your API_KEY and create an OAUTH2 key, and set them as env variables:
export GCP_OAUTH2_CREDENTIALS=/path/to/client_secret_<ID>.apps.googleusercontent.com.json
export GCP_API_KEY=<API_KEY>
Then, use the gmon accounts command to get / create an account, or link a project to an existing account:
# Get Cloud Operations account
gmon accounts get -p <PROJECT_ID>
# Create Cloud Operations account
gmon accounts create -p <PROJECT_ID>
# Link project with Cloud Operations account
gmon accounts link -p <PROJECT_ID> <PROJECT_ID_TO_LINK>
Metadata
Release files for gmon 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gmon-1.1.2.tar.gz | 16.1 kB | Without provenance | Details for gmon-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gmon-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for gmon-1.1.2-py3-none-any.whl |
Total release size: 33.8 kB
Release files / gmon-1.1.2.tar.gz
| Download URL | gmon-1.1.2.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9383a58a17e0b4e67031120f75a7521184d16b3b6d3ac52f0dc6134b530bd7f3
|
|
BLAKE2b-256 checksum How to use checksums |
bf294a99af273a65013109670b9db968755219da9159928111e1ab2bcf5ce5ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
|
Release files / gmon-1.1.2-py3-none-any.whl
| Download URL | gmon-1.1.2-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a409477fc9a3970d55e515d2966a027d8ed999cc0d2630a3941d790db7a0f64
|
|
BLAKE2b-256 checksum How to use checksums |
1a94289d6c883d9eec9dc00294680764c9ae6ee61707318a5bdd6e90e85d7ee1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
|
Security for gmon 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.