Prometheus メトリックを複数の Azure Monitor ワークスペースに送信する
追加のデータ収集規則を作成することで、より多くの Azure Monitor ワークスペースにさまざまなメトリックをルーティングできます。
対応するデータ収集エンドポイントと共にデータ収集規則を作成し、同じ Kubernetes クラスターからさまざまなメトリックを追加の Azure Monitor ワークスペースに送信できます。 現在、これは Resource Manager テンプレートを使ってオンボードすることによってのみ利用できます。 通常のオンボード プロセスに従った後、同じ Resource Manager テンプレートを編集して、別の Azure Monitor ワークスペース用の DCR と DCE を追加できます。 テンプレートを編集して、新しい Azure Monitor ワークスペースごとにパラメーターを追加し、新しい Azure Monitor ワークスペースごとに別の DCR を追加して、別の DCE を追加し、新しい Azure Monitor ワークスペースに監視閲覧者ロールを追加して、Grafana 用に新しい Azure Monitor ワークスペース統合を追加する必要があります。
次のパラメーターを追加します:
"parameters": { "azureMonitorWorkspaceResourceId2": { "type": "string" }, "azureMonitorWorkspaceLocation2": { "type": "string", "defaultValue": "", "allowedValues": [ "eastus2euap", "centraluseuap", "centralus", "eastus", "eastus2", "northeurope", "southcentralus", "southeastasia", "uksouth", "westeurope", "westus", "westus2" ] }, ... }
さらにデータ収集エンドポイントを追加します。
<dceName>
を置き換える "必要があります"。{ "type": "Microsoft.Insights/dataCollectionEndpoints", "apiVersion": "2021-09-01-preview", "name": "[variables('dceName')]", "location": "[parameters('azureMonitorWorkspaceLocation2')]", "kind": "Linux", "properties": {} }
新しいデータ収集エンドポイントで新しい DCR を追加します。
<dcrName>
を置き換える "必要があります"。{ "type": "Microsoft.Insights/dataCollectionRules", "apiVersion": "2021-09-01-preview", "name": "<dcrName>", "location": "[parameters('azureMonitorWorkspaceLocation2')]", "kind": "Linux", "properties": { "dataCollectionEndpointId": "[resourceId('Microsoft.Insights/dataCollectionEndpoints/', variables('dceName'))]", "dataFlows": [ { "destinations": ["MonitoringAccount2"], "streams": ["Microsoft-PrometheusMetrics"] } ], "dataSources": { "prometheusForwarder": [ { "name": "PrometheusDataSource", "streams": ["Microsoft-PrometheusMetrics"], "labelIncludeFilter": "microsoft_metrics_include_label": "MonitoringAccountLabel2" } ] }, "description": "DCR for Azure Monitor Metrics Profile (Managed Prometheus)", "destinations": { "monitoringAccounts": [ { "accountResourceId": "[parameters('azureMonitorWorkspaceResourceId2')]", "name": "MonitoringAccount2" } ] } }, "dependsOn": [ "[resourceId('Microsoft.Insights/dataCollectionEndpoints/', variables('dceName'))]" ] }
関連するデータ収集ルール (DCR) を使用して、さらにデータ収集ルールの関連付け (DCRA) を追加します。 これにより、DCR がクラスターに関連付けられます。
<dcraName>
を置き換える必要があります。{ "type": "Microsoft.Resources/deployments", "name": "<dcraName>", "apiVersion": "2017-05-10", "subscriptionId": "[variables('clusterSubscriptionId')]", "resourceGroup": "[variables('clusterResourceGroup')]", "dependsOn": [ "[resourceId('Microsoft.Insights/dataCollectionEndpoints/', variables('dceName'))]", "[resourceId('Microsoft.Insights/dataCollectionRules', variables('dcrName'))]" ], "properties": { "mode": "Incremental", "template": { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": {}, "variables": {}, "resources": [ { "type": "Microsoft.ContainerService/managedClusters/providers/dataCollectionRuleAssociations", "name": "[concat(variables('clusterName'),'/microsoft.insights/', variables('dcraName'))]", "apiVersion": "2021-09-01-preview", "location": "[parameters('clusterLocation')]", "properties": { "description": "Association of data collection rule. Deleting this association will break the data collection for this AKS Cluster.", "dataCollectionRuleId": "[resourceId('Microsoft.Insights/dataCollectionRules', variables('dcrName'))]" } } ] }, "parameters": {} } }
新しい Grafana 統合を追加します。
{ "type": "Microsoft.Dashboard/grafana", "apiVersion": "2022-08-01", "name": "[split(parameters('grafanaResourceId'),'/')[8]]", "sku": { "name": "[parameters('grafanaSku')]" }, "location": "[parameters('grafanaLocation')]", "properties": { "grafanaIntegrations": { "azureMonitorWorkspaceIntegrations": [ // Existing azureMonitorWorkspaceIntegrations values (if any) // { // "azureMonitorWorkspaceResourceId": "<value>" // }, // { // "azureMonitorWorkspaceResourceId": "<value>" // }, { "azureMonitorWorkspaceResourceId": "[parameters('azureMonitorWorkspaceResourceId')]" }, { "azureMonitorWorkspaceResourceId": "[parameters('azureMonitorWorkspaceResourceId2')]" } ] } } }
- 新しい Azure Monitor ワークスペースからデータを読み取る
Monitoring Data Reader
ロールを割り当てます。
{ "type": "Microsoft.Authorization/roleAssignments", "apiVersion": "2022-04-01", "name": "[parameters('roleNameGuid')]", "scope": "[parameters('azureMonitorWorkspaceResourceId2')]", "properties": { "roleDefinitionId": "[concat('/subscriptions/', variables('clusterSubscriptionId'), '/providers/Microsoft.Authorization/roleDefinitions/', 'b0d8363b-8ddd-447d-831f-62ca05bff136')]", "principalId": "[reference(resourceId('Microsoft.Dashboard/grafana', split(parameters('grafanaResourceId'),'/')[8]), '2022-08-01', 'Full').identity.principalId]" } }
- 新しい Azure Monitor ワークスペースからデータを読み取る
次に、事前に定義しておいたラベル microsoft_metrics_account
をメトリックに追加し、メトリックがルーティングされるワークスペースを構成します。 その値は、そのワークスペースに対する DCR の対応する microsoft_metrics_include_label
と同じにする必要があります。 メトリックにラベルを追加するには、スクレイピングの構成で relabel_configs
を利用できます。1 つのジョブからのすべてのメトリックを特定のワークスペースに送信するには、次のラベル変更構成を追加します。
relabel_configs:
- source_labels: [__address__]
target_label: microsoft_metrics_account
action: replace
replacement: "MonitoringAccountLabel2"
ソース ラベルは __address__
であり、このラベルは常に存在するため、このラベル変更構成は常に適用されます。 ターゲット ラベルは常に microsoft_metrics_account
であり、その値をワークスペースの対応するラベル値に置き換える必要があります。
例
3 つの異なるジョブがメトリックを 3 つの異なるワークスペースに送信するように構成する場合は、各データ収集規則に次を含めます。
"labelIncludeFilter": {
"microsoft_metrics_include_label": "MonitoringAccountLabel1"
}
"labelIncludeFilter": {
"microsoft_metrics_include_label": "MonitoringAccountLabel2"
}
"labelIncludeFilter": {
"microsoft_metrics_include_label": "MonitoringAccountLabel3"
}
次に、スクレイピングの構成に、それぞれと同じラベル値を含めます。
scrape_configs:
- job_name: prometheus_ref_app_1
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
action: keep
regex: "prometheus-reference-app-1"
- source_labels: [__address__]
target_label: microsoft_metrics_account
action: replace
replacement: "MonitoringAccountLabel1"
- job_name: prometheus_ref_app_2
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
action: keep
regex: "prometheus-reference-app-2"
- source_labels: [__address__]
target_label: microsoft_metrics_account
action: replace
replacement: "MonitoringAccountLabel2"
- job_name: prometheus_ref_app_3
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
action: keep
regex: "prometheus-reference-app-3"
- source_labels: [__address__]
target_label: microsoft_metrics_account
action: replace
replacement: "MonitoringAccountLabel3"