  def GetCpuUsage(self,
    instance_ids: Optional[List[str]] = None,
    days: int = 7,
    aggregation_minutes: int = 60
    ) -> List[Dict[str, Any]]:
    """Returns CPU usage metrics for compute instances.

    By default returns hourly usage for the last seven days for all instances
    within a project.

    Args:
      instance_ids list[str]: Optional. A list of instance IDs to collect
        metrics for. When not provided will collect metrics for all instances
        in the project.
      days (int): Optional. The number of days to collect metrics for.
      aggregation_minutes (int): Optional. The minutes to aggregate on.

    Returns:
      List[Dict[str, Any]]: a list of CPU usage for each instance in the format
        [
          {
            'instance_name': str,
            'instance_id': str,
            'cpu_usage':
            [
              {
                'timestamp': str,
                'cpu_usage': float
              },
            ]
          },
        ]
    """
    service = self.GcmApi()
    gcm_timeseries_client = service.projects().timeSeries() # pylint: disable=no-member

    start_time = common.FormatRFC3339(
        datetime.datetime.utcnow() - datetime.timedelta(days=days))
    end_time = common.FormatRFC3339(datetime.datetime.utcnow())
    period = aggregation_minutes * 60
    instance_filter = self._BuildUsageFilter(
      'compute.googleapis.com/instance/cpu/utilization', instance_ids)

    responses = common.ExecuteRequest(gcm_timeseries_client, 'list', {
        'name': 'projects/{0:s}'.format(self.project_id),
        'filter': instance_filter,
        'interval_startTime': start_time,
        'interval_endTime': end_time,
        'view': 'FULL',
        'aggregation_perSeriesAligner': 'ALIGN_MEAN',
        'aggregation_alignmentPeriod': '{0:d}s'.format(period),
    })

    cpu_usage_instances = []

    for response in responses:
      time_series = response.get('timeSeries', [])
      for ts in time_series:
        instance_name = ts['metric']['labels']['instance_name']
        instance_id = ts['resource']['labels']['instance_id']
        points = ts['points']
        cpu_usage = []
        for point in points:
          cpu_usage.append({
              'timestamp': point['interval']['startTime'],
              'cpu_usage': point['value']['doubleValue']})

        cpu_usage_instances.append({
            'instance_name': instance_name,
            'instance_id': instance_id,
            'cpu_usage': cpu_usage})

    return cpu_usage_instances
Returns CPU usage metrics for compute instances.

By default returns hourly usage for the last seven days for all instances
within a project.

Args:
instance_ids list[str]: Optional. A list of instance IDs to collect
metrics for. When not provided will collect metrics for all instances
in the project.
days (int): Optional. The number of days to collect metrics for.
aggregation_minutes (int): Optional. The minutes to aggregate on.

Returns:
List[Dict[str, Any]]: a list of CPU usage for each instance in the format
[
{
'instance_name': str,
'instance_id': str,
'cpu_usage':
[
{
'timestamp': str,
'cpu_usage': float
},
]
},
]
libcloudforensics/providers/gcp/internal/monitoring.py