0

I started working with Azure batch recently and found I could not get statistics for a given job although fields for that exists.

I am using the Python API, when I poll for job information the stats field is always None. The JobListOptions class can be used with the job.list method but documentation is not very useful.

Going through the BatchExplorer sample code I found out that the expand field of the JobListOptions class might require to be set to stats but I'm still unsure as I'm still not getting stats from the Python API.

Rastikan
  • 517
  • 5
  • 18

2 Answers2

3

You can get stats from jobs as follows:

my_batch_client.job.list(
    job_list_options=azure.batch.models.JobListOptions(
        expand='stats'
    )
)

Note that it's more efficient to get a job rather than list all of your jobs if you're just interested in a single job. In that case use my_batch_client.job.get() with the appropriate JobGetOptions.

Or for all tasks under a job:

my_batch_client.task.list(
    job_id='MY_JOB_ID',
    task_list_options=azure.batch.models.TaskListOptions(
        expand='stats'
    )
)

Similarly, if you are only interested in a single task under a job, query just that task as it's more efficient:

my_batch_client.task.get(
    job_id='MY_JOB_ID',
    task_id='MY_TASK_ID',
    task_get_options=azure.batch.models.TaskGetOptions(
        expand='stats'
    )
)
fpark
  • 2,304
  • 2
  • 14
  • 21
0

It sounds like you want to get the resource usage statistics for the entire lifetime of jobs & tasks of Azure Batch using Azure Python SDK, so first you need to turn on diagnostics to collect the ServiceLog logs as the figure below.

enter image description here

Then you can get these statistics stats from the response of the methods batch_client.job.get(JOB_ID) & batch_client.task.get(JOB_ID, TASK_ID).

Peter Pan
  • 23,476
  • 4
  • 25
  • 43