claude final draft

This commit is contained in:
buenosairesam
2025-12-29 23:44:30 -03:00
parent 116d4032e2
commit e5aafd5097
22 changed files with 2815 additions and 32 deletions

5
shared/__init__.py Normal file
View File

@@ -0,0 +1,5 @@
"""Shared utilities and generated protobuf modules."""
from . import metrics_pb2, metrics_pb2_grpc
__all__ = ["metrics_pb2", "metrics_pb2_grpc"]

104
shared/config.py Normal file
View File

@@ -0,0 +1,104 @@
"""Shared configuration management using Pydantic Settings."""
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
class BaseConfig(BaseSettings):
"""Base configuration shared across all services."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
# Service identification
service_name: str = "unknown"
machine_id: str = "local"
# Logging
log_level: str = "INFO"
log_format: str = "json" # "json" or "console"
# Redis
redis_url: str = "redis://localhost:6379"
# Events
events_backend: str = "redis_pubsub"
class CollectorConfig(BaseConfig):
"""Collector service configuration."""
service_name: str = "collector"
# Aggregator connection
aggregator_url: str = "localhost:50051"
# Collection settings
collection_interval: int = 5 # seconds
# Metrics to collect
collect_cpu: bool = True
collect_memory: bool = True
collect_disk: bool = True
collect_network: bool = True
collect_load: bool = True
class AggregatorConfig(BaseConfig):
"""Aggregator service configuration."""
service_name: str = "aggregator"
# gRPC server
grpc_port: int = 50051
# TimescaleDB - can be set directly via TIMESCALE_URL
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
class GatewayConfig(BaseConfig):
"""Gateway service configuration."""
service_name: str = "gateway"
# HTTP server
http_port: int = 8000
# Aggregator connection
aggregator_url: str = "localhost:50051"
# TimescaleDB - can be set directly via TIMESCALE_URL
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
class AlertsConfig(BaseConfig):
"""Alerts service configuration."""
service_name: str = "alerts"
# TimescaleDB - can be set directly via TIMESCALE_URL or built from components
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
@lru_cache
def get_collector_config() -> CollectorConfig:
return CollectorConfig()
@lru_cache
def get_aggregator_config() -> AggregatorConfig:
return AggregatorConfig()
@lru_cache
def get_gateway_config() -> GatewayConfig:
return GatewayConfig()
@lru_cache
def get_alerts_config() -> AlertsConfig:
return AlertsConfig()

74
shared/logging.py Normal file
View File

@@ -0,0 +1,74 @@
"""Structured logging configuration."""
import logging
import sys
from typing import Any
import structlog
def setup_logging(
service_name: str,
log_level: str = "INFO",
log_format: str = "json",
) -> structlog.BoundLogger:
"""
Configure structured logging for a service.
Args:
service_name: Name of the service for log context
log_level: Logging level (DEBUG, INFO, WARNING, ERROR)
log_format: Output format ("json" or "console")
Returns:
Configured structlog logger
"""
# Shared processors
shared_processors: list[Any] = [
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
]
if log_format == "json":
# JSON format for production
processors = shared_processors + [
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
]
else:
# Console format for development
processors = shared_processors + [
structlog.dev.ConsoleRenderer(colors=True),
]
structlog.configure(
processors=processors,
wrapper_class=structlog.make_filtering_bound_logger(
getattr(logging, log_level.upper(), logging.INFO)
),
context_class=dict,
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=True,
)
# Also configure standard library logging
logging.basicConfig(
format="%(message)s",
stream=sys.stdout,
level=getattr(logging, log_level.upper(), logging.INFO),
)
# Get logger with service context
logger = structlog.get_logger(service=service_name)
return logger
def get_logger(name: str | None = None) -> structlog.BoundLogger:
"""Get a logger instance, optionally with a specific name."""
if name:
return structlog.get_logger(component=name)
return structlog.get_logger()

93
shared/metrics_pb2.py Normal file
View File

@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: metrics.proto
# Protobuf Python Version: 6.31.1
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(
_runtime_version.Domain.PUBLIC,
6,
31,
1,
'',
'metrics.proto'
)
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rmetrics.proto\x12\nmonitoring\"\x07\n\x05\x45mpty\"\xd8\x01\n\x06Metric\x12\x12\n\nmachine_id\x18\x01 \x01(\t\x12\x10\n\x08hostname\x18\x02 \x01(\t\x12\x14\n\x0ctimestamp_ms\x18\x03 \x01(\x03\x12$\n\x04type\x18\x04 \x01(\x0e\x32\x16.monitoring.MetricType\x12\r\n\x05value\x18\x05 \x01(\x01\x12.\n\x06labels\x18\x06 \x03(\x0b\x32\x1e.monitoring.Metric.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"s\n\x0bMetricBatch\x12\x12\n\nmachine_id\x18\x01 \x01(\t\x12\x10\n\x08hostname\x18\x02 \x01(\t\x12\x14\n\x0ctimestamp_ms\x18\x03 \x01(\x03\x12(\n\x07metrics\x18\x04 \x03(\x0b\x32\x17.monitoring.MetricPoint\"\xa6\x01\n\x0bMetricPoint\x12$\n\x04type\x18\x01 \x01(\x0e\x32\x16.monitoring.MetricType\x12\r\n\x05value\x18\x02 \x01(\x01\x12\x33\n\x06labels\x18\x03 \x03(\x0b\x32#.monitoring.MetricPoint.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"G\n\tStreamAck\x12\x0f\n\x07success\x18\x01 \x01(\x08\x12\x18\n\x10metrics_received\x18\x02 \x01(\x03\x12\x0f\n\x07message\x18\x03 \x01(\t\"\"\n\x0cStateRequest\x12\x12\n\nmachine_id\x18\x01 \x01(\t\"\x8c\x02\n\x0cMachineState\x12\x12\n\nmachine_id\x18\x01 \x01(\t\x12\x10\n\x08hostname\x18\x02 \x01(\t\x12\x14\n\x0clast_seen_ms\x18\x03 \x01(\x03\x12+\n\x0f\x63urrent_metrics\x18\x04 \x03(\x0b\x32\x12.monitoring.Metric\x12(\n\x06health\x18\x05 \x01(\x0e\x32\x18.monitoring.HealthStatus\x12\x38\n\x08metadata\x18\x06 \x03(\x0b\x32&.monitoring.MachineState.MetadataEntry\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\">\n\x10\x41llMachinesState\x12*\n\x08machines\x18\x01 \x03(\x0b\x32\x18.monitoring.MachineState\"\xd7\x01\n\x0e\x43ontrolCommand\x12\x12\n\ncommand_id\x18\x01 \x01(\t\x12<\n\x0fupdate_interval\x18\x02 \x01(\x0b\x32!.monitoring.UpdateIntervalCommandH\x00\x12\x37\n\x07restart\x18\x03 \x01(\x0b\x32$.monitoring.RestartCollectionCommandH\x00\x12/\n\x08shutdown\x18\x04 \x01(\x0b\x32\x1b.monitoring.ShutdownCommandH\x00\x42\t\n\x07\x63ommand\"1\n\x15UpdateIntervalCommand\x12\x18\n\x10interval_seconds\x18\x01 \x01(\x05\"\x1a\n\x18RestartCollectionCommand\"#\n\x0fShutdownCommand\x12\x10\n\x08graceful\x18\x01 \x01(\x08\"G\n\x0f\x43ontrolResponse\x12\x12\n\ncommand_id\x18\x01 \x01(\t\x12\x0f\n\x07success\x18\x02 \x01(\x08\x12\x0f\n\x07message\x18\x03 \x01(\t\"#\n\rConfigRequest\x12\x12\n\nmachine_id\x18\x01 \x01(\t\"\x80\x02\n\x0f\x43ollectorConfig\x12#\n\x1b\x63ollection_interval_seconds\x18\x01 \x01(\x05\x12/\n\x0f\x65nabled_metrics\x18\x02 \x03(\x0e\x32\x16.monitoring.MetricType\x12\x37\n\x06labels\x18\x03 \x03(\x0b\x32\'.monitoring.CollectorConfig.LabelsEntry\x12/\n\nthresholds\x18\x04 \x03(\x0b\x32\x1b.monitoring.ThresholdConfig\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"u\n\x0fThresholdConfig\x12+\n\x0bmetric_type\x18\x01 \x01(\x0e\x32\x16.monitoring.MetricType\x12\x19\n\x11warning_threshold\x18\x02 \x01(\x01\x12\x1a\n\x12\x63ritical_threshold\x18\x03 \x01(\x01*\x8d\x03\n\nMetricType\x12\x1b\n\x17METRIC_TYPE_UNSPECIFIED\x10\x00\x12\x0f\n\x0b\x43PU_PERCENT\x10\x01\x12\x18\n\x14\x43PU_PERCENT_PER_CORE\x10\x02\x12\x12\n\x0eMEMORY_PERCENT\x10\x03\x12\x15\n\x11MEMORY_USED_BYTES\x10\x04\x12\x1a\n\x16MEMORY_AVAILABLE_BYTES\x10\x05\x12\x10\n\x0c\x44ISK_PERCENT\x10\x06\x12\x13\n\x0f\x44ISK_USED_BYTES\x10\x07\x12\x17\n\x13\x44ISK_READ_BYTES_SEC\x10\x08\x12\x18\n\x14\x44ISK_WRITE_BYTES_SEC\x10\t\x12\x1a\n\x16NETWORK_SENT_BYTES_SEC\x10\n\x12\x1a\n\x16NETWORK_RECV_BYTES_SEC\x10\x0b\x12\x17\n\x13NETWORK_CONNECTIONS\x10\x0c\x12\x11\n\rPROCESS_COUNT\x10\r\x12\x0f\n\x0bLOAD_AVG_1M\x10\x0e\x12\x0f\n\x0bLOAD_AVG_5M\x10\x0f\x12\x10\n\x0cLOAD_AVG_15M\x10\x10*o\n\x0cHealthStatus\x12\x1d\n\x19HEALTH_STATUS_UNSPECIFIED\x10\x00\x12\x0b\n\x07HEALTHY\x10\x01\x12\x0b\n\x07WARNING\x10\x02\x12\x0c\n\x08\x43RITICAL\x10\x03\x12\x0b\n\x07UNKNOWN\x10\x04\x12\x0b\n\x07OFFLINE\x10\x05\x32\xdc\x01\n\x0eMetricsService\x12>\n\rStreamMetrics\x12\x12.monitoring.Metric\x1a\x15.monitoring.StreamAck\"\x00(\x01\x12G\n\x0fGetCurrentState\x12\x18.monitoring.StateRequest\x1a\x18.monitoring.MachineState\"\x00\x12\x41\n\x0cGetAllStates\x12\x11.monitoring.Empty\x1a\x1c.monitoring.AllMachinesState\"\x00\x32Z\n\x0e\x43ontrolService\x12H\n\x07\x43ontrol\x12\x1a.monitoring.ControlCommand\x1a\x1b.monitoring.ControlResponse\"\x00(\x01\x30\x01\x32\xa1\x01\n\rConfigService\x12\x45\n\tGetConfig\x12\x19.monitoring.ConfigRequest\x1a\x1b.monitoring.CollectorConfig\"\x00\x12I\n\x0bWatchConfig\x12\x19.monitoring.ConfigRequest\x1a\x1b.monitoring.CollectorConfig\"\x00\x30\x01\x42%Z#github.com/your-org/sysmonstm/protob\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'metrics_pb2', _globals)
if not _descriptor._USE_C_DESCRIPTORS:
_globals['DESCRIPTOR']._loaded_options = None
_globals['DESCRIPTOR']._serialized_options = b'Z#github.com/your-org/sysmonstm/proto'
_globals['_METRIC_LABELSENTRY']._loaded_options = None
_globals['_METRIC_LABELSENTRY']._serialized_options = b'8\001'
_globals['_METRICPOINT_LABELSENTRY']._loaded_options = None
_globals['_METRICPOINT_LABELSENTRY']._serialized_options = b'8\001'
_globals['_MACHINESTATE_METADATAENTRY']._loaded_options = None
_globals['_MACHINESTATE_METADATAENTRY']._serialized_options = b'8\001'
_globals['_COLLECTORCONFIG_LABELSENTRY']._loaded_options = None
_globals['_COLLECTORCONFIG_LABELSENTRY']._serialized_options = b'8\001'
_globals['_METRICTYPE']._serialized_start=1810
_globals['_METRICTYPE']._serialized_end=2207
_globals['_HEALTHSTATUS']._serialized_start=2209
_globals['_HEALTHSTATUS']._serialized_end=2320
_globals['_EMPTY']._serialized_start=29
_globals['_EMPTY']._serialized_end=36
_globals['_METRIC']._serialized_start=39
_globals['_METRIC']._serialized_end=255
_globals['_METRIC_LABELSENTRY']._serialized_start=210
_globals['_METRIC_LABELSENTRY']._serialized_end=255
_globals['_METRICBATCH']._serialized_start=257
_globals['_METRICBATCH']._serialized_end=372
_globals['_METRICPOINT']._serialized_start=375
_globals['_METRICPOINT']._serialized_end=541
_globals['_METRICPOINT_LABELSENTRY']._serialized_start=210
_globals['_METRICPOINT_LABELSENTRY']._serialized_end=255
_globals['_STREAMACK']._serialized_start=543
_globals['_STREAMACK']._serialized_end=614
_globals['_STATEREQUEST']._serialized_start=616
_globals['_STATEREQUEST']._serialized_end=650
_globals['_MACHINESTATE']._serialized_start=653
_globals['_MACHINESTATE']._serialized_end=921
_globals['_MACHINESTATE_METADATAENTRY']._serialized_start=874
_globals['_MACHINESTATE_METADATAENTRY']._serialized_end=921
_globals['_ALLMACHINESSTATE']._serialized_start=923
_globals['_ALLMACHINESSTATE']._serialized_end=985
_globals['_CONTROLCOMMAND']._serialized_start=988
_globals['_CONTROLCOMMAND']._serialized_end=1203
_globals['_UPDATEINTERVALCOMMAND']._serialized_start=1205
_globals['_UPDATEINTERVALCOMMAND']._serialized_end=1254
_globals['_RESTARTCOLLECTIONCOMMAND']._serialized_start=1256
_globals['_RESTARTCOLLECTIONCOMMAND']._serialized_end=1282
_globals['_SHUTDOWNCOMMAND']._serialized_start=1284
_globals['_SHUTDOWNCOMMAND']._serialized_end=1319
_globals['_CONTROLRESPONSE']._serialized_start=1321
_globals['_CONTROLRESPONSE']._serialized_end=1392
_globals['_CONFIGREQUEST']._serialized_start=1394
_globals['_CONFIGREQUEST']._serialized_end=1429
_globals['_COLLECTORCONFIG']._serialized_start=1432
_globals['_COLLECTORCONFIG']._serialized_end=1688
_globals['_COLLECTORCONFIG_LABELSENTRY']._serialized_start=210
_globals['_COLLECTORCONFIG_LABELSENTRY']._serialized_end=255
_globals['_THRESHOLDCONFIG']._serialized_start=1690
_globals['_THRESHOLDCONFIG']._serialized_end=1807
_globals['_METRICSSERVICE']._serialized_start=2323
_globals['_METRICSSERVICE']._serialized_end=2543
_globals['_CONTROLSERVICE']._serialized_start=2545
_globals['_CONTROLSERVICE']._serialized_end=2635
_globals['_CONFIGSERVICE']._serialized_start=2638
_globals['_CONFIGSERVICE']._serialized_end=2799
# @@protoc_insertion_point(module_scope)

385
shared/metrics_pb2_grpc.py Normal file
View File

@@ -0,0 +1,385 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings
from shared import metrics_pb2 as metrics__pb2
GRPC_GENERATED_VERSION = '1.76.0'
GRPC_VERSION = grpc.__version__
_version_not_supported = False
try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
except ImportError:
_version_not_supported = True
if _version_not_supported:
raise RuntimeError(
f'The grpc package installed is at version {GRPC_VERSION},'
+ ' but the generated code in metrics_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
)
class MetricsServiceStub(object):
"""MetricsService handles streaming metrics from collectors to aggregator
"""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.StreamMetrics = channel.stream_unary(
'/monitoring.MetricsService/StreamMetrics',
request_serializer=metrics__pb2.Metric.SerializeToString,
response_deserializer=metrics__pb2.StreamAck.FromString,
_registered_method=True)
self.GetCurrentState = channel.unary_unary(
'/monitoring.MetricsService/GetCurrentState',
request_serializer=metrics__pb2.StateRequest.SerializeToString,
response_deserializer=metrics__pb2.MachineState.FromString,
_registered_method=True)
self.GetAllStates = channel.unary_unary(
'/monitoring.MetricsService/GetAllStates',
request_serializer=metrics__pb2.Empty.SerializeToString,
response_deserializer=metrics__pb2.AllMachinesState.FromString,
_registered_method=True)
class MetricsServiceServicer(object):
"""MetricsService handles streaming metrics from collectors to aggregator
"""
def StreamMetrics(self, request_iterator, context):
"""Client-side streaming: collector streams metrics to aggregator
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def GetCurrentState(self, request, context):
"""Get current state of a machine
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def GetAllStates(self, request, context):
"""Get current state of all machines
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_MetricsServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'StreamMetrics': grpc.stream_unary_rpc_method_handler(
servicer.StreamMetrics,
request_deserializer=metrics__pb2.Metric.FromString,
response_serializer=metrics__pb2.StreamAck.SerializeToString,
),
'GetCurrentState': grpc.unary_unary_rpc_method_handler(
servicer.GetCurrentState,
request_deserializer=metrics__pb2.StateRequest.FromString,
response_serializer=metrics__pb2.MachineState.SerializeToString,
),
'GetAllStates': grpc.unary_unary_rpc_method_handler(
servicer.GetAllStates,
request_deserializer=metrics__pb2.Empty.FromString,
response_serializer=metrics__pb2.AllMachinesState.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'monitoring.MetricsService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('monitoring.MetricsService', rpc_method_handlers)
# This class is part of an EXPERIMENTAL API.
class MetricsService(object):
"""MetricsService handles streaming metrics from collectors to aggregator
"""
@staticmethod
def StreamMetrics(request_iterator,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.stream_unary(
request_iterator,
target,
'/monitoring.MetricsService/StreamMetrics',
metrics__pb2.Metric.SerializeToString,
metrics__pb2.StreamAck.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
@staticmethod
def GetCurrentState(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/monitoring.MetricsService/GetCurrentState',
metrics__pb2.StateRequest.SerializeToString,
metrics__pb2.MachineState.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
@staticmethod
def GetAllStates(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/monitoring.MetricsService/GetAllStates',
metrics__pb2.Empty.SerializeToString,
metrics__pb2.AllMachinesState.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
class ControlServiceStub(object):
"""ControlService handles bidirectional control commands
"""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.Control = channel.stream_stream(
'/monitoring.ControlService/Control',
request_serializer=metrics__pb2.ControlCommand.SerializeToString,
response_deserializer=metrics__pb2.ControlResponse.FromString,
_registered_method=True)
class ControlServiceServicer(object):
"""ControlService handles bidirectional control commands
"""
def Control(self, request_iterator, context):
"""Bidirectional streaming for commands and responses
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_ControlServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'Control': grpc.stream_stream_rpc_method_handler(
servicer.Control,
request_deserializer=metrics__pb2.ControlCommand.FromString,
response_serializer=metrics__pb2.ControlResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'monitoring.ControlService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('monitoring.ControlService', rpc_method_handlers)
# This class is part of an EXPERIMENTAL API.
class ControlService(object):
"""ControlService handles bidirectional control commands
"""
@staticmethod
def Control(request_iterator,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.stream_stream(
request_iterator,
target,
'/monitoring.ControlService/Control',
metrics__pb2.ControlCommand.SerializeToString,
metrics__pb2.ControlResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
class ConfigServiceStub(object):
"""ConfigService handles dynamic configuration
"""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.GetConfig = channel.unary_unary(
'/monitoring.ConfigService/GetConfig',
request_serializer=metrics__pb2.ConfigRequest.SerializeToString,
response_deserializer=metrics__pb2.CollectorConfig.FromString,
_registered_method=True)
self.WatchConfig = channel.unary_stream(
'/monitoring.ConfigService/WatchConfig',
request_serializer=metrics__pb2.ConfigRequest.SerializeToString,
response_deserializer=metrics__pb2.CollectorConfig.FromString,
_registered_method=True)
class ConfigServiceServicer(object):
"""ConfigService handles dynamic configuration
"""
def GetConfig(self, request, context):
"""Get current configuration for a collector
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def WatchConfig(self, request, context):
"""Stream configuration updates
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_ConfigServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'GetConfig': grpc.unary_unary_rpc_method_handler(
servicer.GetConfig,
request_deserializer=metrics__pb2.ConfigRequest.FromString,
response_serializer=metrics__pb2.CollectorConfig.SerializeToString,
),
'WatchConfig': grpc.unary_stream_rpc_method_handler(
servicer.WatchConfig,
request_deserializer=metrics__pb2.ConfigRequest.FromString,
response_serializer=metrics__pb2.CollectorConfig.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'monitoring.ConfigService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('monitoring.ConfigService', rpc_method_handlers)
# This class is part of an EXPERIMENTAL API.
class ConfigService(object):
"""ConfigService handles dynamic configuration
"""
@staticmethod
def GetConfig(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/monitoring.ConfigService/GetConfig',
metrics__pb2.ConfigRequest.SerializeToString,
metrics__pb2.CollectorConfig.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
@staticmethod
def WatchConfig(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_stream(
request,
target,
'/monitoring.ConfigService/WatchConfig',
metrics__pb2.ConfigRequest.SerializeToString,
metrics__pb2.CollectorConfig.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)