createScraper method

Future<CreateScraperResponse> createScraper({
  1. required Destination destination,
  2. required ScrapeConfiguration scrapeConfiguration,
  3. required Source source,
  4. String? alias,
  5. String? clientToken,
  6. List<ExporterConfiguration>? exporters,
  7. RoleConfiguration? roleConfiguration,
  8. Map<String, String>? tags,
})

Creates a scraper to collect metrics from Prometheus-compatible sources. The scraper sends the collected metrics to Amazon Managed Service for Prometheus workspaces or CloudWatch datasets. You can configure scrapers to collect metrics from Amazon EKS clusters, Amazon MSK clusters, or from VPC-based sources that support DNS-based service discovery. Scrapers are flexible. You can configure a scraper to control which metrics to collect, the frequency of collection, which transformations to apply to the metrics, and more.

An IAM role will be created for you that Amazon Managed Service for Prometheus uses to access the metrics in your source. You must configure this role with a policy that allows it to scrape metrics from your source. For Amazon EKS sources, see Configuring your Amazon EKS cluster in the Amazon Managed Service for Prometheus User Guide.

The scrapeConfiguration parameter contains the base-64 encoded YAML configuration for the scraper.

When creating a scraper, the service creates a Network Interface in each Availability Zone that are passed into CreateScraper through subnets. These network interfaces are used to connect to your source within the VPC for scraping metrics.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter destination : The destination where the scraper sends the collected metrics. Valid destinations are Amazon Managed Service for Prometheus workspaces and CloudWatch datasets.

Parameter scrapeConfiguration : The configuration file to use in the new scraper. For more information, see Scraper configuration in the Amazon Managed Service for Prometheus User Guide.

Parameter source : The Amazon EKS or Amazon Web Services cluster from which the scraper will collect metrics.

Parameter alias : (optional) An alias to associate with the scraper. This is for your use, and does not need to be unique.

Parameter clientToken : (Optional) A unique, case-sensitive identifier that you can provide to ensure the idempotency of the request.

Parameter exporters : The exporter configurations for the scraper. You can configure at most one Amazon OpenSearch Service domain. If you don't specify a value, the scraper is created without an exporter configuration.

Parameter roleConfiguration : Use this structure to enable cross-account access, so that you can use a target account to access Prometheus metrics from source accounts.

Parameter tags : (Optional) The list of tag keys and values to associate with the scraper.

Implementation

Future<CreateScraperResponse> createScraper({
  required Destination destination,
  required ScrapeConfiguration scrapeConfiguration,
  required Source source,
  String? alias,
  String? clientToken,
  List<ExporterConfiguration>? exporters,
  RoleConfiguration? roleConfiguration,
  Map<String, String>? tags,
}) async {
  final $payload = <String, dynamic>{
    'destination': destination,
    'scrapeConfiguration': scrapeConfiguration,
    'source': source,
    if (alias != null) 'alias': alias,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (exporters != null) 'exporters': exporters,
    if (roleConfiguration != null) 'roleConfiguration': roleConfiguration,
    if (tags != null) 'tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/scrapers',
    exceptionFnMap: _exceptionFns,
  );
  return CreateScraperResponse.fromJson(response);
}