Skip to content

Commit 287d062

Browse files
committed
add resourceType as convenience parameter
Signed-off-by: Markus Blaschke <[email protected]>
1 parent e6c57fc commit 287d062

File tree

2 files changed

+89
-40
lines changed

2 files changed

+89
-40
lines changed

README.md

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -293,47 +293,47 @@ azurerm_ratelimit{scope="subscription",subscriptionID="...",type="read"} 11999
293293

294294
HINT: service discovery information is cached for duration set by `$AZURE_SERVICEDISCOVERY_CACHE` (set to `0` to disable)
295295

296-
| GET parameter | Default | Required | Multiple | Description |
297-
|------------------------|---------------------------|----------|----------|----------------------------------------------------------------------|
298-
| `subscription` | | **yes** | **yes** | Azure Subscription ID (or multiple separate by comma) |
299-
| `filter` | | **yes** | no | Azure Resource filter (https://docs.microsoft.com/en-us/rest/api/resources/resources/list) |
300-
| `resourceSubPath` | | no | no | Additional resource path which will be appended to Resource ID |
301-
| `timespan` | `PT1M` | no | no | Metric timespan |
302-
| `interval` | | no | no | Metric timespan |
303-
| `metricNamespace` | | no | **yes** | Metric namespace (might need also `resourceSubPath`) |
304-
| `metric` | | no | **yes** | Metric name |
305-
| `aggregation` | | no | **yes** | Metric aggregation (`minimum`, `maximum`, `average`, `total`, `count`, multiple possible separated with `,`) |
306-
| `name` | `azurerm_resource_metric` | no | no | Prometheus metric name |
307-
| `metricFilter` | | no | no | Prometheus metric filter (dimension support) |
308-
| `metricTop` | | no | no | Prometheus metric dimension count (dimension support) |
309-
| `metricOrderBy` | | no | no | Prometheus metric order by (dimension support) |
310-
| `cache` | (same as timespan) | no | no | Use of internal metrics caching |
311-
| `template` | set to `$METRIC_TEMPLATE` | no | no | see [metric name template system](#metric-name-template-system) |
296+
| GET parameter | Default | Required | Multiple | Description |
297+
|----------------------------|---------------------------|----------|----------|----------------------------------------------------------------------|
298+
| `subscription` | | **yes** | **yes** | Azure Subscription ID (or multiple separate by comma) |
299+
| `resourceType` or `filter` | | **yes** | no | Azure Resource type or filter query (https://docs.microsoft.com/en-us/rest/api/resources/resources/list) |
300+
| `resourceSubPath` | | no | no | Additional resource path which will be appended to Resource ID |
301+
| `timespan` | `PT1M` | no | no | Metric timespan |
302+
| `interval` | | no | no | Metric timespan |
303+
| `metricNamespace` | | no | **yes** | Metric namespace (might need also `resourceSubPath`) |
304+
| `metric` | | no | **yes** | Metric name |
305+
| `aggregation` | | no | **yes** | Metric aggregation (`minimum`, `maximum`, `average`, `total`, `count`, multiple possible separated with `,`) |
306+
| `name` | `azurerm_resource_metric` | no | no | Prometheus metric name |
307+
| `metricFilter` | | no | no | Prometheus metric filter (dimension support) |
308+
| `metricTop` | | no | no | Prometheus metric dimension count (dimension support) |
309+
| `metricOrderBy` | | no | no | Prometheus metric order by (dimension support) |
310+
| `cache` | (same as timespan) | no | no | Use of internal metrics caching |
311+
| `template` | set to `$METRIC_TEMPLATE` | no | no | see [metric name template system](#metric-name-template-system) |
312312

313313
*Hint: Multiple values can be specified multiple times or with a comma in a single value.*
314314

315315
### /probe/metrics/scrape parameters
316316

317317
HINT: service discovery information is cached for duration set by `$AZURE_SERVICEDISCOVERY_CACHE` (set to `0` to disable)
318318

319-
| GET parameter | Default | Required | Multiple | Description |
320-
|------------------------|---------------------------|----------|----------|----------------------------------------------------------------------|
321-
| `subscription` | | **yes** | **yes** | Azure Subscription ID (or multiple separate by comma) |
322-
| `filter` | | **yes** | no | Azure Resource filter (https://docs.microsoft.com/en-us/rest/api/resources/resources/list) |
323-
| `resourceSubPath` | | no | no | Additional resource path which will be appended to Resource ID |
324-
| `metricTagName` | | **yes** | no | Resource tag name for getting "metrics" list |
325-
| `aggregationTagName` | | **yes** | no | Resource tag name for getting "aggregations" list |
326-
| `timespan` | `PT1M` | no | no | Metric timespan |
327-
| `interval` | | no | no | Metric timespan |
328-
| `metricNamespace` | | no | **yes** | Metric namespace (might need also `resourceSubPath`) |
329-
| `metric` | | no | **yes** | Metric name |
330-
| `aggregation` | | no | **yes** | Metric aggregation (`minimum`, `maximum`, `average`, `total`, multiple possible separated with `,`) |
331-
| `name` | `azurerm_resource_metric` | no | no | Prometheus metric name |
332-
| `metricFilter` | | no | no | Prometheus metric filter (dimension support) |
333-
| `metricTop` | | no | no | Prometheus metric dimension count (integer, dimension support) |
334-
| `metricOrderBy` | | no | no | Prometheus metric order by (dimension support) |
335-
| `cache` | (same as timespan) | no | no | Use of internal metrics caching |
336-
| `template` | set to `$METRIC_TEMPLATE` | no | no | see [metric name template system](#metric-name-template-system) |
319+
| GET parameter | Default | Required | Multiple | Description |
320+
|----------------------------|---------------------------|----------|----------|----------------------------------------------------------------------|
321+
| `subscription` | | **yes** | **yes** | Azure Subscription ID (or multiple separate by comma) |
322+
| `resourceType` or `filter` | | **yes** | no | Azure Resource type or filter query (https://docs.microsoft.com/en-us/rest/api/resources/resources/list) |
323+
| `resourceSubPath` | | no | no | Additional resource path which will be appended to Resource ID |
324+
| `metricTagName` | | **yes** | no | Resource tag name for getting "metrics" list |
325+
| `aggregationTagName` | | **yes** | no | Resource tag name for getting "aggregations" list |
326+
| `timespan` | `PT1M` | no | no | Metric timespan |
327+
| `interval` | | no | no | Metric timespan |
328+
| `metricNamespace` | | no | **yes** | Metric namespace (might need also `resourceSubPath`) |
329+
| `metric` | | no | **yes** | Metric name |
330+
| `aggregation` | | no | **yes** | Metric aggregation (`minimum`, `maximum`, `average`, `total`, multiple possible separated with `,`) |
331+
| `name` | `azurerm_resource_metric` | no | no | Prometheus metric name |
332+
| `metricFilter` | | no | no | Prometheus metric filter (dimension support) |
333+
| `metricTop` | | no | no | Prometheus metric dimension count (integer, dimension support) |
334+
| `metricOrderBy` | | no | no | Prometheus metric order by (dimension support) |
335+
| `cache` | (same as timespan) | no | no | Use of internal metrics caching |
336+
| `template` | set to `$METRIC_TEMPLATE` | no | no | see [metric name template system](#metric-name-template-system) |
337337

338338
*Hint: Multiple values can be specified multiple times or with a comma in a single value.*
339339

@@ -394,7 +394,7 @@ using ServiceDiscovery:
394394
name: ["my_own_metric_name"]
395395
subscription:
396396
- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
397-
filter: ["resourceType eq 'Microsoft.Cache/Redis'"]
397+
resourceType: ["Microsoft.Cache/Redis"]
398398
metric:
399399
- connectedclients
400400
- totalcommandsprocessed
@@ -424,6 +424,44 @@ using ServiceDiscovery:
424424
- targets: ["azure-metrics:8080"]
425425
```
426426
427+
using ServiceDiscovery with custom resource filter query:
428+
```yaml
429+
- job_name: azure-metrics-redis
430+
scrape_interval: 1m
431+
metrics_path: /probe/metrics/list
432+
params:
433+
name: ["my_own_metric_name"]
434+
subscription:
435+
- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
436+
filter: ["resourceType eq 'Microsoft.Cache/Redis'"]
437+
metric:
438+
- connectedclients
439+
- totalcommandsprocessed
440+
- cachehits
441+
- cachemisses
442+
- getcommands
443+
- setcommands
444+
- operationsPerSecond
445+
- evictedkeys
446+
- totalkeys
447+
- expiredkeys
448+
- usedmemory
449+
- usedmemorypercentage
450+
- usedmemoryRss
451+
- serverLoad
452+
- cacheWrite
453+
- cacheRead
454+
- percentProcessorTime
455+
- cacheLatency
456+
- errors
457+
interval: ["PT1M"]
458+
timespan: ["PT1M"]
459+
aggregation:
460+
- average
461+
- total
462+
static_configs:
463+
- targets: ["azure-metrics:8080"]
464+
```
427465
### VirtualNetworkGateways
428466
429467
```yaml
@@ -434,7 +472,7 @@ using ServiceDiscovery:
434472
name: ["my_own_metric_name"]
435473
subscription:
436474
- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
437-
filter: ["resourceType eq 'Microsoft.Network/virtualNetworkGateways'"]
475+
resourceType: ["Microsoft.Network/virtualNetworkGateways"]
438476
metric:
439477
- AverageBandwidth
440478
- P2SBandwidth
@@ -466,7 +504,7 @@ Virtual Gateway connection metrics (dimension support)
466504
name: ["my_own_metric_name"]
467505
subscription:
468506
- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
469-
filter: ["resourceType eq 'Microsoft.Network/virtualNetworkGateways'"]
507+
resourceType: ["Microsoft.Network/virtualNetworkGateways"]
470508
metric:
471509
- TunnelAverageBandwidth
472510
- TunnelEgressBytes
@@ -498,7 +536,7 @@ Virtual Gateway connection metrics (dimension support)
498536
name: ["my_own_metric_name"]
499537
subscription:
500538
- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
501-
filter: ["resourceType eq 'Microsoft.Storage/storageAccounts'"]
539+
resourceType: ["Microsoft.Storage/storageAccounts"]
502540
resourceSubPath: ["blobServices/default"] # will be appened to resource ID
503541
metricNamespace: ["Microsoft.Storage/storageAccounts/blobServices"]
504542
metric:

metrics/settings.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,23 @@ func NewRequestMetricSettings(r *http.Request, opts config.Opts) (RequestMetricS
6565
)
6666

6767
// param filter
68-
if filter, err := paramsGetRequired(params, "filter"); err == nil {
68+
resourceType := paramsGetWithDefault(params, "resourceType", "")
69+
filter := paramsGetWithDefault(params, "filter", "")
70+
71+
if resourceType != "" && filter != "" {
72+
return ret, fmt.Errorf("parameter \"resourceType\" and \"filter\" are mutually exclusive")
73+
} else if resourceType != "" {
74+
ret.Filter = fmt.Sprintf(
75+
"resourceType eq '%s'",
76+
strings.ReplaceAll(resourceType, "'", "\\'"),
77+
)
78+
} else if filter != "" {
6979
ret.Filter = filter
7080
} else {
71-
return ret, err
81+
return ret, fmt.Errorf("parameter \"resourceType\" or \"filter\" is missing")
7282
}
7383

84+
fmt.Println(ret.Filter )
7485
// param timespan
7586
ret.Timespan = paramsGetWithDefault(params, "timespan", "PT1M")
7687

0 commit comments

Comments
 (0)