-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tyler Gu <[email protected]>
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from typing import List | ||
from acto.kubernetes_engine.base import KubernetesEngine | ||
|
||
class WatchStats(): | ||
|
||
def __init__(self, cluster: KubernetesEngine, cluster_name: str, output_dir: str) -> None: | ||
self._cluster = cluster | ||
self._cluster_name = cluster_name | ||
self._output_dir = output_dir | ||
self._stop = False | ||
|
||
def write_stats(self, stats_buf: List[dict], sequence: int): | ||
with open(os.path.join(self._output_dir, f'{self._cluster_name}_stats.{sequence:08d}.json'), 'w') as f: | ||
json.dump(stats_buf, f, indent=4) | ||
|
||
def start(self): | ||
stats_buf = [] | ||
sequence = 0 | ||
stats_stream = self._cluster.stream_control_plane_stats("anvil") | ||
for stats in stats_stream: | ||
if self._stop: | ||
break | ||
stats_buf.append(stats) | ||
if len(stats_buf) >= 1000: | ||
self.write_stats(stats_buf, sequence) | ||
stats_buf = [] | ||
sequence += 1 | ||
if len(stats_buf) > 0: | ||
logging.info(f"Stopped, Writing {len(stats_buf)} stats to file") | ||
self.write_stats(stats_buf, sequence) | ||
return | ||
|
||
def stop(self): | ||
self._stop = True |