标签: stackdriver

使用Google Cloud Monitoring v3 api写入自定义时间序列

谷歌警告说,v2监控api现已弃用,很快就会消失.然而,迁移到v3被证明有点困难.我正在尝试编写自定义指标,并收到以下错误响应:

服务> Google Monitoring API v3> monitoring.projects.timeSeries.create

{
    "timeSeries": [{
        "metric": {
            "type": "custom.googleapis.com/test_metric",
            "labels": {
                "payment_type": "Paypal"
            }
        },
        "resource": {
            "type": "custom.googleapis.com/test_metric",
            "labels": {
                "payment_type": "Paypal"
            }
        },
        "metricKind": "GAUGE",
        "valueType": "INT64",
        "points": [{
            "interval": {
                "endTime": "2016-03-20T15:01:23.045123456Z",
                "startTime": "2016-03-20T15:01:23.045123456Z"
            },
            "value": {
                "int64Value": "2"
            }
        }]
    }]
}

{
  "error": {
  "code": 400,
  "message": "Field timeSeries[0].resource.type had an invalid value of \"custom.googleapis.com/test_metric\": Unrecognized resource name.",
  "status": "INVALID_ARGUMENT"
}
Run Code Online (Sandbox Code Playgroud)

"资源"字段是必需的,文档称它是"MonitoredResource"...但我没有看到任何api用于创建一个,仅用于列表.采取疯狂的猜测并将其设置为"全局"似乎让我更进一步,并给了我这个不同的错误:

{
 "error": {
  "code": 400,
  "message": "Field timeSeries[0].resource.labels[0] …
Run Code Online (Sandbox Code Playgroud)

google-app-engine google-cloud-platform stackdriver google-cloud-monitoring

7
推荐指数
1
解决办法
1763
查看次数

如何在Google Container VM映像中安装Stackdriver监控代理?

我按照此说明 https://cloud.google.com/monitoring/agent/install-agent#linux-install

$ curl -O "https://repo.stackdriver.com/stack-install.sh"
$ sudo bash stack-install.sh --write-gcm
Unidentifiable or unsupported platform.
Run Code Online (Sandbox Code Playgroud)

/ etc/os-release的内容.

$ cat /etc/os-release
BUILD_ID=8820.0.0
NAME="Container-VM Image"
GOOGLE_CRASH_ID=Lakitu
VERSION_ID=55
BUG_REPORT_URL=https://crbug.com/new
PRETTY_NAME="Google Container-VM Image"
VERSION=55
GOOGLE_METRICS_PRODUCT_ID=26
HOME_URL="https://cloud.google.com/compute/docs/containers/vm-image/"
ID=gci
Run Code Online (Sandbox Code Playgroud)

https://cloud.google.com/compute/docs/containers/vm-image/faq#what_is_the_software_package_manager_for_container-vm_image

为了更新特定包,需要更新整个OS映像

所以,似乎我们必须等到更新堆栈驱动程序代理安装的映像版本或放弃它.

此vm图像也不是我的选择.默认情况下,新创建的GKE节点使用Container-VM映像.所以现在我将尝试通过创建节点gcloud container node-pools create --image-type

google-kubernetes-engine stackdriver google-container-os

7
推荐指数
3
解决办法
1989
查看次数

我可以为 StackDriver 错误报告通知指定不同的电子邮件吗

我们尝试使用 StackDriver 错误报告通知功能,但似乎对于任何项目,当我们打开通知时,它总是发送到与我们登录的开发者帐户关联的电子邮件。我们如何将其更改为不同的电子邮件帐户。(我们使用 PageDuty,我们希望将此通知发送到 pagerduty 接收器电子邮件帐户)

stackdriver google-cloud-error-reporting

7
推荐指数
1
解决办法
1021
查看次数

使用 stackdriver CLI 查找时间戳之间的日志

我需要使用 stackdriver CLI 查找两个时间戳之间的日志。我使用了以下命令。

gcloud beta logging read "timestamp>=\"2017-02-19T00:00:00Z\" AND timestamp<\"2017-03-14T00:00:00Z\"" 
Run Code Online (Sandbox Code Playgroud)

但它给了我错误:

文件名、目录名或卷标语法不正确。

这是我的 gcloud 版本详细信息

gcloud --version

google-cloud-platform gcloud stackdriver

7
推荐指数
3
解决办法
3045
查看次数

使用Google Sheet Add-on时,Stackdriver中"脚本延迟(xx分钟)等待配额"的含义

我开发了一个Google Sheet Add-On"Jira Sheet Tools",基本上对于我的理解应该只受到谷歌根据配额仪表板的以下配额的影响:

  • 属性读/写
  • URL提取呼叫
  • URL获取收到的数据

a)配额概述对"消费者","Google Apps .."和"G-Suite"中的限制进行分类.如何阅读/理解这一点; 限制是否适用于我的附加组件的每个用户,或者是针对我的开发人员帐户对所有已安装的实例使用的限制?

b)在我相关的Stackdriver日志中,我可以看到很多(每天/每小时几个)错误日志,如:

脚本延迟(21.0分钟)等待配额

脚本延迟(813.0分钟)等待配额

我不明白为什么以及如何.对于我自己,当我自己使用附加组件时,我无法重现这些日志的任何触发器.它必须由我的附加组件的其他用户引起,我想了解为什么会发生这种情况,对用户的影响是什么以及如何改进我的附加组件以避免此类错误/延迟.

任何见解和帮助都非常有用.Thx提前

add-on google-sheets quota google-apps-script stackdriver

7
推荐指数
1
解决办法
503
查看次数

Google Cloud Container优化的操作系统主机记录到stackdriver

TL; DR
将容器优化的os 主机日志(ssh和执行的shell命令)发送到Stackdriver 的最佳做法是什么?

背景:
我正在使用Googles Container Optimized OS,效果很好.将容器日志发送到Stackdriver非常容易,但如何将主机日志发送到Stackdriver?

这是出于审计目的,我需要记录所有SSH连接(接受或拒绝)以及通过shell执行的所有命令.以前我只是通过stackdriver主机记录器包将rsyslogd(auth,authpriv)发送到stackdriver.

这适用于在托管实例组(mig)中运行的Container Optimized OS VM,而不是在Google Kubernetes Engine中运行.

它可能非常明显,但我似乎无法找到任何文档.

google-cloud-platform stackdriver

7
推荐指数
1
解决办法
644
查看次数

在GKE上运行的Ruby的Stackdriver错误报告

从GKE上运行的Rails应用程序收集错误需要哪些步骤?

我已将stackdriver gem添加到我的Rails应用程序中,并且已经使用该errorreporting.errorEvents.create权限创建了自定义角色.该角色将提供给Compute Engine默认服务帐户

我解释在GKE上运行时不需要执行以下设置的文档:

# Add this to config/environments/*.rb
Rails.application.configure do |config|
  # Stackdriver Error Reporting specific parameters
  config.google_cloud.error_reporting.project_id = "YOUR-PROJECT-ID"
  config.google_cloud.error_reporting.keyfile    = "/path/to/service-account.json"
end
Run Code Online (Sandbox Code Playgroud)

我手动创建了一个例外

这给了我宝贵的信息:

irb(main):001:0> Google::Cloud::ErrorReporting.report Exception.new(msg: "from console")
=> nil
irb(main):002:0> {:msg=>"from console"} (Exception)
Google::Cloud::PermissionDeniedError: 7:Stackdriver Error Reporting API has not been used in project NNNNN before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/clouderrorreporting.googleapis.com/overview?project=NNNN then retry. If you enabled this API recently, wait a few minutes …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails google-kubernetes-engine stackdriver google-cloud-stackdriver google-iam

7
推荐指数
1
解决办法
172
查看次数

获取Terraform google_monitoring_notification_channel资源的Slack auth_token

我希望从gcloud-> slack设置一些警报,到目前为止,已经按照以下说明进行了测试并正在运行:

https://cloud.google.com/monitoring/support/notification-options?_ga=2.190773474.-879257953.1550134526#slack

但是,理想情况下,我会将这些通知的配置存储在terraform脚本中,这样,如果需要再次设置,则无需遵循手动步骤。看起来这应该可行:https//www.terraform.io/docs/providers/google/r/monitoring_notification_channel.html

我已经运行了gcloud alpha monitoring channel-descriptors describe projects/<My Project>/notificationChannelDescriptors/slack,它会为labels + type产生以下输出:

labels:
- description: A permanent authentication token provided by Slack. This field is obfuscated
    by returning only a few characters of the key when fetched.
  key: auth_token
- description: The Slack channel to which to post notifications.
  key: channel_name
type: slack
Run Code Online (Sandbox Code Playgroud)

因此,我认为通知渠道的Terraform配置希望是:

resource "google_monitoring_notification_channel" "basic" {
  display_name = "My slack notifications"
  type = "slack"
  labels = {
    auth_token = "????????"
    channel_name = …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform terraform slack stackdriver

7
推荐指数
1
解决办法
349
查看次数

如何使用StackDriver API的v2查询BigQuery用法?

我准备用这些Stackdriver API金跟踪BigQuery的使用情况和存在设置此功能的一个很好的教程在这里.但是,此处的查询使用API 的弃用v1,并且可用文档仍然适用于v1.

在BigQuery控制台中,v2仅提供以下字段:

logName
timestamp
severity
insertId
resource
resource.type
resource.labels
resource.labels.project_id
httpRequest
httpRequest.requestMethod
httpRequest.requestUrl
httpRequest.requestSize
httpRequest.status
httpRequest.responseSize
httpRequest.userAgent
httpRequest.remoteIp
httpRequest.serverIp
httpRequest.referer
httpRequest.cacheHit
httpRequest.cacheValidatedWithOriginServer
httpRequest.latency
httpRequest.cacheLookup
httpRequest.cacheFillBytes
operation
operation.id
operation.producer
operation.first
operation.last
protopayload_google_cloud_audit_auditlog
protopayload_google_cloud_audit_auditlog.serviceName
protopayload_google_cloud_audit_auditlog.methodName
protopayload_google_cloud_audit_auditlog.resourceName
protopayload_google_cloud_audit_auditlog.numResponseItems
protopayload_google_cloud_audit_auditlog.status
protopayload_google_cloud_audit_auditlog.status.code
protopayload_google_cloud_audit_auditlog.status.message
trace
sourceLocation  
sourceLocation.file 
sourceLocation.line 
sourceLocation.function
Run Code Online (Sandbox Code Playgroud)

现在没有totalBilledBytes字段,在示例v1查询中用于计算使用情况.如何使用API​​的v2查询使用成本?

google-bigquery google-cloud-platform stackdriver

6
推荐指数
1
解决办法
477
查看次数

使用 Python 查询 GCP Stackdriver 日志

我正在使用 Python3 查询 Stackdriver 以获取 GCP 日志。不幸的是,具有重要数据的日志条目以“NoneType”而不是“dict”或“str”的形式返回给我。结果“entry.payload”是“None”类型,“entry.payload_pb”有我想要的数据,但是是乱码。

有没有办法让 Stackdriver 以干净的格式返回这些数据,或者有没有办法解析它?如果没有,有没有办法查询比我正在做的更好的数据并产生干净的数据?

我的代码看起来像这样:

#!/usr/bin/python3

from google.cloud.logging import Client, ASCENDING, DESCENDING
from google.oauth2.service_account import Credentials

projectName = 'my_project'
myFilter = 'logName="projects/' + projectName + '/logs/compute.googleapis.com%2Factivity_log"'

client = Client(project = projectName)
entries = client.list_entries(order_by=DESCENDING, page_size = 500, filter_ = myFilter)
for entry in entries:
    if isinstance(entry.payload, dict):
        print(entry.payload)
    if isinstance(entry.payload, str):
        print(entry.payload)
    if isinstance(entry.payload, None):
        print(entry.payload_pb)
Run Code Online (Sandbox Code Playgroud)

“entry.payload_pb”数据总是这样开头:

type_url: "type.googleapis.com/google.cloud.audit.AuditLog"
 value: "\032;\n9gcp-user@my-project.iam.gserviceaccount.com"I\n\r129.105.16.28\0228
Run Code Online (Sandbox Code Playgroud)

google-bigquery google-cloud-logging stackdriver google-cloud-python google-cloud-stackdriver

6
推荐指数
1
解决办法
2023
查看次数