PHP 7.4.33
Preview: uwsgi.py Size: 4.73 KB
//lib/fm-agent/plugins/uwsgi.py

import agent_util
import logging

logger = logging.getLogger(__name__)


class UWSGIPlugin(agent_util.Plugin):
    textkey = "uwsgi"
    label = "UWSGI"

    @classmethod
    def get_metadata(self, config):
        status = agent_util.SUPPORTED
        msg = None

        # check if uwsgi is even installed
        installed = agent_util.which("uwsgi")
        if not installed:
            self.log.info("The uwsgi binary was not found.")
            status = agent_util.UNSUPPORTED
            msg = "uwsgi binary not found"
            return {}

        if not config:
            msg = "The [uwsgi] config block is not found in the agent config file."
            self.log.info(msg)
            status = agent_util.MISCONFIGURED

        if status == agent_util.SUPPORTED and (
            not "server" in config or not "port" in config
        ):
            msg = "The server and port settings were not found in the [uwsgi] block of the agent config file."
            self.log.info(msg)
            status = agent_util.MISCONFIGURED

        workers = []
        if status is agent_util.SUPPORTED:
            try:
                status, output = agent_util.execute_command(
                    "nc %s %s" % (config["server"], config["port"])
                )
                if status != 0:
                    raise Exception(output)
                output = agent_util.json_loads(output)
                for worker in output["workers"]:
                    workers.append("Worker #%s" % worker["pid"])
                workers.sort()

            except:
                status = agent_util.MISCONFIGURED
                msg = "Unable to get uwsgi status, please make sure uwsgi is running with the status module enabled and that the connection settings in the agent configuration file are valid."
                self.log.info(msg)

        if status == agent_util.SUPPORTED and not workers:
            status = agent_util.MISCONFIGURED
            msg = "No workers found."

        metadata = {
            "requests": {
                "label": "Requests per second",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "requests",
            },
            "exceptions": {
                "label": "Exceptions",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "exceptions",
            },
            "status": {
                "label": "Worker is busy or free to use(BUSY=1, FREE=0)",
                "options": workers,
                "status": status,
                "error_message": msg,
            },
            "rss": {
                "label": "Worker RSS (Resident Set Size)",
                "options": workers,
                "status": status,
                "error_message": msg,
            },
            "vsz": {
                "label": "Worker VSZ (Virtual Memory Size)",
                "options": workers,
                "status": status,
                "error_message": msg,
            },
            "running_time": {
                "label": "How long worker is working",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "workers",
            },
            "respawn_count": {
                "label": "How many requests worker did since worker (re)spawn",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "requests",
            },
            "tx": {
                "label": "How many data was transmitted by worker",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "data",
            },
            "avg_rt": {
                "label": "Average request time",
                "options": workers,
                "status": status,
                "error_message": msg,
                "unit": "ms",
            },
        }
        return metadata

    def check(self, textkey, worker, config):
        status, output = agent_util.execute_command(
            "nc %s %s" % (config["server"], config["port"])
        )
        if status != 0:
            raise Exception(output)
        output = agent_util.json_loads(output)
        workers = output["workers"]
        pid = worker.replace("Worker #", "")

        for w in workers:
            if w["pid"] == int(pid):
                worker = w
                break
        try:
            res = worker[textkey]
            if textkey == "status":
                if res == "idle":
                    res = 0
                else:
                    res = 1
        except:
            res = 0
        return res

Directory Contents

Dirs: 1 × Files: 55

Name Size Perms Modified Actions
- drwxr-xr-x 2025-06-19 05:08:01
Edit Download
20.07 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
13.66 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
6.34 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
22.59 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
9.46 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.89 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
9.56 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
32.09 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
7.33 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
16.80 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
38.95 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.90 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
930 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.00 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
5.07 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.68 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
13.46 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
13.21 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
13.58 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
8.39 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.34 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.54 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.64 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
6.04 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
26.56 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
16.61 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
20.40 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
5.58 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
12.33 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
6.44 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.98 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.30 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
15.51 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
8.88 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
5.61 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.60 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.99 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
21.37 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
17.23 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
19.85 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
11.31 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.42 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.42 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
6.59 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.28 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
7.09 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
19.11 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.62 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.61 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.09 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.73 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.91 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
13.84 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
19.20 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
0 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).