~iacobs/gstats/main

« back to all changes in this revision

Viewing changes to scripts/gstatsctl

  • Committer: GitHub
  • Author(s): Sabin Iacob
  • Date: 2019-12-17 14:14:59 UTC
  • mfrom: (53.1.13)
  • Revision ID: git-v1:1596c4477eb98ad96a164c4b66a6cccbf8742e62
Merge pull request #2 from spapas/master

Python 3.x release

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
    def send_command(self, cmd, get_answer=True):
74
74
        comm = self.context.socket(zmq.REQ)
75
75
        comm.connect(self.addr)
76
 
        comm.send(cmd.upper())
 
76
        comm.send(str.encode(cmd.upper()))
77
77
 
78
78
        if get_answer:
79
79
            return comm.recv_json()
89
89
        stats = self.send_command('stats')
90
90
 
91
91
        for prefix, data in stats.items():
92
 
            print prefix
93
 
            print '=' * len(prefix)
94
 
            print 'Requests: started=%s, finished=%s, processing=%s' % (data['started'], data['finished'], int(data['started']) - int(data['finished']))
95
 
            print 'Response time: average=%s, stdev=%s' % (data['processing_time']['avg'], data['processing_time']['std'])
96
 
            print ''
 
92
            print(prefix)
 
93
            print('=' * len(prefix))
 
94
            print('Requests: started=%s, finished=%s, processing=%s' % (data['started'], data['finished'], int(data['started']) - int(data['finished'])))
 
95
            print('Response time: average=%s, stdev=%s' % (data['processing_time']['avg'], data['processing_time']['std']))
 
96
            print('')
97
97
 
98
98
    def handle_rtimes(self, prefix):
99
99
        """ usage: %prog rtimes <prefix> """
100
100
        rtimes = self.send_command('rtimes')
101
101
 
102
 
        print '\n'.join(map(str, rtimes.get(prefix, [])))
 
102
        print ('\n'.join(map(str, rtimes.get(prefix, []))))
103
103
 
104
104
    def handle_reset(self):
105
105
        """ usage: %prog reset """
129
129
    except (NoSuchCommand, TypeError):
130
130
        parser.print_help()
131
131
        exit(1)
132
 
    except CommandError, e:
133
 
        print str(e).replace('%prog', parser.prog)
 
132
    except CommandError as e:
 
133
        print (str(e).replace('%prog', parser.prog))
134
134
        exit(2)