Sometimes our GCP VM instances reboot without any apparent reason, and I want to view the logs of the VMs using the Google Logs Exporter service. In my GCP project, I have more than 200 instances, but I can see only 30–40 GKE nodes.
I saw logs from the hosts approximately a year ago, but now they have disappeared. No host settings have been changed.
I know it should work without installing any agents by default. If you install an agent, you will just see more information from the host, but it is not necessary.
How can I check if logs are enabled for the VM instances or the entire project?
I found the problem
The ServiceAccount used with VM does not have permissions to write logs.
These rights were missing:
resource "google_project_iam_member" "backend_machine_monitoring_metric_writer" {
project = var.project
role = "roles/monitoring.metricWriter"
member = "serviceAccount:${google_service_account.backend_machine.email}"
}
resource "google_project_iam_member" "backend_machine_logging_log_writer" {
project = var.project
role = "roles/logging.logWriter"
member = "serviceAccount:${google_service_account.backend_machine.email}"
}