|
|
|
@ -736,6 +736,83 @@ export class CloudWatchDatasource |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async metricFindQuery(query: string) { |
|
|
|
|
let region; |
|
|
|
|
let namespace; |
|
|
|
|
let metricName; |
|
|
|
|
let filterJson; |
|
|
|
|
|
|
|
|
|
const regionQuery = query.match(/^regions\(\)/); |
|
|
|
|
if (regionQuery) { |
|
|
|
|
return this.getRegions(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const namespaceQuery = query.match(/^namespaces\(\)/); |
|
|
|
|
if (namespaceQuery) { |
|
|
|
|
return this.getNamespaces(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const metricNameQuery = query.match(/^metrics\(([^\)]+?)(,\s?([^,]+?))?\)/); |
|
|
|
|
if (metricNameQuery) { |
|
|
|
|
namespace = metricNameQuery[1]; |
|
|
|
|
region = metricNameQuery[3]; |
|
|
|
|
return this.getMetrics(namespace, region); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)(,\s?([^,]+?))?\)/); |
|
|
|
|
if (dimensionKeysQuery) { |
|
|
|
|
namespace = dimensionKeysQuery[1]; |
|
|
|
|
region = dimensionKeysQuery[3]; |
|
|
|
|
return this.getDimensionKeys(namespace, region); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dimensionValuesQuery = query.match( |
|
|
|
|
/^dimension_values\(([^,]+?),\s?([^,]+?),\s?([^,]+?),\s?([^,]+?)(,\s?(.+))?\)/ |
|
|
|
|
); |
|
|
|
|
if (dimensionValuesQuery) { |
|
|
|
|
region = dimensionValuesQuery[1]; |
|
|
|
|
namespace = dimensionValuesQuery[2]; |
|
|
|
|
metricName = dimensionValuesQuery[3]; |
|
|
|
|
const dimensionKey = dimensionValuesQuery[4]; |
|
|
|
|
filterJson = {}; |
|
|
|
|
if (dimensionValuesQuery[6]) { |
|
|
|
|
filterJson = JSON.parse(this.templateSrv.replace(dimensionValuesQuery[6])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.getDimensionValues(region, namespace, metricName, dimensionKey, filterJson); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ebsVolumeIdsQuery = query.match(/^ebs_volume_ids\(([^,]+?),\s?([^,]+?)\)/); |
|
|
|
|
if (ebsVolumeIdsQuery) { |
|
|
|
|
region = ebsVolumeIdsQuery[1]; |
|
|
|
|
const instanceId = ebsVolumeIdsQuery[2]; |
|
|
|
|
return this.getEbsVolumeIds(region, instanceId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ec2InstanceAttributeQuery = query.match(/^ec2_instance_attribute\(([^,]+?),\s?([^,]+?),\s?(.+?)\)/); |
|
|
|
|
if (ec2InstanceAttributeQuery) { |
|
|
|
|
region = ec2InstanceAttributeQuery[1]; |
|
|
|
|
const targetAttributeName = ec2InstanceAttributeQuery[2]; |
|
|
|
|
filterJson = JSON.parse(this.templateSrv.replace(ec2InstanceAttributeQuery[3])); |
|
|
|
|
return this.getEc2InstanceAttribute(region, targetAttributeName, filterJson); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const resourceARNsQuery = query.match(/^resource_arns\(([^,]+?),\s?([^,]+?),\s?(.+?)\)/); |
|
|
|
|
if (resourceARNsQuery) { |
|
|
|
|
region = resourceARNsQuery[1]; |
|
|
|
|
const resourceType = resourceARNsQuery[2]; |
|
|
|
|
const tagsJSON = JSON.parse(this.templateSrv.replace(resourceARNsQuery[3])); |
|
|
|
|
return this.getResourceARNs(region, resourceType, tagsJSON); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const statsQuery = query.match(/^statistics\(\)/); |
|
|
|
|
if (statsQuery) { |
|
|
|
|
return this.standardStatistics.map((s: string) => ({ value: s, label: s, text: s })); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Promise.resolve([]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
annotationQuery(options: any) { |
|
|
|
|
const annotation = options.annotation; |
|
|
|
|
const statistic = this.templateSrv.replace(annotation.statistic); |
|
|
|
|