예제 #1
0
    def _get_runtime_gc_count(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for garbage collection

        Args:
            observer: the observer to update
        """
        gc_count = gc.get_count()
        for index, count in enumerate(gc_count):
            self._runtime_gc_labels["count"] = str(index)
            observer.observe(count, self._runtime_gc_labels)
예제 #2
0
    def _get_runtime_memory(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for runtime memory

        Args:
            observer: the observer to update
        """
        proc_memory = self._proc.memory_info()
        for _type in self._config["runtime_memory"]:
            self._runtime_memory_labels["type"] = _type
            observer.observe(getattr(proc_memory, _type),
                             self._runtime_memory_labels)
예제 #3
0
    def _get_runtime_cpu(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for runtime CPU

        Args:
            observer: the observer to update
        """
        proc_cpu = self._proc.cpu_times()
        for _type in self._config["runtime_cpu"]:
            self._runtime_cpu_labels["type"] = _type
            observer.observe(getattr(proc_cpu, _type),
                             self._runtime_cpu_labels)
예제 #4
0
    def _get_system_cpu(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for system cpu

        Args:
            observer: the observer to update
        """
        cpu_times = psutil.cpu_times()
        for _type in self._config["system_cpu"]:
            self._system_cpu_labels["type"] = _type
            observer.observe(getattr(cpu_times, _type),
                             self._system_cpu_labels)
예제 #5
0
    def _get_network_bytes(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for network bytes

        Args:
            observer: the observer to update
        """
        net_io = psutil.net_io_counters()
        for _type in self._config["network_bytes"]:
            self._network_bytes_labels["type"] = _type
            observer.observe(getattr(net_io, _type),
                             self._network_bytes_labels)
예제 #6
0
    def _get_system_memory(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for memory available

        Args:
            observer: the observer to update
        """
        system_memory = psutil.virtual_memory()
        for metric in self._config["system_memory"]:
            self._system_memory_labels["type"] = metric
            observer.observe(getattr(system_memory, metric),
                             self._system_memory_labels)
예제 #7
0
    def _get_system_swap_usage(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for swap usage

        Args:
            observer: the observer to update
        """
        system_swap = psutil.swap_memory()

        for metric in self._config["system.swap.usage"]:
            self._system_swap_usage_labels["state"] = metric
            observer.observe(getattr(system_swap, metric),
                             self._system_swap_usage_labels)
예제 #8
0
    def _get_system_cpu_time(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for system CPU time

        Args:
            observer: the observer to update
        """
        for cpu, times in enumerate(psutil.cpu_times(percpu=True)):
            for metric in self._config["system.cpu.time"]:
                self._system_cpu_time_labels["state"] = metric
                self._system_cpu_time_labels["cpu"] = cpu + 1
                observer.observe(getattr(times, metric),
                                 self._system_cpu_time_labels)
예제 #9
0
    def _get_system_memory_usage(self,
                                 observer: metrics.ValueObserver) -> None:
        """Observer callback for memory usage

        Args:
            observer: the observer to update
        """
        virtual_memory = psutil.virtual_memory()
        for metric in self._config["system.memory.usage"]:
            self._system_memory_usage_labels["state"] = metric
            observer.observe(
                getattr(virtual_memory, metric),
                self._system_memory_usage_labels,
            )
예제 #10
0
    def _get_system_swap_utilization(self,
                                     observer: metrics.ValueObserver) -> None:
        """Observer callback for swap utilization

        Args:
            observer: the observer to update
        """
        system_swap = psutil.swap_memory()

        for metric in self._config["system.swap.utilization"]:
            self._system_swap_utilization_labels["state"] = metric
            observer.observe(
                getattr(system_swap, metric) / system_swap.total,
                self._system_swap_utilization_labels,
            )
    def _get_system_memory_utilization(
            self, observer: metrics.ValueObserver) -> None:
        """Observer callback for memory utilization

        Args:
            observer: the observer to update
        """
        system_memory = psutil.virtual_memory()

        for metric in self._config["system.memory.utilization"]:
            self._system_memory_utilization_labels["state"] = metric
            if hasattr(system_memory, metric):
                observer.observe(
                    getattr(system_memory, metric) / system_memory.total,
                    self._system_memory_utilization_labels,
                )
예제 #12
0
    def _get_system_cpu_utilization(self,
                                    observer: metrics.ValueObserver) -> None:
        """Observer callback for system CPU utilization

        Args:
            observer: the observer to update
        """

        for cpu, times_percent in enumerate(
                psutil.cpu_times_percent(percpu=True)):
            for metric in self._config["system.cpu.utilization"]:
                self._system_cpu_utilization_labels["state"] = metric
                self._system_cpu_utilization_labels["cpu"] = cpu + 1
                observer.observe(
                    getattr(times_percent, metric) / 100,
                    self._system_cpu_utilization_labels,
                )