netdata_tsrelay.nim
author Mahlon E. Smith <mahlon@laika.com>
Sun, 18 Feb 2018 18:16:37 -0800
changeset 8 1ef3f2d6d10e
parent 7 c0bcf3bea772
child 9 aa9d537f7067
permissions -rw-r--r--
Multiple changes. - There's still a delay somewhere with threading in the socket read() that impacts simultaneous client connections. After a bunch of experimenting with Channel message passing, rip it all out in favor of a simple fork()ing server. - Remove the color option, just check stdout for a tty instead to make it automatic. - Better error handling for malformed packets/samples.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
     1
# vim: set et nosta sw=4 ts=4 :
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
     2
# im: set et nosta sw=4 ts=4 ft=nim : 
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     3
#
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     4
# Copyright (c) 2018, Mahlon E. Smith <mahlon@martini.nu>
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     5
# All rights reserved.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     6
# Redistribution and use in source and binary forms, with or without
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     7
# modification, are permitted provided that the following conditions are met:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     8
#
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     9
#     * Redistributions of source code must retain the above copyright
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    10
#       notice, this list of conditions and the following disclaimer.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    11
#
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    12
#     * Redistributions in binary form must reproduce the above copyright
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    13
#       notice, this list of conditions and the following disclaimer in the
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    14
#       documentation and/or other materials provided with the distribution.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    15
#
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    16
#     * Neither the name of Mahlon E. Smith nor the names of his
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    17
#       contributors may be used to endorse or promote products derived
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    18
#       from this software without specific prior written permission.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    19
#
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    20
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    21
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    22
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    23
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    24
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    25
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    26
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    27
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    28
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    29
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    30
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    31
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    32
import
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    33
    db_postgres,
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    34
    json,
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    35
    math,
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    36
    nativesockets,
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    37
    net,
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    38
    os,
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    39
    parseopt2,
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    40
    posix,
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    41
    strutils,
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    42
    tables,
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    43
    terminal,
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    44
    times
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    45
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    46
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    47
const
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    48
    VERSION = "v0.1.0"
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    49
    USAGE = """
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    50
./netdata_tsrelay [-q][-v][-h] --dbopts="[PostgreSQL connection string]" --listen-port=14866 --listen-addr=0.0.0.0
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    51
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    52
  -q: Quiet mode.  No output at all.  Ignored if -d is supplied.
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    53
  -d: Debug: Show incoming and parsed data.
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    54
  -v: Display version number.
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    55
  -h: Help.  You're lookin' at it.
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    56
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    57
The default connection string is:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    58
  "host=localhost port=5432 dbname=netdata user=netdata application_name=netdata-tsrelay"
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    59
    """
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    60
    INSERT_SQL = """
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    61
    INSERT INTO netdata
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    62
        ( time, host, metrics )
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    63
    VALUES
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    64
        ( 'epoch'::timestamptz + ? * '1 second'::interval, ?, ? )
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    65
    """
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    66
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    67
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    68
type
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    69
    Config = object of RootObj
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    70
        dbopts:      string  # The postgresql connection parameters.  (See https://www.postgresql.org/docs/current/static/libpq-connect.html)
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    71
        listen_port: int     # The port to listen for incoming connections
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    72
        listen_addr: string  # The IP address listen for incoming connections.  Defaults to inaddr_any.
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    73
        verbose:     bool    # Be informative
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    74
        debug:       bool    # Spew out raw data
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    75
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    76
# Global configuration
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    77
var conf: Config
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    78
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    79
proc hl( msg: string, fg: ForegroundColor, bright=false ): string =
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    80
    ## Quick wrapper for color formatting a string, since the 'terminal'
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    81
    ## module only deals with stdout directly.
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    82
    if not isatty(stdout): return msg
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    83
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    84
    var color: BiggestInt = ord( fg )
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    85
    if bright: inc( color, 60 )
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    86
    result = "\e[" & $color & 'm' & msg & "\e[0m"
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    87
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
    88
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    89
proc fetch_data( client: Socket ): string =
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    90
    ## Netdata JSON backend doesn't send a length, so we read line by
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    91
    ## line and wait for stream timeout to determine a "sample".
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    92
    var buf: string = nil
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    93
    try:
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    94
        result = client.recv_line( timeout=500 )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    95
        if result != "" and not result.is_nil: result = result & "\n"
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    96
        while buf != "":
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    97
            buf = client.recv_line( timeout=500 )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
    98
            if buf != "" and not buf.is_nil: result = result & buf & "\n"
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    99
    except TimeoutError:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   100
        discard
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   101
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   102
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   103
proc parse_data( data: string ): seq[ JsonNode ] =
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   104
    ## Given a raw +data+ string, parse JSON and return a sequence
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   105
    ## of JSON samples. Netdata can buffer multiple samples in one batch.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   106
    result = @[]
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   107
    if data == "" or data.is_nil: return
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   108
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   109
    # Hash of sample timeperiods to pivoted json data
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   110
    var pivoted_data = init_table[ BiggestInt, JsonNode ]()
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   111
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   112
    for sample in split_lines( data ):
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   113
        if sample == "" or sample.is_nil: continue
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   114
        #if conf.debug: echo sample.hl( fgBlack, bright=true )
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   115
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   116
        var parsed: JsonNode
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   117
        try:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   118
            parsed = sample.parse_json
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   119
        except JsonParsingError:
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   120
            if conf.debug: echo hl( "Unable to parse sample line: " & sample.hl(fgRed, bright=true), fgRed )
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   121
            continue
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   122
        if parsed.kind != JObject: return
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   123
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   124
        # Create or use existing Json object for modded data.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   125
        #
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   126
        var pivot: JsonNode
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   127
        try:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   128
            let key = parsed["timestamp"].get_num
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   129
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   130
            if pivoted_data.has_key( key ):
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   131
                pivot = pivoted_data[ key ]
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   132
            else:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   133
                pivot = newJObject()
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   134
                pivoted_data[ key ] = pivot
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   135
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   136
            var name = parsed[ "chart_id" ].get_str & "." & parsed[ "id" ].get_str
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   137
            pivot[ "hostname" ] = parsed[ "hostname" ]
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   138
            pivot[ "timestamp" ] = parsed[ "timestamp" ]
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   139
            pivot[ name ] = parsed[ "value" ]
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   140
        except:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   141
            continue
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   142
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   143
    for timestamp, sample in pivoted_data:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   144
        result.add( sample )
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   145
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   146
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   147
proc write_to_database( samples: seq[ JsonNode ] ): void =
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   148
    ## Given a sequence of json samples, write them to database.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   149
    if samples.len == 0: return
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   150
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   151
    let db = open( "", "", "", conf.dbopts )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   152
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   153
    try:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   154
        db.exec sql( "BEGIN" )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   155
        for sample in samples:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   156
            var
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   157
                timestamp = sample[ "timestamp" ].get_num
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   158
                host = sample[ "hostname" ].get_str
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   159
            sample.delete( "timestamp" )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   160
            sample.delete( "hostname" )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   161
            db.exec sql( INSERT_SQL ), timestamp, host, sample
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   162
        db.exec sql( "COMMIT" )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   163
    except:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   164
        let
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   165
            e = getCurrentException()
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   166
            msg = getCurrentExceptionMsg()
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   167
        echo "Got exception ", repr(e), " while writing to DB: ", msg
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   168
        discard
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   169
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   170
    db.close
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   171
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   172
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   173
proc process( client: Socket, address: string ): void =
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   174
    ## Do the work for a connected client within a thread.
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   175
    ## Returns the formatted json data keyed on sample time.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   176
    let t0 = cpu_time()
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   177
    var raw_data = client.fetch_data
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   178
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   179
    # Done with the socket, netdata will automatically
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   180
    # reconnect.  Save local resources/file descriptors
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   181
    # by closing after the send is considered complete.
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   182
    #
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   183
    try:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   184
        client.close
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   185
    except OSError:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   186
        return
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   187
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   188
    # Pivot the parsed data to a single JSON blob per sample time.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   189
    var samples = parse_data( raw_data )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   190
    write_to_database( samples )
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   191
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   192
    if conf.verbose:
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   193
        echo(
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   194
            hl( $(epochTime().to_int), fgMagenta, bright=true ),
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   195
            " ",
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   196
            hl( $(samples.len), fgWhite, bright=true ),
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   197
            " sample(s) parsed from ",
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   198
            address.hl( fgYellow, bright=true ),
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   199
            " in ", hl($( round(cpu_time() - t0, 3) ), fgWhite, bright=true), " seconds."
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   200
            # " ", hl($(round((get_occupied_mem()/1024/1024),1)), fgWhite, bright=true), "MB memory used."
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   201
        )
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   202
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   203
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   204
proc serverloop( conf: Config ): void =
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   205
    ## Open a database connection, bind to the listening socket,
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   206
    ## and start serving incoming netdata streams.
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   207
    let db = open( "", "", "", conf.dbopts )
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   208
    if conf.verbose: echo( "Successfully tested connection to the backend database.".hl( fgGreen ) )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   209
    db.close
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   210
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   211
    # Setup listening socket.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   212
    #
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   213
    var server = newSocket()
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   214
    server.set_sock_opt( OptReuseAddr, true )
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   215
    server.bind_addr( Port(conf.listen_port), conf.listen_addr )
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   216
    server.listen()
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   217
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   218
    if conf.verbose:
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   219
        echo(
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   220
            "Listening for incoming connections on ".hl( fgGreen, bright=true ),
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   221
            hl( (if conf.listen_addr == "0.0.0.0": "*" else: conf.listen_addr) , fgBlue, bright=true ),
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   222
            ":",
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   223
            hl( $conf.listen_port, fgBlue, bright=true ),
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   224
        )
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   225
        echo ""
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   226
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   227
    # Wait for incoming connections, fork for each client.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   228
    #
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   229
    while true:
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   230
        var
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   231
            client  = new Socket
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   232
            address = ""
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   233
            status: cint = 0
