DEV Community

Cover image for Setup Prometheus in Microsoft Azure (WebApp) using Azure CLI
Suryabhan Singh Vaghela
Suryabhan Singh Vaghela

Posted on • Edited on

Setup Prometheus in Microsoft Azure (WebApp) using Azure CLI

Goal :

  • Create Prometheus WebApp in Microsoft Azure using Azure CLI

Pre-Requisite :

Resource will Create :

  • App Service plan
  • Storage account
  • App Service

Script



$ResourceGroupName      = "suryarg"
$LocationName           = "eastus2"
$ACRName                = "suryacr"
$ACRUrl                 = "$ACRName.azurecr.io"

$AppServicePlan         = "suryaasp"
$AppServicePlanSku      = "S1"
$StorageAccountName     = "suryastorageaccountsa"
$StorageAccountSku      = "Standard_ZRS"
$StorageAccountShare    = "suryasprometheus"
$WebAppName             = "suryawaprometheus"


Enter fullscreen mode Exit fullscreen mode


#Create App Service Plan
az appservice plan create --resource-group $ResourceGroupName --name $AppServicePlan --is-linux --sku $AppServicePlanSku    

#Create a Storage Account
az storage account create --resource-group $ResourceGroupName --name $StorageAccountName --kind StorageV2 --sku $StorageAccountSku

#Create an Storage Account File Share
az storage share-rm create --resource-group $ResourceGroupName --storage-account $StorageAccountName --name $StorageAccountShare --access-tier "TransactionOptimized" --quota 64

#Create an Webapp for Prometheus
az webapp create --resource-group $ResourceGroupName --name $WebAppName --plan $AppServicePlan -i "$ACRUrl/prometheus:SuryaLatest"


Enter fullscreen mode Exit fullscreen mode


#Create Storage Mount for Prometheus WebApp
$storageaccountkey  =   $(az storage account keys list --resource-group $ResourceGroupName --account-name $StorageAccountName --query [0].value -o tsv)

az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "prometheus" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/etc/prometheus"
az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "prometheus_data" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/prometheus"


Enter fullscreen mode Exit fullscreen mode


#Set an Environment Variable for Prometheus WebApp
az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings WEBSITES_PORT=9090

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


* 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"]
```
![Prometheus.yml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cfym9ubbzkd5jhq3ddf.png)
![Prometheus.yml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fd9k16rxaj83mcobx1yn.png)
![Prometheus.yml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6hhcqxco3kg3w9p24e7.png)


> * [Example file prometheus.yml (Documentation)](https://github.com/prometheus/prometheus/blob/release-2.37/config/testdata/conf.good.yml)


**Output :**


![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zrajylthrpjypngversf.png)
![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ueh6ia1ke8f8wui79r9.png)
![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8xgql6h4waak8atd1nu.png)
![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abnllfmsxcbwc0l4y9lp.png)
![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fdjj66l1tsfovg95wj0.png)
![Prometheus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/033ig1ll3bgxwlkw8rpb.png)

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
chethankumblekar profile image
Chethan K

nice, if any of the people tried it and faced issue if the application didn't came up then just remove the port 9090 from appsettings