Changeset - cba85338def9
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 3 years ago 2022-05-13 08:07:36
drewp@bigasterisk.com
port to metrics()
1 file changed with 6 insertions and 12 deletions:
0 comments (0 inline, 0 general)
light9/collector/output.py
Show inline comments
 
@@ -167,8 +167,6 @@ class ArtnetDmx(BackgroundLoopOutput):
 

	
 

	
 
class Udmx(BackgroundLoopOutput):
 
    _reconnections = scales.IntStat('reconnections')
 
    _connected = scales.IntStat('connected')
 

	
 
    def __init__(self, uri, bus, address, lastDmxChannel, rate=22):
 
        self.bus = bus
 
@@ -177,24 +175,20 @@ class Udmx(BackgroundLoopOutput):
 
        self.dev = None
 
        super().__init__(uri, rate=rate)
 

	
 
        self._errStats = scales.collection(self.statPath + '/write',
 
                                           scales.IntStat('overflow'),
 
                                           scales.IntStat('ioError'),
 
                                           scales.IntStat('pipeError'))
 
        self.reconnect()
 

	
 
    def shortId(self) -> str:
 
        return super().shortId() + f'_bus={self.bus}'
 

	
 
    def reconnect(self):
 
        self._connected = 0
 
        metrics('connected', output=self.shortId()).set(0)
 
        from pyudmx import pyudmx
 
        self.dev = pyudmx.uDMXDevice()
 
        if not self.dev.open(bus=self.bus, address=self.address):
 
            raise ValueError("dmx open failed")
 
        log.info(f'opened {self.dev}')
 
        self._connected = 1
 
        self._reconnections += 1
 
        metrics('connected', output=self.shortId()).set(1)
 
        metrics('reconnections', output=self.shortId()).inc()
 

	
 
    #def update(self, buf:bytes):
 
    #    self._write(buf)
 
@@ -232,15 +226,15 @@ class Udmx(BackgroundLoopOutput):
 
            except usb.core.USBError as e:
 
                # not in main thread
 
                if e.errno == 75:
 
                    self._errStats.overflow += 1
 
                    metrics('write_overflow', output=self.shortId()).inc()
 
                    return
 

	
 
                if e.errno == 5:  # i/o err
 
                    self._errStats.ioError += 1
 
                    metrics('write_io_error', output=self.shortId()).inc()
 
                    return
 

	
 
                if e.errno == 32:  # pipe err
 
                    self._errStats.pipeError += 1
 
                    metrics('write_pipe_error', output=self.shortId()).inc()
 
                    return
 

	
 
                msg = 'usb: sending %s bytes to %r; error %r' % (len(buf),
0 comments (0 inline, 0 general)