3
votes

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
Please make sure the logs are generated after the creation of the logs-based metrics. As the metrics are not populated with data from log entries that are already in Logging. I would also recommend trying the GUI option by following the documentation, this will help to narrow down the issue. - Mustafiz
@MussRahman The answer appears to be that logs created BEFORE the creation of the logs-based metric are not counted in the metric. I've found that and the bottom of the documentation. - DataHearth
glad to hear, my shared document helped. - Mustafiz

1 Answers

4
votes

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.