README.md
author Mahlon E. Smith <mahlon@laika.com>
Mon, 19 Feb 2018 18:22:25 -0800
changeset 11 475c9942eb15
parent 10 252cdb26f76b
child 12 450df27eaeec
permissions -rw-r--r--
Multiple changes: - Make the 'release' build the default. - Add a configurable socket timeout parameter. - Make the table name configurable. - Add usage docs to the README.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     2
Netdata-TSRelay
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     3
===============
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     4
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     5
What's this?
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     6
------------
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     7
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
     8
This program is designed to accept JSON streams from
10
252cdb26f76b Fix the netdata link to point the the right spot.
Mahlon E. Smith <mahlon@laika.com>
parents: 5
diff changeset
     9
[Netdata](https://my-netdata.io/) clients, and write metrics to a
252cdb26f76b Fix the netdata link to point the the right spot.
Mahlon E. Smith <mahlon@laika.com>
parents: 5
diff changeset
    10
PostgreSQL table - specifically, [Timescale](http://timescale.com)
252cdb26f76b Fix the netdata link to point the the right spot.
Mahlon E. Smith <mahlon@laika.com>
parents: 5
diff changeset
    11
backed tables (though that's not technically a requirement.)
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    12
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    13
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    14
Installation
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    15
------------
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    16
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    17
You'll need a working [Nim](http://nim-lang.org) build environment and
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    18
PostgreSQL development headers to compile the binary.
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    19
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    20
Simply run `make` to build it.  Put it wherever you please.
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    21
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    22
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    23
Configuration
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    24
-------------
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    25
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    26
There are a few assumptions that should be satisfied before running
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    27
this successfully.
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    28
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    29
### Database setup
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    30
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    31
You'll need to create the destination table.
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    32
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    33
```sql
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    34
CREATE TABLE netdata (
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    35
	time timestamptz default now() not null,
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    36
	host text not null,
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    37
	metrics jsonb default '{}'::jsonb not null
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    38
);
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    39
```
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    40
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    41
Index it based on how you intend to query the data, including JSON
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    42
functional indexing, etc.  See PostgreSQL documentation for details.
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    43
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    44
Strongly encouraged:  Promote this table to a Timescale "hypertable".
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    45
See [Timescale](http://timescale.com) docs for that, but a quick example
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    46
to partition automatically at weekly boundaries would look something
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    47
like:
3
f34855556f4d Add timescale creation example.
Mahlon E. Smith <mahlon@laika.com>
parents: 1
diff changeset
    48
f34855556f4d Add timescale creation example.
Mahlon E. Smith <mahlon@laika.com>
parents: 1
diff changeset
    49
```sql
f34855556f4d Add timescale creation example.
Mahlon E. Smith <mahlon@laika.com>
parents: 1
diff changeset
    50
SELECT create_hypertable( 'netdata', 'time', chunk_time_interval => 604800000000 );
f34855556f4d Add timescale creation example.
Mahlon E. Smith <mahlon@laika.com>
parents: 1
diff changeset
    51
```
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    52
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    53
Timescale also has some great examples and advice for efficient [JSON
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    54
indexing](http://docs.timescale.com/v0.8/using-timescaledb/schema-management#json)
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    55
and queries.
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    56
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    57
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    58
### Netdata
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    59
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    60
You'll likely want to pare down what netdata is sending.  Here's an
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    61
example configuration for `netdata.conf` -- season this to taste (what
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    62
charts to send and frequency.)
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    63
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    64
```
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    65
[backend]
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    66
    hostname           = your-hostname
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    67
    enabled            = yes
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    68
    type               = json
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    69
    data source        = average
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    70
    destination        = machine-where-netdata-tsrelay-lives:14866
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    71
    prefix             = n
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    72
    update every       = 60
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    73
    buffer on failures = 5
5
a1276c3d39eb Multiple changes.
Mahlon E. Smith <mahlon@laika.com>
parents: 3
diff changeset
    74
    send charts matching = !cpu.cpu* !ipv6* !users* nfs.rpc net.* net_drops.* net_packets.* !system.interrupts* system.* disk.* disk_space.* disk_ops.* mem.*
1
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    75
```
160338bb2822 Add README.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff changeset
    76
11
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    77
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    78
Running the Relay
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    79
-----------------
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    80
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    81
### Options
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    82
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    83
  * [-q|--quiet]:    Quiet mode.  No output at all. Ignored if -d is supplied.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    84
  * [-d|--debug]:    Debug mode.  Show incoming data.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    85
  * [--dbopts]:      PostgreSQL connection information.  (See below for more details.)
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    86
  * [-h|--help]:     Display quick help text.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    87
  * [--listen-addr]: A specific IP address to listen on.  Defaults to INADDR_ANY.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    88
  * [--listen-port]: The port to listen for netdata JSON streams.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    89
                     Default is 14866.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    90
  * [-T|--dbtable]:  Change the table name to insert to.  Defaults to **netdata**.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    91
  * [-t|--timeout]:  Maximum time in milliseconds to wait for data.  Slow
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    92
                     connections may need to increase this from the default 500 ms.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    93
  * [-v|--version]:  Show version.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    94
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    95
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    96
**Notes**
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    97
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    98
Nim option parsing might be slightly different than what you're used to.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
    99
Flags that require arguments must include an '=' or ':' character.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   100
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   101
  * --timeout=1000  *valid*
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   102
  * --timeout:1000  *valid*
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   103
  * --t:1000  *valid*
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   104
  * --timeout 1000  *invalid*
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   105
  * -t 1000  *invalid*
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   106
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   107
All database connection options are passed as a key/val string to the
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   108
*dbopts* flag.  The default is:
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   109
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   110
	"host=localhost port=5432 dbname=netdata user=netdata application_name=netdata-tsrelay"
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   111
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   112
Reference
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   113
https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   114
PARAMKEYWORDS for all available options (including how to store
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   115
passwords in a seperate file, enable SSL mode, etc.)
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   116
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   117
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   118
### Daemonizing
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   119
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   120
Use a tool of your choice to run this at system
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   121
startup in the background.  My personal preference is
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   122
[daemontools](https://cr.yp.to/daemontools.html), but I won't judge you
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   123
if you use something else.
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   124
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   125
Here's an example using the simple
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   126
[daemon](https://www.freebsd.org/cgi/man.cgi?query=daemon&apropos=0&sektion=8&manpath=FreeBSD+11.0-RELEASE+and+Ports&arch=default&format=html) wrapper tool:
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   127
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   128
	# daemon \
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   129
		-o /var/log/netdata_tsrelay.log \
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   130
		-p /var/run/netdata_tsrelay.pid \
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   131
		-u nobody -cr \
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   132
		/usr/local/bin/netdata_tsrelay \
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   133
			--dbopts="dbname=metrics user=metrics host=db-master port=6432 application_name=netdata-tsrelay"
475c9942eb15 Multiple changes:
Mahlon E. Smith <mahlon@laika.com>
parents: 10
diff changeset
   134