问题
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