Deploy the Remote Monitoring solution accelerator locally - Visual Studio
This article shows you how to deploy the Remote Monitoring solution accelerator to your local machine for testing and development. You learn how to run the microservices in Visual Studio. A local microservices deployment uses the following cloud services: IoT Hub, Cosmos DB, Azure Streaming Analytics, and Azure Time Series Insights services in the cloud.
If you want to run the Remote Monitoring solution accelerator in Docker on your local machine, see Deploy the Remote Monitoring solution accelerator locally - Docker.
Prerequisites
To deploy the Azure services used by the Remote Monitoring solution accelerator, you need an active Azure subscription.
If you don’t have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.
Machine setup
To complete the local deployment, you need the following tools installed on your local development machine:
- Git
- Docker
- Visual Studio
- Nginx
- Node.js v8 - this software is a prerequisite for the PCS CLI that the scripts use to create Azure resources. Don't use Node.js v10.
Note
Visual Studio is available for Windows and Mac.
Download the source code
The Remote Monitoring source code repositories include the source code and the Docker configuration files you need to run the microservices Docker images.
To clone and create a local version of the repository, use your command-line environment to navigate to a suitable folder on your local machine. Then run one of the following sets of commands to clone either the .NET repository:
To download the latest version of the .NET microservice implementations, run:
git clone --recurse-submodules https://github.com/Azure/azure-iot-pcs-remote-monitoring-dotnet.git
# To retrieve the latest submodules, run the following command:
cd azure-iot-pcs-remote-monitoring-dotnet
git submodule foreach git pull origin master
Note
These commands download the source code for all the microservices in addition to the scripts you use to run the microservices locally. Although you don't need the source code to run the microservices in Docker, the source code is useful if you later plan to modify the solution accelerator and test your changes locally.
Deploy the Azure services
Although this article shows you how to run the microservices locally, they depend on Azure services running in the cloud. Use the following script to deploy the Azure services. The following script examples assume you're using the .NET repository on a Windows machine. If you're working in another environment, adjust the paths, file extensions, and path separators appropriately.
Create new Azure resources
If you've not yet created the required Azure resources, follow these steps:
In your command-line environment, navigate to the \services\scripts\local\launch folder in your cloned copy of the repository.
Run the following commands to install the pcs CLI tool and sign in to your Azure account:
npm install -g iot-solutions pcs login
Run the start.cmd script. The script prompts you for the following information:
A solution name.
The Azure subscription to use.
The location of the Azure datacenter to use.
The script creates resource group in Azure with your solution name. This resource group contains the Azure resources the solution accelerator uses. You can delete this resource group once you no longer need the corresponding resources.
The script also adds a set of environment variables with a prefix PCS to your local machine. These environment variables provide the details for Remote Monitoring to be able to read from an Azure Key Vault resource. This Key Vault resource is where Remote Monitoring will read its configuration values from.
Tip
When the script completes, it also saves the environment variables to a file called <your home folder>\.pcs\<solution name>.env. You can use them for future solution accelerator deployments. Note that any environment variables set on your local machine override values in the services\scripts\local\.env file when you run docker-compose.
Exit from your command-line environment.
Use existing Azure resources
If you've already created the required Azure resources, create the corresponding environment variables on your local machine. Set the environment variables for the following:
- PCS_KEYVAULT_NAME - Name of the Azure Key Vault resource
- PCS_AAD_APPID - The AAD application ID
- PCS_AAD_APPSECRET - The AAD application secret
Configuration values will be read from this Azure Key Vault resource. These environment variables may be saved in the <your home folder>\.pcs\<solution name>.env file from the deployment. Note that environment variables set on your local machine override values in the services\scripts\local\.env file when you run docker-compose.
Some of the configuration needed by the microservice is stored in an instance of Key Vault that was created on initial deployment. The corresponding variables in keyvault should be modified as needed.
Run the microservices
In this section, you run the Remote Monitoring microservices. You run the web UI natively, the Device Simulation service in Docker, and the microservices in Visual Studio.
Run the device simulation service
Open a new command prompt window to be sure that you have access to the environment variables set by the start.cmd script in the previous section.
Run the following command to launch the Docker container for the device simulation service. The service simulates devices for the remote monitoring solution.
<path_to_cloned_repository>\services\device-simulation\scripts\docker\run.cmd
Deploy all other microservices on local machine
The following steps show you how to run the Remote Monitoring microservices in Visual Studio:
- Launch Visual Studio.
- Open the remote-monitoring.sln solution in the services folder in your local copy of the repository.
- In Solution Explorer, right-click the solution and the click Properties.
- Select Common Properties > Startup Project.
- Select Multiple startup projects and set Action to Start for the following projects:
- WebService (asa-manager\WebService)
- WebService (auth\WebService)
- WebService (config\WebService)
- WebService (device-telemetry\WebService)
- WebService (iothub-manager\WebService)
- WebService (storage-adapter\WebService)
- Click OK to save your choices.
- Click Debug > Start Debugging to build and run the web services on the local machine.
Each web service opens a command prompt and web browser window. At the command prompt, you see output from the running service, and the browser window lets you monitor the status. Don't close the command prompts or web pages, this action stops the web service.
Start the Stream Analytics job
Follow these steps to start the Stream Analytics job:
- Navigate to the Azure portal.
- Navigate to the Resource group created for your solution. The name of the resource group is the name you chose for your solution when you ran the start.cmd script.
- Click the Stream Analytics job in the list of resources.
- On the Stream Analytics job overview page, click the Start button. Then click Start to start the job now.
Run the web UI
In this step, you start the web UI. Open a new command prompt window to be sure that you have access to the environment variables set by the start.cmd script. Navigate to the webui folder in your local copy of the repository and run the following commands:
npm install
npm start
When the start is complete, your browser displays the page http://localhost:3000/dashboard. The errors on this page are expected. To view the application without errors, complete the following step.
Configure and run NGINX
Set up a reverse proxy server to link the web application and microservices running on your local machine:
- Copy the nginx.conf file from the webui\scripts\localhost folder in your local copy of the repository to the nginx\conf install directory.
- Run nginx.
For more information about running nginx, see nginx for Windows.
Connect to the dashboard
To access the Remote Monitoring solution dashboard, navigate to http://localhost:9000 in your browser.
Clean up
To avoid unnecessary charges, when you've finished your testing remove the cloud services from your Azure subscription. To remove the services, navigate to the Azure portal and delete the resource group that the start.cmd script created.
You can also delete the local copy of the Remote Monitoring repository created when you cloned the source code from GitHub.
Next steps
Now that you've deployed the Remote Monitoring solution, the next step is to explore the capabilities of the solution dashboard.