Created
June 18, 2018 11:11
-
-
Save colin-nolan/3c02bc737a87a44e1f3e78a618396cf6 to your computer and use it in GitHub Desktop.
Very quick plot of passenger instance memory usage over time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires install of packages: | |
# - delta | |
# - leather | |
# | |
# Working with data written periodically to a file: | |
# `passenger-status --show=xml | python <(echo -e "import xmltodict\nimport json\nimport sys\nprint(json.dumps(xmltodict.parse(sys.stdin.read())))")` | |
import json | |
from collections import defaultdict | |
import leather | |
import delta | |
def get_x(point, index): | |
uptime = point["uptime"] | |
return delta.parse(uptime).total_seconds() | |
def get_y(point, index): | |
return int(point.get("real_memory", -1)) | |
def read_data(): | |
process_data = defaultdict(list) | |
with open("statuses", "r") as file: | |
for line in file.readlines(): | |
line_data = json.loads(line)["info"]["supergroups"]["supergroup"]["group"]["processes"]["process"] | |
for point in line_data: | |
pid = point["pid"] | |
process_data[pid].append(point) | |
return process_data | |
def main(): | |
process_data = read_data() | |
chart = leather.Chart("Line") | |
for pid, data in process_data.items(): | |
chart.add_line(data, x=get_x, y=get_y, name=pid) | |
chart.to_svg("save.svg", height=2000, width=10000) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment