Configure Prometheus with Basic Authentication in Microsoft Azure WebApp
Tags: azure, prometheus, monitoring, tutorial
Published: 2022-08-17 08:48:06

**Goal :**

- Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp.

**Pre-Requisite :** 

- [Deploying Prometheus Image to Azure Container Registry Using Azure CLI](https://dev.to/suryabhansv/deploying-prometheus-image-to-azure-container-registry-using-azure-cli-4b30)
- [Setup Prometheus in Microsoft Azure (WebApp) using Azure CLI](https://dev.to/suryabhansv/setup-prometheus-in-microsoft-azure-webapp-using-azure-cli-253m)



**Steps**

1. [Create a web.yml file (documentation)](https://prometheus.io/docs/guides/basic-auth/#creating-web-yml)

2. [You can also use bcrypt generators on the web](https://bcrypt-generator.com/)


![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6igdbp3vny3cxpdxz19x.png)
![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xvfbnzvnlqxn4m7mbcq.png)
![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lu2g6d02ylpghozgxim.png)

* ` web.yml (Upload this file in **suryasprometheus** Storage Account Share)`
```
basic_auth_users:
  suryauser: $2a$12$6g5f3MZriVtoOZ7GrCEwzuTBxnPQwHurpktXTXUu1neg/XZeHzipy
```

![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zkokz6nfoi3ggs6ipqm6.png)


* `Set an Startup Commmand for Prometheus WebApp which includes web.yml`
```
az webapp config set --name $WebAppName --resource-group $ResourceGroupName --startup-file `
"--config.file=/etc/prometheus/prometheus.yml --web.config.file=/etc/prometheus/web.yml --web.enable-lifecycle --storage.tsdb.retention.time=7d"
```

![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08cn8bxbdj3xnzyn68cx.png)

* `prometheus.yml (Upload this file in **suryasprometheus** Storage Account Share)`

```
# my global config
global:
  scrape_interval: 30s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 30s # Evaluate rules every 15 seconds. The default is every 1 minute.
  scrape_timeout: 30s #is set to the global default (10s).
  

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "Prometheus"
    static_configs:
      - targets: ["suryawaprometheus.azurewebsites.net"]
    basic_auth:
        username: suryauser
        password: suryapassword
```

![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vxxhheanye3fhp56buw.png)
![Configuration of Prometheus Basic Authentication in Microsoft Azure WebApp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9l4o1qm7ia9yq4pmr3s3.png)