def __init__(self, target, target_str): self.target = target if isinstance(target_str, str): f = target_str else: f = target_str.__class__.__name__ f = function.parse_name(f) self._tap_count = Counter(f'total_{f}', f'total rows {f}') self._tap_data = Summary(f'data_size_{f}', f'summary of data size {f} (KB)') self._tap_data_histogram = Histogram( f'data_size_histogram_{f}', f'histogram of data size {f} (KB)')
def __init__( self, tap, tap_schema: dict = None, tap_name: str = None, tap_key: str = None, port: int = 8000, ): """ Parameters ---------- tap: str / object tap source. tap_schema: Dict, (default=None) data schema if tap an object. If `tap_schema` is None, it will auto generate schema. tap_name: str, (default=None) name for tap, necessary if tap is an object. it will throw an error if not a string if tap is an object. tap_key: str, (default=None) important non-duplicate key from `tap.emit()`, usually a timestamp. port: int, (default=8000) prometheus exporter port. """ if not isinstance(tap, str) and not hasattr(tap, 'emit'): raise ValueError( 'tap must a string or an object with method `emit`') if hasattr(tap, '__dict__'): self.tap = helper.Tap( tap, tap_schema=tap_schema, tap_name=tap_name, tap_key=tap_key, ) f = tap_name self.tap_schema = tap_schema else: self.tap = tap self.tap_schema = None f = tap self.tap_name = tap_name self._targets = [] start_http_server(port) f = function.parse_name(f) self._tap_count = Counter(f'total_{f}', f'total rows {f}') self._tap_data = Summary(f'data_size_{f}', f'summary of data size {f} (KB)') self._tap_data_histogram = Histogram( f'data_size_histogram_{f}', f'histogram of data size {f} (KB)')