Reputation: 731
I am trying to retrieve Instance Id & Process Id of an Azure WebJob.As highlighted in below snapshot, I want to retrieve the running InstanceId.
Also I want retrieve the ProcessId of WebJob. Using C# code is it possible to retrieve both values?
Thank you for help in advance.
Upvotes: 7
Views: 5434
Reputation: 1038
Each web app's instance will have its own instance id. It will save as an environment variable in its Web app server.
To get the current WebJobs instance id, use environment-variable(WEBSITE_INSTANCE_ID).
The instance id represents the VM that the site is running on (If site runs on multiple instances, each instance will have a different id)
You could refer to below code for more details:
public static void ProcessQueueMessage([QueueTrigger("queue3")] string thumbnail, TextWriter log)
{
string instanceid = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
log.Write( "Current instance ID : " + instanceid);
}
For more details and example to get ProcessId and InstanceId, refer to this blogpost.
As Kenneth LeFebvre mentioned, you can also use Kudu Console “Environment” tab to check the Instance and Process ID’s.
Upvotes: 2
Reputation: 407
The environment variable, "WEBSITE_INSTANCE_ID" contains the instance id. In your screenshot, the string "e582f3" is an abbreviation of the full id.
[09/08/2017 21:00:53 > be313b: INFO] [21:00:45 INF] Instance: RD00155DF9356E (be313b15729ccddadf6ea48a522d9456e23cc0abf82e5180e3997118fae84fe3)
This is a log entry I wrote that printed out the environment variable "COMPUTERNAME" and "WEBSITE_INSTANCE_ID". You can see that be313b is really the first six digits of the full id be313b15729ccddadf6ea48a522d9456e23cc0abf82e5180e3997118fae84fe3.
If you want to see all the variables available to you, go to your Kudu console and click on "Environment": https://your-appservice.scm.azurewebsites.net/Env.cshtml
For the Process Id, I presume you can just call Process.GetCurrentProcess().Id
like you would anywhere else.
I hope that's helpful!
Upvotes: 4