<commit_before># -*- coding: utf-8 -*-

"""Displays the number of docker containers running

Requires the following python packages:
    * docker

"""

try:
    import docker
except ImportError:
    pass

from requests.exceptions import ConnectionError

import bumblebee.input
import bumblebee.output
import bumblebee.engine


class Module(bumblebee.engine.Module):
    def __init__(self, engine, config):
        widget = bumblebee.output.Widget(full_text=self.status)
        super(Module, self).__init__(engine, config, widget)
        self._status = self.status

    def update(self, widgets):
        self._status = self.status

    def status(self, _):
        try:
            cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
            cli.ping()
        except ConnectionError:
            return "Daemon off"
        except Exception:
            return "n/a"
        return "OK - {}".format(len(cli.containers.list(filters={'status': "running"})))<commit_msg>[module] improvement of docker_ps by adding states<commit_after># -*- coding: utf-8 -*-

"""Displays the number of docker containers running

Requires the following python packages:
    * docker

"""

try:
    import docker
except ImportError:
    pass

from requests.exceptions import ConnectionError

import bumblebee.input
import bumblebee.output
import bumblebee.engine


class Module(bumblebee.engine.Module):
    def __init__(self, engine, config):
        widgets = bumblebee.output.Widget(full_text=self.status)
        super(Module, self).__init__(engine, config, widgets)
        self._status = self.status
        self._state = self.state

    def update(self, widgets):
        self._status = self.status
        self._state = self.state

    def state(self, widget):
        state = []
        status = self.status(widget)
        if status == "OK - 0":
            state.append("warning")
        elif  status in ["n/a", "Daemon off"]:
            state.append("critical")
        return state

    def status(self, widget):
        try:
            cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
            cli.ping()
        except ConnectionError:
            return "Daemon off"
        except Exception:
            return "n/a"
        return "OK - {}".format(len(cli.containers.list(filters={'status': "running"})))
{'fraction_non_alphanumeric': 0.11357813834329633, 'fraction_numerical': 0.0012809564474807857, 'mean_word_length': 2.6325581395348836, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99402', 'n_tokens_mistral': 686, 'n_tokens_neox': 659, 'n_words': 170}