Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

The LogicMonitor Python Data library

This Python Library is suitable for ingesting the metrics into the LogicMonitor Platform

Documentation Status PyPI - Version PyPI - Downloads

Overview

LogicMonitor's Push Metrics feature allows you to send metrics directly to the LogicMonitor platform via a dedicated API, removing the need to route the data through a LogicMonitor Collector. Once ingested, these metrics are presented alongside all other metrics gathered via LogicMonitor, providing a single pane of glass for metric monitoring and alerting.

Requirements.

Python 2.7 and 3.4+

Documentation

https://logicmonitor-data-sdk-py.readthedocs.io/en/latest/

Getting Started

Please install using pip and then run below a working example for submitting the disk metrics to your LM account. This script will monitor the Usage, Free and Total of the disk at every 10 sec interval.

    import logging
    import os
    import sys
    import time
    
    import psutil as psutil
    
    import logicmonitor_data_sdk
    from logicmonitor_data_sdk.api.response_interface import ResonseInterface
    from logicmonitor_data_sdk.models import Resource, DataSource, DataPoint, \
      DataSourceInstance
    
    from logicmonitor_data_sdk.api.metrics import Metrics
    
    logger = logging.getLogger('lmdata.api')
    logger.setLevel(logging.INFO)
    
    configuration = logicmonitor_data_sdk.Configuration()
    # For debug log, set the value to True
    configuration.debug = True
    
    
    class MyResponse(ResonseInterface):
      """
      Sample callback to handle the response from the REST endpoints
      """
    
      def success_callback(self, request, response, status, request_id):
        logger.info("%s: %s: %s", response, status, request_id)
    
      def error_callback(self, request, response, status, request_id, reason):
        logger.error("%s: %s: %s %s", response, status, reason, request_id)
    
    
    def MetricRequest():
      """
      Main function to get the CPU values using `psutil` and send to Metrics REST endpoint
      """
      device_name = os.uname()[1]
      resource = Resource(ids={'system.displayname': device_name}, name=device_name,
                          create=True)
      datasource = DataSource(name="DiskUsingSDK")
      datapoints = ['total', 'used', 'free']
      metric_api = Metrics(batch=True, interval=30, response_callback=MyResponse())
      while True:
        partitions = psutil.disk_partitions()
        for p in partitions:
          instance_name = p.device
          usage = psutil.disk_usage(instance_name)._asdict()
          # Create the instance object for every device. Name should not have the
          # special characters so replacing it with the '-'.
          instance = DataSourceInstance(name=instance_name.replace('/', '-'),
                                        display_name=instance_name)
          for one_datapoint in datapoints:
            datapoint = DataPoint(name=one_datapoint)
            values = {str(int(time.time())): str(usage[one_datapoint])}
            metric_api.send_metrics(resource=resource,
                                    datasource=datasource,
                                    instance=instance,
                                    datapoint=datapoint,
                                    values=values)
        time.sleep(5)
    
    
    if __name__ == "__main__":
      MetricRequest()

Then run the program as:

    pip install psutil
    LM_COMPANY=<ACOUNT_NAME> LM_ACCESS_ID=<ID> LM_ACCESS_KEY='<KEY>' python disk_metrics.py

Get in Touch

If you have questions in general, reach out to our support


Copyright, 2021, LogicMonitor, Inc.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Release files for logicmonitor-data-sdk 0.0.9b3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logicmonitor-data-sdk 0.0.9b3
File Size Uploaded
logicmonitor_data_sdk-0.0.9b3.tar.gz 51.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logicmonitor-data-sdk 0.0.9b3
File Interpreter ABI Platform
logicmonitor_data_sdk-0.0.9b3-py3-none-any.whl Python 3 none any Details

Total release size: 137.4 kB

Release files / logicmonitor_data_sdk-0.0.9b3.tar.gz

Download URL logicmonitor_data_sdk-0.0.9b3.tar.gz
Size 51.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0e26841bf29e402af29c0ce122aae185a7fe2837906678168215d666f012c69d
BLAKE2b-256 checksum
How to use checksums
f1477cc8ca6f4acf604c94d23d1d487c7fe724025e190486fe55b0657a36ae81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / logicmonitor_data_sdk-0.0.9b3-py3-none-any.whl

Download URL logicmonitor_data_sdk-0.0.9b3-py3-none-any.whl
Size 85.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eed75ae59173c29ad31d75b2bddc1770c889eee981f233abaf423d8bcc2528c8
BLAKE2b-256 checksum
How to use checksums
560778ce36a7d612284b3869bbf1907edf3e4ec39e7ca41df3f89b56e1983a3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page