In a GCP project with Vertex AI endpoints already deployed, I want to know if the monitoring is enabled with the google-cloud-aiplatform library.
How can I do it ?
For more context, I ran following commands:
Command Line Interface
gcloud config set project <my_GCP_project_id>
gcloud config set billing/quota_project <my_GCP_project_id>
gcloud auth login
gcloud auth application-default login
Python
from google.cloud import aiplatform
PROJECT_ID = <my_GCP_project_id>
LOCATION_ID = <my_GCP_location_id>
aiplatform.init(
project = PROJECT_ID,
location = LOCATION_ID,
)
last_endpoint = aiplatform.Endpoint.list(order_by="update_time desc")[0]
No choice but to look for a a ModelDeploymentMonitoringJob
(see Python documentation here) linked to this endpoint.
from google.cloud import aiplatform
def check_if_endpoint_monitoring_is_enabled(my_endpoint: aiplatform.Endpoint) -> bool:
"""True/False a monitoring job has been deployed on the endpoint.
"""
aiplatform.init(project=my_endpoint.project, location=my_endpoint.location)
for monitoring_job in aiplatform.ModelDeploymentMonitoringJob.list():
if my_endpoint.resource_name == monitoring_job.to_dict()['endpoint']:
return True
return False
# ENDPOINT_ID: Endpoint identifier as string (quotes required)
target_endpoint = aiplatform.Endpoint(ENDPOINT_ID)
print(f"Monitoring activated for {target_endpoint.display_name}: {check_if_endpoint_monitoring_is_enabled((target_endpoint)}.")