跳转到主要内容

云监控API客户端(非官方)

项目描述

云监控CLI

gmon 是用Python编写的云监控命令行界面。

CLI支持以下端点

  • metrics (GA):管理云监控指标。
  • accounts (EAP):管理云监控账户。
  • services (ALPHA):管理云监控服务。
  • slos (ALPHA):管理云监控服务级别目标。

其他端点可直接在 gcloud alpha monitoring 中使用,不会添加到 gmon,特别是

  • channel-descriptors (ALPHA):云监控通知通道描述符。
  • channels (ALPHA):管理云监控通知通道。
  • policies (ALPHA):管理云监控警报策略。
  • 仪表盘 (GA):管理云监控仪表盘。

此 CLI 的目标是填补空白,简化用户查询监控端点的方式,并 troubleshoot 他们的监控设置。

安装

克隆存储库,然后运行

cd tools/gmon
python3 setup.py install

端点

度量

gmon metrics 命令允许您与 Google Cloud Monitoring 度量进行交互。

您可以通过运行 gmon metrics --help 来获取有关此命令的更多信息,但这里有一份速查表

# 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 也支持部分查询,这意味着如果找不到精确匹配项,它将要求您输入。例如

# 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'}

服务

gmon services 命令允许您与 Google Cloud Monitoring 服务进行交互。

# 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>

服务水平目标

gmon slos 命令允许您与 Google Cloud Monitoring 服务水平目标进行交互。

# 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>

账户

gmon accounts 命令允许您与 Google Cloud Operations 账户(以前称为 Stackdriver 工作区)进行交互。

要使用云操作账户客户端,您需要获得 Accounts API 的 EAP 程序的 white-listed。一旦您被 white-listed,获取您的 API_KEY 并创建一个 OAUTH2 密钥,并将它们设置为环境变量

export GCP_OAUTH2_CREDENTIALS=/path/to/client_secret_<ID>.apps.googleusercontent.com.json
export GCP_API_KEY=<API_KEY>

然后,使用 gmon accounts 命令获取 / 创建一个账户,或将项目链接到现有账户

# 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>

项目详情


下载文件

下载您平台的文件。如果您不确定要选择哪个,请了解更多关于 安装软件包 的信息。

源分布

gmon-1.1.2.tar.gz (16.1 kB 查看散列值)

上传时间

构建分布

gmon-1.1.2-py3-none-any.whl (17.8 kB 查看散列值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面