There is only one python file for this project - main-py.py The objective is to read the measurements from desired tests running in Thousand Eyes, and export them to Prometheus in a format that it understands.
This project does not show how the output file that contains all the measurements fetched at a given time, is exposed to prometheus on HTTP
There are two sections in this code -
- Fetching Data from Thousand Eyes
- Exporting this Data to Prometheus Format
- Read all the tests in Thousand Eyes
- Filter the tests based on some criteria. In this project, the criteria is to look at the test name and look for "GIS" as first three characters.
- Store the test IDs of these filtered tests
- Get the measurements of each test based on the test ID stored from Step-3
- Store all the measurements in a python dictionary. Later save this in a pickle file (just for troubleshooting purpose).
We chose "Guage" metric type for our use case. (Explore other metric types from https://prometheus.io/docs/concepts/metric_types/)
- Define the labels we want to use for each measurement.
- Add data to the labels for each measurement. This is not the measurement data. This is meta data that helps you in designing good queries.
- Add measurement data to each measurement.
- Export this in a format that Prometheus understands.
- Save this exported huge text string (that's what it really is) to a file
This code also implements a simple python logger that logs all the export times to a simple file - main-py.log
Let me know if any part is unclear in this code.