From e0381ec7f6f4ad1c5a65dfaafc161c859ed0c16f Mon Sep 17 00:00:00 2001 From: Shao Yu Lung Date: Mon, 10 Jun 2019 10:58:35 +0800 Subject: [PATCH] add nginx agent use python3 --- snmp/nginx-python3.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 snmp/nginx-python3.py diff --git a/snmp/nginx-python3.py b/snmp/nginx-python3.py new file mode 100755 index 0000000..4bfb3a4 --- /dev/null +++ b/snmp/nginx-python3.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from urllib.request import urlopen +import re + +data = urlopen('http://localhost/nginx-status').read() + +params = {} + +for line in data.decode().split("\n"): + smallstat = re.match(r"\s?Reading:\s(.*)\sWriting:\s(.*)\sWaiting:\s(.*)$", line) + req = re.match(r"\s+(\d+)\s+(\d+)\s+(\d+)", line) + if smallstat: + params["Reading"] = smallstat.group(1) + params["Writing"] = smallstat.group(2) + params["Waiting"] = smallstat.group(3) + elif req: + params["Requests"] = req.group(3) + else: + pass + +dataorder = ["Active", "Reading", "Writing", "Waiting", "Requests"] + +for param in dataorder: + if param == "Active": + Active = int(params["Reading"]) + int(params["Writing"]) + int(params["Waiting"]) + print(Active) + else: + print(params[param])