Send data to an Azure Monitor workspace from your Prometheus server
Azure Red Hat OpenShift is preinstalled with a default Prometheus server. As detailed in the Azure Red Hat OpenShift support policy, this default Prometheus server shouldn't be removed.
In some scenarios, you might want to centralize data from self-managed Prometheus clusters for long-term data retention to create a centralized view across your clusters. You can use Azure Monitor managed service for Prometheus to collect and analyze metrics at scale by using a Prometheus-compatible monitoring solution that's based on the Prometheus project from the Cloud Native Computing Foundation. You can use remote write to send data from Prometheus servers in your cluster to the Azure managed service.
Prerequisites
To send data from a Prometheus server by using remote write, you need:
- An Azure Monitor workspace. If you don't already have a workspace, you must create a new workspace.
Register an application with Microsoft Entra ID
Complete the steps to register an application with Microsoft Entra ID and create a service principal.
Copy the tenant ID and client ID of the service principal:
- In the Microsoft Entra admin center, go to Identity > Applications > App registrations, and then select your application.
- Go to the Overview page for the app.
- Copy and retain the Directory (tenant) ID value.
- Copy and retain the Application (client) ID value.
Create a new client secret. Copy and retain the value of the secret.
In your application code, set the values of the tenant ID, client ID, and client secret that you copied:
export TENANT_ID=<tenant-id> export CLIENT_ID=<client-id> export CLIENT_SECRET=<client-secret>
Assign the Monitoring Metrics Publisher role to the application
The application must have the Monitoring Metrics Publisher role for the data collection rule that is associated with your Azure Monitor workspace.
In the Azure portal, go to the instance of Azure Monitor for your subscription.
On the resource menu, select Data Collection Rules.
Select the data collection rule that is associated with your Azure Monitor workspace.
On the Overview page for the data collection rule, select Access control (IAM).
Select Add, and then select Add role assignment.
Select the Monitoring Metrics Publisher role, and then select Next.
Select User, group, or service principal, and then choose Select members. Select the application that you registered, and then choose Select.
To complete the role assignment, select Review + assign.
Create a secret in your Azure Red Hat OpenShift cluster
To authenticate by using a remote write endpoint, you use the OAuth 2.0 authentication method from the supported remote write authentication settings.
To begin, create a secret by using the client ID and client secret:
cat << EOF | oc apply -f -
apiVersion: v1
kind: Secret
metadata:
name: oauth2-credentials
namespace: openshift-monitoring
stringData:
id: "${CLIENT_ID}"
secret: "${CLIENT_SECRET}"
EOF
Set up remote write
To set up remote write for the default platform monitoring, update the cluster-monitoring-config config map YAML file in the openshift-monitoring namespace.
Open the config map file for editing:
oc edit -n openshift-monitoring cm cluster-monitoring-config
data: config.yaml: | prometheusK8s: remoteWrite: - url: "<INGESTION-URL>" oauth2: clientId: secret: name: oauth2-credentials key: id clientSecret: name: oauth2-credentials key: secret tokenUrl: "https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token" scopes: - "https://monitor.azure.com/.default"
Update the config map file:
Replace
INGESTION-URL
in the config map file with the value for Metrics ingestion endpoint from the Overview page for the Azure Monitor workspace.Replace
TENANT_ID
in the config map file with the tenant ID of the service principal.
Visualize metrics by using Azure Managed Grafana
You can use community Grafana dashboards to visualize the captured metrics, or you can create contextual dashboards.
Create an Azure Managed Grafana workspace.
Link the Azure Managed Grafana workspace to your Azure Monitor workspace.
Import the community Grafana dashboard Openshift/K8 Cluster Overview (ID 3870) to the Grafana workspace.
For the data source, use your Azure Monitor workspace.
Save the dashboard.
To access the dashboard, in your Azure Managed Grafana workspace, go to Home > Dashboards, and then select the dashboard.
Troubleshoot
For troubleshooting information, see Azure Monitor managed service for Prometheus remote write.