equal
deleted
inserted
replaced
44 |
44 |
45 |
45 |
46 const |
46 const |
47 VERSION = "v0.2.0" |
47 VERSION = "v0.2.0" |
48 USAGE = """ |
48 USAGE = """ |
49 ./netdata_tsrelay [-q][-v][-h] --dbopts="[PostgreSQL connection string]" --listen-port=14866 --listen-addr=0.0.0.0 |
49 ./netdata_tsrelay [-d][-h][-q][-t][-T][-v] --dbopts="[PostgreSQL connection string]" --listen-port=14866 --listen-addr=0.0.0.0 |
50 |
50 |
51 -q: Quiet mode. No output at all. Ignored if -d is supplied. |
51 -q: Quiet mode. No output at all. Ignored if -d is supplied. |
52 -d: Debug: Show incoming and parsed data. |
52 -d: Debug: Show incoming and parsed data. |
53 -v: Display version number. |
53 -v: Display version number. |
54 -T: Change the destination table name from the default 'netdata'. |
54 -T: Change the destination table name from the default 'netdata'. |
92 |
92 |
93 |
93 |
94 proc fetch_data( client: Socket ): string = |
94 proc fetch_data( client: Socket ): string = |
95 ## Netdata JSON backend doesn't send a length, so we read line by |
95 ## Netdata JSON backend doesn't send a length, so we read line by |
96 ## line and wait for stream timeout to determine a "sample". |
96 ## line and wait for stream timeout to determine a "sample". |
97 var buf: string = "" |
97 var buf = "" |
98 try: |
98 try: |
99 result = client.recv_line( timeout=conf.timeout ) |
99 while true: |
100 if result != "": result = result & "\n" |
100 client.readline( buf, timeout=conf.timeout ) |
101 while buf != "": |
|
102 buf = client.recv_line( timeout=conf.timeout ) |
|
103 if buf != "": result = result & buf & "\n" |
101 if buf != "": result = result & buf & "\n" |
104 except TimeoutError: |
102 except TimeoutError: |
105 discard |
103 return |
106 |
104 |
107 |
105 |
108 proc parse_data( data: string ): seq[ JsonNode ] = |
106 proc parse_data( data: string ): seq[ JsonNode ] = |
109 ## Given a raw +data+ string, parse JSON and return a sequence |
107 ## Given a raw +data+ string, parse JSON and return a sequence |
110 ## of JSON samples. Netdata can buffer multiple samples in one batch. |
108 ## of JSON samples. Netdata can buffer multiple samples in one batch. |