Skip to content

idrop/cloudwatch-metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Concourse CloudWatch Metrics Resource

Concourse resource for placing an AWS CloudWatch metric.

Example use:

record the rate that scheduled jobs fail, so that alerts can be raised

The resource is a wrapper around the AWS CLI for CloudWatch put-metric-data.

Source Configuration

  • namespace: Required
    Namespace under which to put the metric. Should not start with AWS/.
  • metric: Required
    The name of the metric to put.
  • aws_access_key_id: Optional
    The AWS access key to use when putting the metric.
  • aws_secret_access_key: Optional
    The AWS secret key to use when putting the metric.
  • aws_region: Optional
    The AWS region for the credentials.

AWS credentials and region configuration above are optional, and override a Concourse instance using AWS credentials from IAM instance profiles.

The AWS credentials used should have the Cloudwatch_PutMetricData policy attached.

Behaviour

check: not implemented


in: not implemented


out: Put a metric to CloudWatch

Put a single metric to CloudWatch, on the given namespace, metric name and dimensions.

Parameters

All params are optional.

  • dimensions: Optional
    up to seven key-value pairs to set as dimensions. The dimensions of resource metadata BUILD_JOB_NAME, BUILD_PIPELINE_NAME and BUILD_TEAM_NAME are always set as dimensions.
  • value: Optional
    double to place as a metric, typically 1 or 0. Default 1.
  • unit: Optional
    unit to assign to the value. Default None.

Example Configuration

Resource Type

resource_types:
  - name: cloudwatch-metrics
    type: docker-image
    source:
      repository: ghcr.io/idrop/cloudwatch-metrics/cloudwatch-metrics
      tag: 0.2

Resource

resources:
  - name: smoketest-fails
    type: cloudwatch-metrics
    source:
      aws_region: eu-west-2
      aws_access_key_id: ((aws_access_key_id))
      aws_secret_access_key: ((aws_secret_access_key))
      namespace: SmokeTest
      metric: Failure

Plan

jobs:
  - name: smoketest-prod
    plan:
      ........
    on_failure:
      put: smoketest-fails

If the smoketest-prod job fails, the CloudWatch metric Failure would be put on namespace SmokeTest with value 1 and a timestamp of now.

The dimensions set on the metric, given a concourse team named main, pipeline named test-pipeline and job of smoketest-prod, would be:

  • build_team_name: main
  • build_pipeline_name: test-pipeline
  • build_job_name: smoketest-prod

Testing

Create an AWS access key and secret, and attach a Cloudwatch_PutMetricData policy.

Start up the Concourse services locally using the quick-start.

Then set the test pipeline with:

fly set-pipeline -t main -p test -c test/test-pipeline.yaml -v aws_access_key_id=<your aws access key> -v aws_secret_access_key=<your access key secret>

Now run the some-test job, which should fail and send a metric to AWS CloudWatch.