Anodot API python package
Project description
Anodot API python package
Install:
pip install python-anodot
Posting metrics
Protocol 2.0
import anodot
import logging
import sys
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(anodot.Metric20(what='packets_in',
value=event['packets_in'],
target_type=anodot.TargetType.GAUGE,
timestamp=timestamp,
dimensions={'host': event['host'], 'region': event['region']},
tags={'tag_name': ['tag_value']},
version=VERSION))
events.append(anodot.Metric20(what='packets_out',
value=event['packets_out'],
target_type=anodot.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)
anodot.send(events, token='datacollectiontoken', logger=logger, base_url='https://app.anodot.com')
Protocol 3.0
import anodot
import logging
import sys
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
api_client = anodot.ApiClient('accesskeyhere', base_url='https://app.anodot.com')
schema = api_client.create_schema(anodot.Schema('new_schema',
['host', 'region'],
[anodot.Measurement('packets_in', anodot.Aggregation.AVERAGE),
anodot.Measurement('packets_out', anodot.Aggregation.AVERAGE)],
anodot.MissingDimPolicy(action=anodot.MissingDimPolicyAction.FAIL)))
events = []
for event in data:
timestamp = datetime.strptime(event['time'], '%Y-%m-%d %H:%M:%S')
events.append(anodot.Metric30(schema_id=schema['schema']['id'],
measurements={"packets_in": event['packets_in'], "packets_out": event['packets_out']},
timestamp=timestamp,
dimensions={'host': event['host'], 'region': event['region']},
tags={'tag_name': ['tag_value']}))
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)
anodot.send(events, token='datacollectiontoken', logger=logger, base_url='https://app.anodot.com',
protocol=anodot.Protocol.ANODOT30)
anodot.send_watermark(anodot.Watermark(schema['schema']['id'],
datetime.strptime('2020-01-01 00:03:00', '%Y-%m-%d %H:%M:%S')),
token='datacollectiontoken', logger=logger, base_url='https://app.anodot.com'
)
Posting metrics (for package version <2.0)
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
Release history Release notifications | RSS feed
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-2.0.1.tar.gz
(5.9 kB
view hashes)
Built Distribution
Close
Hashes for python_anodot-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade78dd3b2bf6c84c062a6f69f9d0f448366653023710940844b93e201888f61 |
|
MD5 | a2bae85abd0ec3609de91b72a2f9c562 |
|
BLAKE2b-256 | 772fe69dc02b13ff66d40e5584744fa297f992ca3927015d3c8e87c515ae03b9 |