This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
push_graphite_formatted_data.py
65 lines (56 loc) · 1.9 KB
/
push_graphite_formatted_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
import os
import re
import sys
import time
import socket
import platform
import subprocess
import pickle
import struct
from perfvizutils import print_progress
CARBON_SERVER = os.getenv('CARBON_SERVER', 'perfviz')
CARBON_PICKLE_PORT = os.getenv('CARBON_PICKLE_PORT', 2004)
MAX_BUFFER_SIZE = int( os.getenv('MAX_BUFFER_SIZE', 1000) )
SLEEP_INTERVAL = float( os.getenv('SLEEP_INTERVAL', 0) )
def run(sock, file):
"""Make the client go go go"""
with open(file) as fp:
tuples = ([])
line_count = 0
for line in fp:
line_count += 1;
entries = line.split()
if len(entries) == 3:
tuples.append((entries[0], (entries[2], entries[1])))
else:
print ("bad line: %s" % line)
if line_count % MAX_BUFFER_SIZE == 0:
package = pickle.dumps(tuples, 1)
size = struct.pack('!L', len(package))
sock.sendall(size)
sock.sendall(package)
time.sleep(SLEEP_INTERVAL)
print_progress(line_count)
tuples = ([])
package = pickle.dumps(tuples, 1)
size = struct.pack('!L', len(package))
sock.sendall(size)
sock.sendall(package)
print_progress(line_count)
def main():
"""Wrap it all up together"""
if len(sys.argv) <= 1:
raise SystemExit("usage %s <datafile>" % sys.argv[0])
sock = socket.socket()
try:
sock.connect( (CARBON_SERVER, CARBON_PICKLE_PORT) )
except socket.error:
raise SystemExit("Couldn't connect to %(server)s on port %(port)d, is carbon-cache.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PICKLE_PORT })
try:
run(sock, sys.argv[1])
except KeyboardInterrupt:
sys.stderr.write("\nExiting on CTRL-c\n")
sys.exit(0)
if __name__ == "__main__":
main()