Recursos identificados
- APIs habilitadas:
compute.googleapis.com,monitoring.googleapis.com,logging.googleapis.com. - VM:
quickstart-vm(e2-small, Debian, us-east4-c, taghttp-server). - Firewall: permite tcp:80 desde
0.0.0.0/0a VMs con taghttp-server. - Software en la VM: Apache2 + PHP + Google Cloud Ops Agent.
- Ops Agent config: pipelines personalizados para métricas y logs de Apache (
apache,apache_access,apache_error). - Cloud Monitoring: dashboard predefinido "Apache Overview", canal de notificación por email, alerting policy por tráfico Apache (
workload.googleapis.com/apache.traffic > 4 KiB/s).
Comandos ejecutados
En los comandos siguientes, reemplazá <ZONE> y <PROJECT_ID> por los valores de tu lab.
Verificar autenticación y proyecto activo
gcloud auth list
gcloud config list project
Conectarse a la VM por SSH
gcloud compute ssh --zone "<ZONE>" "quickstart-vm" --project "<PROJECT_ID>"
Instalar Apache y PHP
sudo apt-get update
sudo apt-get install apache2 php7.0 -y
Instalar el Ops Agent
curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
sudo bash add-google-cloud-ops-agent-repo.sh --also-install
Hacer backup del config y configurar pipelines de Apache
sudo cp /etc/google-cloud-ops-agent/config.yaml /etc/google-cloud-ops-agent/config.yaml.bak
sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
metrics:
receivers:
apache:
type: apache
service:
pipelines:
apache:
receivers:
- apache
logging:
receivers:
apache_access:
type: apache_access
apache_error:
type: apache_error
service:
pipelines:
apache:
receivers:
- apache_access
- apache_error
EOF
Reiniciar el Ops Agent y verificar estado
sudo systemctl restart google-cloud-ops-agent
sudo systemctl status "google-cloud-ops-agent*"
Generar tráfico al servidor Apache
timeout 120 bash -c -- 'while true; do curl localhost; sleep $((RANDOM % 4)) ; done'
Ver el dashboard de Apache (Console)
Cloud Monitoring → Dashboards → Apache Overview — muestra métricas de tráfico, workers activos y requests por segundo exportadas por el Ops Agent.
Crear canal de notificación y alerting policy (Console)
- Monitoring → Alerting → Edit notification channels → agregar canal Email.
- Monitoring → Alerting → Create policy → métrica
workload.googleapis.com/apache.traffic, threshold > 4 KiB/s, duración 1 minuto, notificar al canal creado.