Skip to main content

Anodot API python package

Project description

Anodot API python package

Install:

pip install python-anodot

Posting metrics

Example

import logging
import sys

from anodot import metric
from datetime import datetime

data = [
  {"time": "2020-01-01 00:00:00", "packets_in": 100, "packets_out": 120, "host": "host134", "region": "region1"},
  {"time": "2020-01-01 00:01:00", "packets_in": 163, "packets_out": 130, "host": "host126", "region": "region1"},
  {"time": "2020-01-01 00:02:00", "packets_in": 215, "packets_out": 140, "host": "host101", "region": "region2"}
]

VERSION = 1

events = []
for event in data:
    timestamp = datetime.strptime(event['time'], '%Y-%m-%d %H:%M:%S')
    events.append(metric.Metric(what='packets_in',
                                value=event['packets_in'],
                                target_type=metric.TargetType.GAUGE,
                                timestamp=timestamp,
                                dimensions={'host': event['host'], 'region': event['region']},
                                tags={'tag_name': ['tag_value']},
                                version=VERSION))    
    events.append(metric.Metric(what='packets_out',
                                value=event['packets_out'],
                                target_type=metric.TargetType.GAUGE,
                                timestamp=timestamp,
                                dimensions={'host': event['host'], 'region': event['region']},
                                tags={'tag_name': ['tag_value']},
                                version=VERSION))       

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)

metric.send(events, token='datacollectiontoken', logger=logger, base_url='https://app.anodot.com')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-anodot-1.0.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

python_anodot-1.0.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page