Projet

Général

Profil

Révision 58c7801f

ID58c7801fd2d2f466edf30ff0a90fa35a24b787dd
Parent b6912e76
Enfant 375d3643

Ajouté par lifeofguenter il y a plus de 4 ans

beanstalkd python3

Voir les différences:

plugins/other/beanstalkd
1
#!/usr/bin/env python
1
#!/usr/bin/env python3
2 2

  
3
import sys, re
4
from beanstalk import serverconn, protohandler
3
import os
4
import sys
5 5

  
6
# Temporary workaround until my patch is merged.
7
if not protohandler._namematch.match('ABZDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+/;.$_()'):
8
    protohandler._namematch = re.compile(r'^[a-zA-Z0-9+\(\)/;.$_][a-zA-Z0-9+\(\)/;.$_-]{0,199}$')
6
from pystalk import BeanstalkClient
9 7

  
10 8
STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried']
11 9

  
12
def connect(host='localhost', port=11300):
13
    return serverconn.ServerConn(host, port)
10

  
11
def connect():
12
    return BeanstalkClient(
13
        os.getenv('host', 'localhost'),
14
        os.getenv('port', '11300'),
15
    )
16

  
14 17

  
15 18
def config():
16 19
    c = connect()
17
    tubes = c.list_tubes()['data']
20
    tubes = c.list_tubes()
18 21
    print_config(tubes)
19 22

  
23

  
20 24
def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'):
21 25
    for tube in tubes:
22
        print 'multigraph job_count_' + tube
23
        print 'graph_title %s (%s)' % (graph_title, tube,)
24
        print 'graph_order ' + ' '.join(STATES)
25
        print 'graph_vlabel ' + graph_vlabel
26
        print(f'multigraph job_count_{tube}')
27
        print(f'graph_title {graph_title} ({tube})')
28
        print(f'graph_order {" ".join(STATES)}')
29
        print(f'graph_vlabel {graph_vlabel}')
26 30
        for state in STATES:
27
            print '%s.label %s' % (state, state,)
28
        print
31
            print(f'{state}.label {state}')
32
        print()
33

  
29 34

  
30 35
def run():
31 36
    c = connect()
32
    tubes = c.list_tubes()['data']
37
    tubes = c.list_tubes()
33 38
    print_values(tubes, c)
34 39

  
40

  
35 41
def print_values(tubes, c):
36 42
    for tube in tubes:
37
        print 'multigraph job_count_' + tube
38
        stats = c.stats_tube(tube)['data']
43
        print(f'multigraph job_count_{tube}')
44
        stats = c.stats_tube(tube)
39 45
        for state in STATES:
40 46
            key = 'current-jobs-' + state
41 47
            value = stats[key]
42
            print '%s.value %d' % (state, value,)
43
        print
48
            print(f'{state}.value {value}')
49
        print()
50

  
44 51

  
45 52
def main():
46 53
    if len(sys.argv) > 1 and sys.argv[1] == "config":
......
48 55
    else:
49 56
        run()
50 57

  
58

  
51 59
if __name__ == "__main__":
52 60
    main()

Formats disponibles : Unified diff