Forum Discussion

Brandon's avatar
5 years ago

Datasource for API Gateway Resources behind a stage

I have been using a custom datasource to collect the metrics for each resource and method (excluding OPTIONS) behind a API Gateway stage.  It has been extremely useful in our production environments.  I would share the datasource via the Exchange, but the discovery method I'm using will not be universal, so I think it would be best if that discovery were to work natively.  If possible, could we please have a discovery method for AWS API Gateway Resources by Stage?  

*Something to note - This has the potential to discover quite a few resources and thus, create a substantial number of cloudwatch calls which might hit customer billing.  For this reason, I added a custom property ##APIGW.stages## so that I could plug in the specific stages I wish to monitor instead of having each one automatically discovered.  The Applies To looks like this:

system.cloud.category == "AWS/APIGateway" && apigw.stages

Autodiscovery is currently written in PowerShell (hence why not everyone can take advantage of it)

$apigwID = '##system.aws.resourceid##';
$region = '##system.aws.region##'
$stages = '##APIGW.Stages##';

$resources = Get-AGResourceList -RestApiId $apigwID -region $region

$stages.split(' ') | %{
    $stage = $_
    $resources | %{
        if($_.ResourceMethods) {
            $path = $_.Path
            $_.ResourceMethods.Keys | where{$_ -notmatch 'OPTIONS'} | %{
                $wildvalue = "Stage=$stage>Resource=$Path>Method=$_"
                Write-Host "$wildvalue##${Stage}: $_ $Path######auto.stage=$stage"
            }
        }
    }
}

 

1 Reply

Replies have been turned off for this discussion
  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Hey @Brandon thanks for posting! We can definitely get an official cloud AD method into the queue (and we'll make sure AD filters are included so discovery can be limited to specific stages)