server: cluster cpu usage monitoring

This commit is contained in:
Koushik Dutta
2024-12-02 15:08:56 -08:00
parent d91ec68e6c
commit a75b263141
21 changed files with 106 additions and 62 deletions

View File

@@ -21,7 +21,6 @@ class ClusterObject(TypedDict):
sourceKey: str
sha256: str
def isClusterAddress(address: str):
return not address or address == os.environ.get("SCRYPTED_CLUSTER_ADDRESS", None)
@@ -99,6 +98,7 @@ class ClusterSetup:
return
self.clusterId = options["clusterId"]
self.clusterSecret = options["clusterSecret"]
self.clusterWorkerId = options["clusterWorkerId"]
self.SCRYPTED_CLUSTER_ADDRESS = os.environ.get("SCRYPTED_CLUSTER_ADDRESS", None)
async def handleClusterClient(
@@ -144,7 +144,7 @@ class ClusterSetup:
m = hashlib.sha256()
m.update(
bytes(
f"{o['id']}{o.get('address') or ''}{o['port']}{o.get('sourceKey', None) or ''}{o['proxyId']}{self.clusterSecret}",
f"{o['id']}{o.get('address', '')}{o['port']}{o.get('sourceKey', '')}{o['proxyId']}{self.clusterSecret}",
"utf8",
)
)

View File

@@ -229,21 +229,21 @@ class EventRegistry(object):
class ClusterManager(scrypted_python.scrypted_sdk.types.ClusterManager):
def __init__(self, api: Any):
self.api = api
def __init__(self, remote: PluginRemote):
self.remote = remote
self.clusterService = None
def getClusterMode(self) -> Any | Any:
return os.getenv("SCRYPTED_CLUSTER_MODE", None)
def getClusterWorkerId(self) -> str:
return os.getenv("SCRYPTED_CLUSTER_WORKER_ID", None)
return self.remote.clusterSetup.clusterWorkerId
async def getClusterWorkers(
self,
) -> Mapping[str, scrypted_python.scrypted_sdk.types.ClusterWorker]:
self.clusterService = self.clusterService or asyncio.ensure_future(
self.api.getComponent("cluster-fork")
self.remote.api.getComponent("cluster-fork")
)
cs = await self.clusterService
return await cs.getClusterWorkers()
@@ -839,7 +839,7 @@ class PluginRemote:
self.systemManager = SystemManager(self.api, self.systemState)
self.deviceManager = DeviceManager(self.nativeIds, self.systemManager)
self.mediaManager = MediaManager(await self.api.getMediaManager())
self.clusterManager = ClusterManager(self.api)
self.clusterManager = ClusterManager(self)
try:
sdk.systemManager = self.systemManager