Get Graph Data

Last updated on 27 September, 2022

Overview

You can use LogicMonitor’s REST API to get graph data, either in a numerical data format or in image format. There are three types of graph data you can request:

  • Instance-level graph data
  • Widget data
  • Service graph data

As with all of our API calls, authentication is required.

Get Instance-Level Graph Data

HTTP Method: GET

Resource URIs:

/device/devices/{deviceID}/devicedatasources/{deviceDataSourceID}/instances/{instanceID}/graphs/{graphID}/data
/device/devicedatasourceinstances/{instanceID}/graphs/{graphID}/data
/device/devicedatasources/{deviceDataSourceID}/groups/{instanceGroupId}/graphs/{overviewGraphID}/data

(Where deviceID is the ID of the device you’d like data for, which you can get from the device resource; deviceDataSourceID is the ID of the device datasource you’d like data for, which you can get from the datasources resource; and Instance ID is the ID of the instance you’d like data for, which you can get from the instance resource; instanceGroupID is the instance group for which you’d like to get overview graph data for, and you can get instance group information from the instance groups resource; graphID is the ID of the particular instance graph you’d like data for, and you can get all graph information for a particular DataSource from the datasources resource; overviewGraphID is the ID of the particular overview graph you’d like data for, and you can get all graph information for a particular DataSource from the DataSources resource.)

Request Parameters: By default, data will be returned for the configured graph time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image | csv – Whether returned data is formatted as number values (data = json) or an image No – defaults to data
width The width of the image, in pixels, if format=image No
height The height of the image, in pixels, if format=image No
start The start time for returned data, in epoch seconds No – defaults to the selected graph time range
end The end time for returned data, in epoch seconds No – defaults to the selected graph time range

Examples

Example: Get Data from Graph

The following Python script gets data from 1482865561 to 1482865719 for graph 253, associated with instance 26657295, datasource 6842, device 258:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/258/devicedatasources/6842/instances/26657295/graphs/253/data'
queryParams ='?start=1482865561&end=1482865719'
data = ''

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3

Example: Save Image File

The following Python script saves an image file ‘instanceGraph.png’ for graph 4825, associated with device DataSource instance 420576596:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devicedatasourceinstances/420576596/graphs/4825/data'
queryParams = '?format=image'
data =''

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.get(url, data=data, headers=headers)

#Print status and write image data to a png file
print('Response Status:',response.status_code)
file_ = open('instanceGraph.png', 'wb')
file_.write(response.content)
file_.close()
Python 3

Get Widget Data

Note: This data resource doesn’t work for text, HTML and flash widgets. For widgets without time series data, like the map widget and the alert widget, data will be returned based on what is displayed in the widget (locations, matching alerts) independent of time. For widgets with time series data, like the custom graph widget and the device graph widget, data will be returned based on the time range configured or specified in the request.

HTTP Method: GET

Resource URI: /dashboard/widgets/{widgetID}/data
(Where widgetID is the id of the widget you’d like to get data for. You can get widgetID from the widgets resource.)

Request Parameters: By default, data will be returned for the configured widget time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image – Whether returned data is formatted as number values or an image No – defaults to data
start The start time for returned data, in epoch seconds No – defaults to the selected widget time range
end The end time for returned data, in epoch seconds No – defaults to the selected widget time range

Example

The following Python script gets data from 1482865561 to 1482865719 for widget 362:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/dashboard/widgets/362/data'
queryParams ='?start=1482865561&end=1482865719'
data = ''

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3

Get Service Graph Data

HTTP Method: GET

Resource URI: /service/services/{serviceID}/checkpoints/{checkpointID}/graphs/{graphName}/data
(Where serviceID is the service you’d like to get data for; you can get serviceID from the services resource. CheckpointID is the ID of the service checkpoint you’d like data for; you can get checkpointIDs by making a GET request to get details for a particular service. graphName is the graph you’d like data for, where possible values are status, performance (only for individual checkpoints) and responsetime.)

Request Parameters: By default, data will be returned for the configured graph time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image – Whether returned data is formatted as number values or an image No – defaults to data
start The start time for returned data, in epoch seconds No – defaults to the selected graph time range
end The end time for returned data, in epoch seconds No – defaults to the selected graph time range

Example

The following Python script requests performance graph data from 1482865561 to 1482865719 for service 58, checkpoint 294:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/service/services/58/checkpoints/294/graphs/performance/data'
queryParams ='?start=1482865561&end=1482865719'
data = ''

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3
In This Article