How to programmatically collect metric values from vROps

Purpose:

Few customers inquired about how they can collect metric values directly from vROps. They majorly wanted to get that information using REST API's. I wrote another blog post detailing how you can do it. I wrote a python script to automatically collect metric values from vROps. This post provides details about that script. Where you can get that script and how it needs to be run.

Introduction:

This python script uses the vROps python client to query and gather information directly from vROps server. Its task is to collect metric values from vROps. It uses REST API's at the backend to get the information. So, to run the script you to download and install Python Client from vROps server. Also, this script was written and tested in Python 2.7 environment. Check my other blog post on details about how you can use python client to interact with vROps server.

Use Case:

This script will automate the task of collecting metric values directly from vROps for you. You can later use the values as per your requirements.

Where to get it?

You can get the script by going to GitHub page (https://github.com/sajaldebnath/vrops-metric-collection)and downloading it from there.

There are samples provided in the script.

How to run?

There are two scripts, "metric-collection.py" and set-config.py. Download both the scripts in the same location. Run set-config.py first.

# python <localtion to file>/set-config.py

It will set the environment. Then run metric-collection.py to collect the metric values.

# python <localtion to file>/metric-collection.py

Ideally, you should automate the run of this script using a scheduler like cron jobs. Script should not run less than 5 minutes apart. Since vROps collects data every 5 minutes, so running this script less than that time frame will result in redundant data. In this mode "Maximum number of samples to collect" parameter should be left to default value 1.

If you want to run the script one time and get as much data as possible (historical), then set the above parameter to the desired value. For example, setting it to 5 will result in getting data from last 5 collections.

How does it collect metric values:

Running set-config.py sets up the environment. It will ask for the following information:

  • Adapter Kind
  • Resource Kind
  • vROPs server IP/FQDN
  • user id
  • vROps password
  • Maximum number of samples to collect
  • Number of Keys to Monitor
  • Keys (one by one)

The adapter kind is the adapter for which you want information (e.g, VMware). The resource kind is the type of resource you want to monitor (e.g., VirtualMachine). These two parameters are used to filter the results.

vROps server and user details are asked to connect to the server. "Maximum number of samples to collect" value is used to determine how many samples we need to collect data for. By default, it is set to 1. Next is the number of keys to monitor. As the name suggests, this determines the number of keys. The last parameter "Keys" takes the key values one by one.

Running the set-config.py script stores these values in JSON format in config.json file. This file is placed in the same directory. Note, the password is not saved as plain text, it is saved in encrypted. I agree, probably it is not the best encryption, but at least better than plain text password.

Next run metric-collection.py, this script will read the values from config.json file and save the output in JSON format in metric-data.json file. This file is also saved in the same location.

Watch the following video for the detailed run and sample output.

Conclusion:

You can use the script if you want to get the metric values directly from vROps server. I did not test the script extensively. It will be a real help if you can test it out and let me know the outcome. Also, any further suggestions are welcome. I hope this helps you as it helped me.