Skip to content

Request Monitor

The RequestMonitor class collects creation time, scheduled time, termination time, and retry count information for each "vRequest" in the simulation. It allows you to track the lifecycle of requests, including their scheduling, execution, and potential retries.

RequestMonitor

Request Monitor.

Source code in PyCloudSim\monitor\request_monitor.py
class RequestMonitor:
    """Request Monitor."""
    _df: pd.DataFrame

    def __init__(
        self,
    ) -> None:
        self._df = pd.DataFrame(
            {
                "request_id": pd.Series(dtype="str"),
                "request_label": pd.Series(dtype="str"),
                "user_id": pd.Series(dtype="str"),
                "user_label": pd.Series(dtype="str"),
                "created_at": pd.Series(dtype="float"),
                "scheduled_at": pd.Series(dtype="float"),
                "terminated_at": pd.Series(dtype="float"),
                "successful": pd.Series(dtype="bool"),
            }
        )

        simulation._request_monitor = self

    def collect(self):
        for request in simulation.REQUESTS:
            request_info = pd.DataFrame(
                {
                    "request_id": request.id,
                    "request_label": request.label,
                    "user_id": request.user.id if request.user else None,
                    "user_label": request.user.label if request.user else None,
                    "created_at": request.created_at,
                    "scheduled_at": request.scheduled_at,
                    "terminated_at": request.terminated_at,
                    "successful": request.completed,
                },
                index=[0],
            )
            self._df = pd.concat([self._df, request_info], ignore_index=True)

    @property
    def df(self) -> pd.DataFrame:
        return self._df