Monitoring

UserAgent/作業系統的 Google App Engine 流量分析

  • September 20, 2019

我有一個在 Google App Engine 中執行的應用程序。他們的生態系統似乎為 StackDriver 中的日誌分析提供了一些工具。

對於我的生活,我無法弄清楚如何獲得按使用者代理或作業系統分解的 HTTP 請求的簡單圖表。

如何配置這樣的圖表?

截至目前,這是不可能的,如文件“指標種類”部分下的表格中所述,其中表示您無法創建值類型為 STRING 的自定義指標。

我已經通過在相應的 repo 文件中使用函式 create_metric_descriptor並編輯其正文來確認這一點:

descriptor.value_type = (monitoring_v3.enums.MetricDescriptor.ValueType.STRING)  

並得到這個錯誤:

InvalidArgument: 400 Field metricDescriptor.valueType had an invalid value of "STRING": When creating metric custom.googleapis.com/my_metric_6365: the value type is not supported for custom metrics.

無論如何,您仍然可以從 Stackdriver Logging 獲取有價值的資訊,以將其傳輸到您選擇的任何數據科學和視覺化方法。您將盡可能從 protoPayload.userAgent 欄位中提取有關作業系統的資訊。

只需試用 Cloud SDK,例如,如下所示:

$ project_id= #FILL
$ module_id=default #EDIT
$ version_id= #FILL
$ gcloud logging read "resource.type=gae_app AND resource.labels.module_id=$module_id AND resource.labels.version_id=$version_id AND logName=(projects/$project_id/logs/stderr OR projects/$project_id/logs/appengine.googleapis.com%2Frequest_log)" --format "json(receiveTimestamp, protoPayload.userAgent, protoPayload.ip, protoPayload.resource)"

你會得到如下條目:

[
  {
           "protoPayload": {
                   "ip": "....",
                   "resource": "/",
                   "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
           },
           "receiveTimestamp": "2019-09-19T15:39:42.236439758Z"
  },
  {
           "protoPayload": {
                   "ip": "...",
                   "resource": "/",
                   "userAgent": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G930F Build/R16NW; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.157 Mobile Safari/537.36"
           },
           "receiveTimestamp": "2019-09-19T15:39:41.153786772Z"
   },
   {
           "protoPayload": {
                   "ip": "...",
                   "resource": "/",
                   "userAgent": "Mozilla/5.0 (Windows NT 5.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"
           },
           "receiveTimestamp": "2019-09-19T15:39:33.286861169Z"
  },
  {
           "protoPayload": {
                   "ip": "...",
                   "resource": "/",
                   "userAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0"
           },
           "receiveTimestamp": "2019-09-19T15:39:31.259811179Z"
   },
   {
           "protoPayload": {
                   "ip": "...",
                   "resource": "/",
                   "userAgent": "curl/7.66.0"
           },
           "receiveTimestamp": "2019-09-19T15:39:01.134762065Z"
   },
   {
           "protoPayload": {
                   "ip": "...",
                   "resource": "/",
                   "userAgent": "Wget/1.17 (linux-gnu)"
           },
           "receiveTimestamp": "2019-09-19T15:38:54.488718412Z"
   }
]

引用自:https://serverfault.com/questions/984762