Forum Discussion

AdamB's avatar
2 years ago

Data for groovy script in complex datapoint

Hi

I have a question regarding using data in complex datapoint.
Long story short - I need to use base-10 logarithm for some calculation - in complex datapoint I can use only log function so my idea is to use groovy script and then I can use Math.log10

DS is using SCRIPT for discovery method and another groovy script is collecting attributes/data.
I would like to use data which is displayed in Normal datapoints (##WILDVALUE##.something).

Is there any smart way to process/get that data in complex datapoint groovy script ? (without pooling device again as it is already done in "Collector Attributes")

8 Replies

  • I don’t think so. I think you’d have to pull the normal datapoints into your script, perform the same math again, then you’d have the value available to use in the rest of the script. 

    My theory is that the groovy complex datapoints are calculated in the same stage as the rest of the complex datapoints. Meaning, the complex datapoint values haven’t been calculated by the time the groovy complex datapoint would need them.

  • Thanks Stuart - now at least I know in which direction should I go 😄

  • Hi Stuart Weenig,

    Can you please guide me, how to pull the historical data to create Complex data point using Groovy Script.

    For Examples:  I have a Datapoint X. I want to create a complex data point, which capture the MAX(X) from last 24 Hours. Please Guide me how to proceed.

    Thanks

  • Hi ,

    Groovy Script For Complex DataPoint 

    import com.santaba.agent.groovyapi.api.DataCollectionAPI

    def dataPointName = "Running"
    def day = System.currentTimeMillis() - 1 * 24 * 60 * 60 * 1000
    def historicalData = DataCollectionAPI.getHistoricalData(dataPointName,day, System.currentTimeMillis())
    def maxRunningWithinWeek = historicalData.max()

    return maxRunningWithinWeek

  • I’m trying to get this working in powershell right now as well… limited success so far.

  • Thanks Stuart - now at least I know in which direction should I go 😄

    Looking at this again, remember that the output of your collection script is available to your complex groovy-based datapoint. So, you could get all the values of any of the normal datapoints just by inspecting/parsing the output you’re already generating. No need to poll the device again.

  • Hi ,

    Groovy Script For Complex DataPoint 

    import com.santaba.agent.groovyapi.api.DataCollectionAPI

    def dataPointName = "Running"
    def day = System.currentTimeMillis() - 1 * 24 * 60 * 60 * 1000
    def historicalData = DataCollectionAPI.getHistoricalData(dataPointName,day, System.currentTimeMillis())
    def maxRunningWithinWeek = historicalData.max()

    return maxRunningWithinWeek

    You could use collector script caching to remember the previous week’s values. Add the current value to that list, find the max and output it. Given the number of poll cycles in a week, you’d size your list accordingly so when you add a new point if the total size of the list is more than a week, you’d just drop the oldest value.