Repository
Munin (contrib)
Last change
2021-03-09
Capabilities
Keywords
Language
Python (3.x)

beanstalkd

Sadly there is no documentation for this plugin.

#!/usr/bin/env python3

import os
import sys

from pystalk import BeanstalkClient

STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried']


def connect():
    return BeanstalkClient(
        os.getenv('host', 'localhost'),
        os.getenv('port', '11300'),
    )


def config():
    c = connect()
    tubes = c.list_tubes()
    print_config(tubes)


def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'):
    for tube in tubes:
        print(f'multigraph job_count_{tube}')
        print(f'graph_title {graph_title} ({tube})')
        print(f'graph_order {" ".join(STATES)}')
        print(f'graph_vlabel {graph_vlabel}')
        for state in STATES:
            print(f'{state}.label {state}')
        print()


def run():
    c = connect()
    tubes = c.list_tubes()
    print_values(tubes, c)


def print_values(tubes, c):
    for tube in tubes:
        print(f'multigraph job_count_{tube}')
        stats = c.stats_tube(tube)
        for state in STATES:
            key = 'current-jobs-' + state
            value = stats[key]
            print(f'{state}.value {value}')
        print()


def main():
    if len(sys.argv) > 1 and sys.argv[1] == "config":
        config()
    else:
        run()


if __name__ == "__main__":
    main()