-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-midiHubStats.py
52 lines (41 loc) · 1.66 KB
/
lambda-midiHubStats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import boto3
import os
import logging
dynamodb = boto3.client('dynamodb')
tableName = os.environ.get('TableName')
logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
global logger, tableName
if not tableName:
logger.error('TableName not set - stopping')
return {'statusCode':500, 'body':'TableName not set'}
paginator = dynamodb.get_paginator('scan')
iterator = paginator.paginate(TableName=tableName)
output = []
for page in iterator:
for stat in page['Items']:
try:
clientId = stat['clientId']['S']
if clientId == 'TransmitPorts': continue
hyphen = clientId.rfind('-')
if hyphen == -1:
name = clientId
port = '????'
else:
name = clientId[:hyphen]
port = clientId[hyphen+1:]
item = {'clientName':name, 'clientPort':port, 'timestamp': stat['timestamp']['N'],
'averageLatency':stat['averageLatency']['S'], 'maxLatency':stat['maxLatency']['S'],
'minLatency':stat['minLatency']['S'], 'lastLatency':stat['lastLatency']['S'],
'maxLatencyTime':stat['maxLatencyTime']['N'], 'minLatencyTime':stat['minLatencyTime']['N'],
'lastLatencyTime':stat['lastLatencyTime']['N']
}
except Exception as e:
logger.error(f'Cannot interpret item {stat}')
logger.error(e)
continue
output.append(item)
return(output)