6
1f366fc61592 Each incoming connection requires its own client socket.
Mahlon E. Smith <mahlon@laika.com>
parents: 5
diff changeset
   234
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   235
        server.acceptAddr( client, address ) # block
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   236
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   237
        if fork() == 0:
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   238
            server.close
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   239
            client.process( address )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   240
            quit( 0 )
7
c0bcf3bea772 Force a GC pass after 25 cycles. Don't bother with sync() at exit, unnecessary.
Mahlon E. Smith <mahlon@laika.com>
parents: 6
diff changeset
   241
6
1f366fc61592 Each incoming connection requires its own client socket.
Mahlon E. Smith <mahlon@laika.com>
parents: 5
diff changeset
   242
        client.close
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   243
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   244
        discard waitpid( P_ALL, status, WNOHANG ) # reap all previous children
7
c0bcf3bea772 Force a GC pass after 25 cycles. Don't bother with sync() at exit, unnecessary.
Mahlon E. Smith <mahlon@laika.com>
parents: 6
diff changeset
   245
        when defined( testing ): dumpNumberOfInstances()
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   246
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   247
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   248
proc parse_cmdline: Config =
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   249
    ## Populate the config object with the user's preferences.
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   250
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   251
    # Config object defaults.
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   252
    #
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   253
    result = Config(
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   254
        dbopts: "host=localhost port=5432 dbname=netdata user=netdata application_name=netdata-tsrelay",
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   255
        listen_port: 14866,
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   256
        listen_addr: "0.0.0.0",
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   257
        verbose: true,
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   258
        debug: false
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   259
    )
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   260
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   261
    # always set debug mode if development build.
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   262
    result.debug = defined( testing )
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   263
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   264
    for kind, key, val in getopt():
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   265
        case kind
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   266
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   267
        of cmdArgument:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   268
            discard
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   269
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   270
        of cmdLongOption, cmdShortOption:
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   271
            case key
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   272
                of "debug", "d":
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   273
                    result.debug = true
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   274
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   275
                of "help", "h":
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   276
                    echo USAGE
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   277
                    quit( 0 )
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   278
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   279
                of "quiet", "q":
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   280
                    result.verbose = false
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   281
            
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   282
                of "version", "v":
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   283
                    echo hl( "netdata_tsrelay " & VERSION, fgWhite, bright=true )
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   284
                    quit( 0 )
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   285
               
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   286
                of "dbopts": result.dbopts = val
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   287
                of "listen-addr", "a": result.listen_addr = val
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   288
                of "listen-port", "p": result.listen_port = val.parse_int
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   289
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   290
                else: discard
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   291
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   292
        of cmdEnd: assert( false ) # shouldn't reach here ever
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   293
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   294
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   295
when isMainModule:
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   296
    system.addQuitProc( resetAttributes )
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   297
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   298
    conf = parse_cmdline()
7
c0bcf3bea772 Force a GC pass after 25 cycles. Don't bother with sync() at exit, unnecessary.
Mahlon E. Smith <mahlon@laika.com>
parents: 6
diff changeset
   299
    if conf.debug: echo hl( $conf, fgYellow )
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 4
diff changeset
   300
8
1ef3f2d6d10e Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 7
diff changeset
   301
    serverloop( conf )
0
72c9c6f0b713 Initial commit.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
   302