{"id":18811720,"url":"https://github.com/logicmonitor/logicmonitor_data_sdk_py","last_synced_at":"2025-04-13T20:31:37.560Z","repository":{"id":37861701,"uuid":"334093730","full_name":"logicmonitor/logicmonitor_data_sdk_py","owner":"logicmonitor","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-27T07:18:58.000Z","size":174,"stargazers_count":2,"open_issues_count":3,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-30T12:51:19.679Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logicmonitor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-01-29T09:16:53.000Z","updated_at":"2024-07-31T05:55:53.000Z","dependencies_parsed_at":"2024-01-03T12:26:29.910Z","dependency_job_id":"c935ed85-3028-485f-ad68-d5ecb756e30d","html_url":"https://github.com/logicmonitor/logicmonitor_data_sdk_py","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flogicmonitor_data_sdk_py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flogicmonitor_data_sdk_py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flogicmonitor_data_sdk_py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flogicmonitor_data_sdk_py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logicmonitor","download_url":"https://codeload.github.com/logicmonitor/logicmonitor_data_sdk_py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223604530,"owners_count":17172314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:27:25.531Z","updated_at":"2024-11-07T23:27:26.137Z","avatar_url":"https://github.com/logicmonitor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The LogicMonitor Python Data library\nThis Python Library is suitable for ingesting the metrics into the LogicMonitor Platform\n\n[![Documentation Status](https://readthedocs.org/projects/logicmonitor-data-sdk-py/badge/?version=latest)](https://logicmonitor-data-sdk-py.readthedocs.io/en/latest/?badge=latest)\n[![PyPI - Version](https://img.shields.io/pypi/v/logicmonitor-data-sdk.svg)](https://pypi.org/project/logicmonitor-data-sdk)\n[![PyPI - Downloads](https://pepy.tech/badge/logicmonitor-data-sdk)](https://pepy.tech/project/logicmonitor-data-sdk)\n\n\n- Library Documentation: https://logicmonitor-data-sdk-py.readthedocs.io/en/latest/\n- LogicMonitor: https://LogicMonitor.com\n\nOverview\n--------\n\nLogicMonitor's Push Metrics feature allows you to send metrics directly\nto the LogicMonitor platform via a dedicated API, removing the need to\nroute the data through a LogicMonitor Collector. Once ingested, these\nmetrics are presented alongside all other metrics gathered via\nLogicMonitor, providing a single pane of glass for metric monitoring and\nalerting.\n\nRequirements.\n------------\n\nPython 2.7 and 3.4+\n\nDocumentation\n-------------\nhttps://logicmonitor-data-sdk-py.readthedocs.io/en/latest/\n\n\nGetting Started\n---------------\n\nPlease install using pip and then run below a working example for submitting the disk metrics to \nyour LM account. This script will monitor the Usage, Free and Total of the disk at every 10 sec \ninterval.\n\n```python\n    import logging\n    import os\n    import sys\n    import time\n    \n    import psutil as psutil\n    \n    import logicmonitor_data_sdk\n    from logicmonitor_data_sdk.api.response_interface import ResonseInterface\n    from logicmonitor_data_sdk.models import Resource, DataSource, DataPoint, \\\n      DataSourceInstance\n    \n    from logicmonitor_data_sdk.api.metrics import Metrics\n    \n    logger = logging.getLogger('lmdata.api')\n    logger.setLevel(logging.INFO)\n    \n    configuration = logicmonitor_data_sdk.Configuration()\n    # For debug log, set the value to True\n    configuration.debug = True\n    \n    \n    class MyResponse(ResonseInterface):\n      \"\"\"\n      Sample callback to handle the response from the REST endpoints\n      \"\"\"\n    \n      def success_callback(self, request, response, status, request_id):\n        logger.info(\"%s: %s: %s\", response, status, request_id)\n    \n      def error_callback(self, request, response, status, request_id, reason):\n        logger.error(\"%s: %s: %s %s\", response, status, reason, request_id)\n    \n    \n    def MetricRequest():\n      \"\"\"\n      Main function to get the CPU values using `psutil` and send to Metrics REST endpoint\n      \"\"\"\n      device_name = os.uname()[1]\n      resource = Resource(ids={'system.displayname': device_name}, name=device_name,\n                          create=True)\n      datasource = DataSource(name=\"DiskUsingSDK\")\n      datapoints = ['total', 'used', 'free']\n      metric_api = Metrics(batch=True, interval=30, response_callback=MyResponse())\n      while True:\n        partitions = psutil.disk_partitions()\n        for p in partitions:\n          instance_name = p.device\n          usage = psutil.disk_usage(instance_name)._asdict()\n          # Create the instance object for every device. Name should not have the\n          # special characters so replacing it with the '-'.\n          instance = DataSourceInstance(name=instance_name.replace('/', '-'),\n                                        display_name=instance_name)\n          for one_datapoint in datapoints:\n            datapoint = DataPoint(name=one_datapoint)\n            values = {str(int(time.time())): str(usage[one_datapoint])}\n            metric_api.send_metrics(resource=resource,\n                                    datasource=datasource,\n                                    instance=instance,\n                                    datapoint=datapoint,\n                                    values=values)\n        time.sleep(5)\n    \n    \n    if __name__ == \"__main__\":\n      MetricRequest()\n\n```\n\nThen run the program as:\n\n```python\n\n    pip install psutil\n    LM_COMPANY=\u003cACOUNT_NAME\u003e LM_ACCESS_ID=\u003cID\u003e LM_ACCESS_KEY='\u003cKEY\u003e' python disk_metrics.py\n```\n\n\nGet in Touch\n------------\nIf you have questions in general, reach out to our [support](mailto:support@logicmonitor.com)\n\n\n------------\nCopyright, 2021, LogicMonitor, Inc.\n\nThis Source Code Form is subject to the terms of the \nMozilla Public License, v. 2.0. If a copy of the MPL \nwas not distributed with this file, You can obtain \none at https://mozilla.org/MPL/2.0/.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicmonitor%2Flogicmonitor_data_sdk_py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogicmonitor%2Flogicmonitor_data_sdk_py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicmonitor%2Flogicmonitor_data_sdk_py/lists"}