189 " sample(s) parsed from ", |
189 " sample(s) parsed from ", |
190 address.hl( fgYellow, bright=true ), |
190 address.hl( fgYellow, bright=true ), |
191 " in ", hl($( round(cpu_time() - t0, 3) ), fgWhite, bright=true), " seconds." |
191 " in ", hl($( round(cpu_time() - t0, 3) ), fgWhite, bright=true), " seconds." |
192 # " ", hl($(round((get_occupied_mem()/1024/1024),1)), fgWhite, bright=true), "MB memory used." |
192 # " ", hl($(round((get_occupied_mem()/1024/1024),1)), fgWhite, bright=true), "MB memory used." |
193 ) |
193 ) |
194 when defined( testing ): dumpNumberOfInstances() |
|
195 |
194 |
196 |
195 |
197 proc serverloop: void = |
196 proc serverloop: void = |
198 ## Open a database connection, bind to the listening socket, |
197 ## Open a database connection, bind to the listening socket, |
199 ## and start serving incoming netdata streams. |
198 ## and start serving incoming netdata streams. |
200 let db = open( "", "", "", conf.dbopts ) |
199 let db = open( "", "", "", conf.dbopts ) |
201 if conf.verbose: echo( "Successfully connected to the backend database.".hl( fgGreen ) ) |
200 if conf.verbose: echo( "Successfully connected to the backend database.".hl( fgGreen ) ) |
202 |
201 |
203 var server = newSocket() |
202 var |
|
203 conn_count = 0 |
|
204 server = newSocket() |
204 |
205 |
205 server.set_sock_opt( OptReuseAddr, true ) |
206 server.set_sock_opt( OptReuseAddr, true ) |
206 server.bind_addr( Port(conf.listen_port), conf.listen_addr ) |
207 server.bind_addr( Port(conf.listen_port), conf.listen_addr ) |
207 server.listen() |
208 server.listen() |
208 |
209 |
217 |
218 |
218 while true: |
219 while true: |
219 var client = newSocket() |
220 var client = newSocket() |
220 var address = "" |
221 var address = "" |
221 |
222 |
|
223 # Force a garbage collection pass. |
|
224 # |
|
225 conn_count = conn_count + 1 |
|
226 if conn_count == 25: |
|
227 when defined( testing ): echo "Forcing GC pass." |
|
228 GC_full_collect() |
|
229 conn_count = 1 |
|
230 |
222 client.close |
231 client.close |
223 server.acceptAddr( client, address ) # blocking call |
232 server.acceptAddr( client, address ) # blocking call |
224 spawn runthread( client, address, db, conf ) |
233 spawn runthread( client, address, db, conf ) |
225 |
234 when defined( testing ): dumpNumberOfInstances() |
226 |
|
227 proc atexit() {.noconv.} = |
|
228 ## Exit cleanly after waiting on any running threads. |
|
229 echo "Exiting..." |
|
230 sync() |
|
231 quit( 0 ) |
|
232 |
235 |
233 |
236 |
234 proc parse_cmdline: void = |
237 proc parse_cmdline: void = |
235 ## Populate the config object with the user's preferences. |
238 ## Populate the config object with the user's preferences. |
236 |
239 |