Exporting Data From a VMware vSphere Environment For Fun And Profit

In this post we will see how we can export data from a VMware vSphere environment from the command-line and then plot some nice graphs of it, because everybody loves graphs, right? :)

For exporting of data from a VMware vSphere environment we are going to use vPoller - VMware vSphere Distributed Pollers and for plotting of the graphs we will be using matplotlib.

For installation and configuration of vPoller please refer to the vPoller Github repository which contains all the details you need in order to get vPoller installed and configured.

So, without further ado let's start with the interesting stuff.

Using vPoller we can export data in various formats using the vPoller Helpers. Example of such a helper is the vpoller.helpers.csvhelper which returns data in CSV format, which makes it easy for us to then use that data for plotting graphs.

Let's first check the overall CPU usage of our ESXi hosts from our vSphere environment:

  1. $ vpoller-client -m host.discover -p summary.quickStats.overallCpuUsage -V vc01.example.org
  2. {
  3.     "msg": "Successfully discovered objects",
  4.     "result": [
  5.         {
  6.             "summary.quickStats.overallCpuUsage": 7065,
  7.             "name": "esx-1"
  8.         },
  9.         {
  10.             "summary.quickStats.overallCpuUsage": 12383
  11.             "name": "esx-2"
  12.         },
  13.         {
  14.             "summary.quickStats.overallCpuUsage": 3945,
  15.             "name": "esx-3"
  16.         },
  17.         {
  18.             "summary.quickStats.overallCpuUsage": 4776,
  19.             "name": "esx-4"
  20.                 },
  21.         {
  22.             "summary.quickStats.overallCpuUsage": 4638,
  23.             "name": "esx-5"
  24.                 },
  25.         {
  26.             "summary.quickStats.overallCpuUsage": 8520,
  27.             "name": "esx-6"
  28.                 },
  29.         {
  30.             "summary.quickStats.overallCpuUsage": 10001,
  31.             "name": "esx-7"
  32.                 },
  33.         {
  34.             "summary.quickStats.overallCpuUsage": 2481,
  35.             "name": "esx-8"
  36.         },
  37.         {
  38.             "summary.quickStats.overallCpuUsage": 5064,
  39.             "name": "esx-9"
  40.         },
  41.     ],
  42.     "success": 0
  43. }

The result returned by default from vPoller is in JSON format. In order to convert this result to CSV we will use the vpoller.helpers.csvhelper helper. Let's do that now:

  1. $ vpoller-client -H vpoller.helpers.csvhelper -m host.discover -p summary.quickStats.overallCpuUsage -V vc01.example.org
  2. name,summary.quickStats.overallCpuUsage
  3. esx-1,7065
  4. esx-2,12383
  5. esx-3,3945
  6. esx-4,4776
  7. esx-5,4638
  8. esx-6,8520
  9. esx-7,10001
  10. esx-8,2481
  11. esx-9,5064

We would also want to save this data in a file somewhere, so later we can use it to plot our graph of overall CPU usage.

  1. $ vpoller-client -H vpoller.helpers.csvhelper -m host.discover -p summary.quickStats.overallCpuUsage -V vc01.example.org > hosts-cpu-usage.csv

Great, we've just exported the overall CPU usage of our ESXi hosts, but that is just some raw data.

The following script uses matplotlib in order to plot the graph for us.

  1. #!/usr/bin/env python