comparison light9/collector/collector.py @ 2357:ccd04278e357

metrics cleanup
author drewp@bigasterisk.com
date Sat, 03 Jun 2023 17:15:40 -0700
parents 2b8a2a25b154
children
comparison
equal deleted inserted replaced
2356:6394d7d71974 2357:ccd04278e357
1 import logging 1 import logging
2 import time 2 import time
3 from typing import Dict, List, Set, Tuple, cast 3 from typing import Dict, List, Set, Tuple, cast
4 from light9.typedgraph import typedValue 4 from light9.typedgraph import typedValue
5 5
6 from prometheus_client import Summary
6 from rdfdb.syncedgraph.syncedgraph import SyncedGraph 7 from rdfdb.syncedgraph.syncedgraph import SyncedGraph
7 from rdflib import URIRef 8 from rdflib import URIRef
8 9
9 from light9.collector.device import resolve, toOutputAttrs 10 from light9.collector.device import resolve, toOutputAttrs
10 from light9.collector.output import Output as OutputInstance 11 from light9.collector.output import Output as OutputInstance
14 from light9.newtypes import (ClientSessionType, ClientType, DeviceAttr, DeviceClass, DeviceSetting, DeviceUri, DmxIndex, DmxMessageIndex, OutputAttr, 15 from light9.newtypes import (ClientSessionType, ClientType, DeviceAttr, DeviceClass, DeviceSetting, DeviceUri, DmxIndex, DmxMessageIndex, OutputAttr,
15 OutputRange, OutputUri, OutputValue, UnixTime, VTUnion, uriTail) 16 OutputRange, OutputUri, OutputValue, UnixTime, VTUnion, uriTail)
16 17
17 log = logging.getLogger('collector') 18 log = logging.getLogger('collector')
18 19
20 STAT_SETATTR = Summary('set_attr', 'setAttr calls')
19 21
20 def makeDmxMessageIndex(base: DmxIndex, offset: DmxIndex) -> DmxMessageIndex: 22 def makeDmxMessageIndex(base: DmxIndex, offset: DmxIndex) -> DmxMessageIndex:
21 return DmxMessageIndex(base + offset - 1) 23 return DmxMessageIndex(base + offset - 1)
22 24
23 25
97 attr = typedValue(OutputAttr, self.graph, remap, L9['outputAttr']) 99 attr = typedValue(OutputAttr, self.graph, remap, L9['outputAttr'])
98 start = typedValue(float, self.graph, remap, L9['start']) 100 start = typedValue(float, self.graph, remap, L9['start'])
99 end = typedValue(float, self.graph, remap, L9['end']) 101 end = typedValue(float, self.graph, remap, L9['end'])
100 self.remapOut[(dev, attr)] = OutputRange((start, end)) 102 self.remapOut[(dev, attr)] = OutputRange((start, end))
101 103
104 @STAT_SETATTR.time()
102 def setAttrs(self, client: ClientType, clientSession: ClientSessionType, settings: DeviceSettings, sendTime: UnixTime): 105 def setAttrs(self, client: ClientType, clientSession: ClientSessionType, settings: DeviceSettings, sendTime: UnixTime):
103 """ 106 """
104 Given DeviceSettings, we resolve conflicting values, 107 Given DeviceSettings, we resolve conflicting values,
105 process them into output attrs, and call Output.update 108 process them into output attrs, and call Output.update
106 to send the new outputs. 109 to send the new outputs.