Getting the max value of the day from the datapoint in table widget for capacity planning

Recommended Posts

Hi, I am trying the display max value of the day (last 24 hours) from the datapoints in a table widget in the dashboard, but its showing current datapoint value. Is there any method to achieve this? Like to understand any other widget display max value of the day in dashboard.

Share this post

Link to post
Share on other sites

You can grab historical data for an dataSource instance using the REST API.  Once you've got the time range you want to evaluate, finding the Max should be relatively simple.  Let me fish up a thread with how to grab those counters for you...

I found my thread for tokenizing the return using powershell, but apparently, didn't include the data grab portion of the code in the thread :(



Share this post

Link to post
Share on other sites

Thanks Cole, I am trying to collect these max values of datapoints from linux host, could you please share groovy script or any alternative method if you have any to achieve this.

Share this post

Link to post
Share on other sites
#!!! Requires Credential Manager 2.0 from the repository !!!#

Import-Module     CredentialManager

function          Send-Request               {
    param (
        $accessid    = $null,
        $accesskey   = $null,
        $URL                ,
        $data        = $null,
        $version     = '2'  ,
        $httpVerb    = "GET"

    if ( $accessId -eq $null) {
        $accessId    = $cred.UserName
        $accessKey   = $cred.GetNetworkCredential().Password

    <# Use TLS 1.2 #>
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    <# Get current time in milliseconds #>
    $epoch           = [Math]::Round(
        ( New-TimeSpan `
            -start (Get-Date -Date "1/1/1970") `
            -end (Get-Date).ToUniversalTime()).TotalMilliseconds

    <# Concatenate Request Details #>
    $requestVars     = $httpVerb + $epoch + $data + $resourcePath

    <# Construct Signature #>
    $hmac            = New-Object System.Security.Cryptography.HMACSHA256
    $hmac.Key        = [Text.Encoding]::UTF8.GetBytes( $accessKey )
    $signatureBytes  = $hmac.ComputeHash( [Text.Encoding]::UTF8.GetBytes( $requestVars ) )
    $signatureHex    = [System.BitConverter]::ToString( $signatureBytes ) -replace '-'
    $signature       = [System.Convert]::ToBase64String( [System.Text.Encoding]::UTF8.GetBytes( $signatureHex.ToLower() ) )

    <# Construct Headers #>
    $auth            = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch
    $headers         = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add(      "Authorization", $auth              )
    $headers.Add(      "Content-Type" , 'application/json' )

    # uses version 2 of the API
    $headers.Add(      "X-version"    , $version           )

    <# Make Request #>
    $response        = Invoke-RestMethod `
        -Uri           $URL      `
        -Method        $httpVerb `
        -Body          $data     `
        -Header        $headers

    $result          = $response

    Return $result
function          Get-LMRestAPIObjectListing {
    param (
        $URLBase          ,
        $resourcePathRoot , # "/device/devices"
        $size = 1000      ,
        $accessKey        ,

    $output  = @()
    $looping = $true
    $counter = 0

    while ($looping) {
        #re-calc offset based on iteration
        $offset = ($counter * $size) + 1

        $resourcePath    = $resourcePathRoot
        $queryParam      = "?size=$size&offset=$offset"
        $url             = $URLBase + $resourcePath + $queryParam

        # Make Request
        $response        = Send-Request `
            -accesskey    $accessKey    `
            -accessid     $accessId     `
            -URL          $url

        if ( $response.items.count -eq $size ) {
            # Return set is full, more items to retrieve
            $output     += $response.items

        } elseif ( $response.items.count -gt 0 ) {
            # Return set is not full, store date, end loop
            $output     += $response.items
            $looping     = $false

        } else {
            # Return set is empty, no data to store, end loop
            $looping     = $false


    write-output $output

#!!! Change to your company name !!!#
$company        = "yourCompanyHere"
$URLBase        = "https://$company.logicmonitor.com/santaba/rest"

# This will resolve to proper values if it's being run from inside LM
$accessID       = "##Logicmonitor.AccessID.key##"
$accessKey      = "##Logicmonitor.AccessKey.key##"

if ( $accessID -like "##*" )       {
    # Not being run from inside LM - populate manually for testing
    Import-Module     CredentialManager

    $Cred       = Get-StoredCredential -Target LogicMonitor
    $accessID   = $cred.UserName
    $accessKey  = $Cred.GetNetworkCredential().Password

#!!! Populate the pertinent ID numbers from the "Info" section of the LM objects
$deviceNumber     = 123
$dataSourceNumber = 456
$instanceNumber   = 789

#region Get collectors
$resourcePath   = "/device/devices/$deviceNumber/devicedatasources/$datasourceNumber/instances/$instanceNumber/data"

$response       = Get-LMRestAPIObjectListing `
    -resourcePathRoot $resourcePath          `
    -accessKey        $accessKey             `
    -accessId         $accessID              `
    -URLBase          $URLBase

To find the ID Numbers, you can build out the $resourcePath for the last few bits until you come across the pieces you need.  I develop in PowerShell ISE to allow me to explore the date more easily once I've populated it.

Share this post

Link to post
Share on other sites

So... I'm on windows, your response came in as I was getting all of that code in there :)  It'll be functionally similar for Linux.  Not sure if it will work, but you may be able to install the Powershell core on your Linux collector to see if that will work there. (Free from Microsoft: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6 )

(I don't know Groovy Script yet :) )

Edited by Cole McDonald

Share this post

Link to post
Share on other sites

While not in a table but if it helps you can use the Gauge widget to show the current value and also show a Peak value for a particular period, including 24 hours.



  • Upvote 2

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.