Extracting datapoints via API
Hi all
I wonder if anyone else has found a good way to pull metric data out of LM into other systems? I've been having a play and have something working. My code is doing this:
- Query the API for any devices where auto.wmi.operational=true
- loop through the devices and for each:
- make an API call to get the datasource id for "WinVolumeUsage" under this device
- make an API call to get the instances under this datasource
- loop through all the instances found
- make an API call to get the datapoints for each instance for the last few hours
- write that data out to an object so it can be later written to another database
It does work, but it's fairly slow (a few seconds per device) as it's having to make multiple API calls for every server it finds.
I had a look at using a report to do this, but it seems reports have a 500 row limit and the dataset I'm looking for is more like tens of thousands. I'm also not sure if I could pull report data through the API.
Anyway doing this kind of thing successfully?
thanks
Dave
Using a report worked for me. I create 3 different Resource Metric Trend reports for CPU, RAM, disk utilisation. Scheduled them to run daily to generate a CSV report. I've got about 600 servers in there at the moment, so was a few thousand rows in the Volumes report, which seems to run fine as a scheduled report and only seems to take a minute or two to run.
I have my script call the /report/links/{reportId} endpoint, then download the most recent CSV and process that data. This is far quicker than iterating through all the API calls needed to gather the data.
The most granular you can go is 2 hours of data, so I'm able to get the average for each data point over the 2 hours before the report was run.
Report frequency is 1 day at the most, but I found that I could reschedule the report from the API as well. So, if I have the script run just after the report, it could get the average for the last 2 hours then the script can reschedule the report to run again in 2 hours.