Can't display data with with log-based metric

[亡魂溺海] 提交于 2020-06-16 17:25:31

问题


I’m struggling to create a chart with stackdriver monitoring with a log-based metric. My metric is a counter one with no unit by default.
Logs are available for my log-based metric but when I create a chart with my metric, it says no data is available for the....
Here’s my metric which does work (called isOperatorAllowed):

resource.type="container"
resource.labels.namespace_id="default"
jsonPayload.message="CaseForOperator flags"
logName="projects/PROJECT-ID/logs/app"
jsonPayload.caseForOperatorFlags.isOperatorAllowed=true

And here’s my JSON config of my chart

{
  "dataSets": [
    {
      "timeSeriesFilter": {
        "filter": "metric.type=\"logging.googleapis.com/user/IsOperatorAllowed\" resource.type=\"gke_container\"",
        "perSeriesAligner": "ALIGN_RATE",
        "crossSeriesReducer": "REDUCE_NONE",
        "secondaryCrossSeriesReducer": "REDUCE_NONE",
        "minAlignmentPeriod": "60s",
        "groupByFields": [],
        "unitOverride": "1"
      },
      "targetAxis": "Y1",
      "plotType": "LINE"
    }
  ],
  "options": {
    "mode": "COLOR"
  },
  "constantLines": [],
  "timeshiftDuration": "0s",
  "y1Axis": {
    "label": "y1Axis",
    "scale": "LINEAR"
  }
}

Does someone know what I’m doing wrong?


回答1:


After discussions and helps, the answer is:
the logs-based metric takes only logs after its creation. So if your logs are older than the metric creation timestamp, they won't appear in the metric count/distribution

Example:

Metric: `03/06/2020 15:55:33`
log 1: `02/06/2020 12:00:00`
log 2: `07/06/2020 12:00:00`

Metric count result: 1 (it will be the log 2)

Here what says the documentation:

New log entries might not match your metric's logs query. A logs-based metric gets data from matching log entries that are received after the metric is created. Logging does not backfill the metric from previous log entries.



来源:https://stackoverflow.com/questions/60486112/cant-display-data-with-with-log-based-metric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!