author | Mahlon E. Smith <mahlon@laika.com> |
Tue, 20 Feb 2018 10:59:26 -0800 | |
changeset 13 | e1777929ba15 |
parent 12 | 450df27eaeec |
child 14 | 717e89280a20 |
permissions | -rw-r--r-- |
1 | 1 |
|
2 |
Netdata-TSRelay |
|
3 |
=============== |
|
4 |
||
5 |
What's this? |
|
6 |
------------ |
|
7 |
||
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 | 12 |
|
13 |
||
14 |
Installation |
|
15 |
------------ |
|
16 |
||
11 | 17 |
You'll need a working [Nim](http://nim-lang.org) build environment and |
18 |
PostgreSQL development headers to compile the binary. |
|
1 | 19 |
|
11 | 20 |
Simply run `make` to build it. Put it wherever you please. |
1 | 21 |
|
22 |
||
23 |
Configuration |
|
24 |
------------- |
|
25 |
||
26 |
There are a few assumptions that should be satisfied before running |
|
11 | 27 |
this successfully. |
1 | 28 |
|
29 |
### Database setup |
|
30 |
||
31 |
You'll need to create the destination table. |
|
32 |
||
33 |
```sql |
|
34 |
CREATE TABLE netdata ( |
|
35 |
time timestamptz default now() not null, |
|
36 |
host text not null, |
|
37 |
metrics jsonb default '{}'::jsonb not null |
|
38 |
); |
|
39 |
``` |
|
40 |
||
11 | 41 |
Index it based on how you intend to query the data, including JSON |
42 |
functional indexing, etc. See PostgreSQL documentation for details. |
|
1 | 43 |
|
44 |
Strongly encouraged: Promote this table to a Timescale "hypertable". |
|
11 | 45 |
See [Timescale](http://timescale.com) docs for that, but a quick example |
46 |
to partition automatically at weekly boundaries would look something |
|
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 | 52 |
|
11 | 53 |
Timescale also has some great examples and advice for efficient [JSON |
54 |
indexing](http://docs.timescale.com/v0.8/using-timescaledb/schema-management#json) |
|
55 |
and queries. |
|
1 | 56 |
|
57 |
||
58 |
### Netdata |
|
59 |
||
60 |
You'll likely want to pare down what netdata is sending. Here's an |
|
11 | 61 |
example configuration for `netdata.conf` -- season this to taste (what |
62 |
charts to send and frequency.) |
|
1 | 63 |
|
64 |
``` |
|
65 |
[backend] |
|
66 |
hostname = your-hostname |
|
67 |
enabled = yes |
|
68 |
type = json |
|
69 |
data source = average |
|
70 |
destination = machine-where-netdata-tsrelay-lives:14866 |
|
71 |
prefix = n |
|
11 | 72 |
update every = 60 |
73 |
buffer on failures = 5 |
|
5 | 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 | 75 |
``` |
76 |
||
11 | 77 |
|
78 |
Running the Relay |
|
79 |
----------------- |
|
80 |
||
81 |
### Options |
|
82 |
||
83 |
* [-q|--quiet]: Quiet mode. No output at all. Ignored if -d is supplied. |
|
84 |
* [-d|--debug]: Debug mode. Show incoming data. |
|
85 |
* [--dbopts]: PostgreSQL connection information. (See below for more details.) |
|
86 |
* [-h|--help]: Display quick help text. |
|
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
87 |
* [--listen-addr]: A specific IP address to listen on. Defaults to **INADDR_ANY**. |
11 | 88 |
* [--listen-port]: The port to listen for netdata JSON streams. |
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
89 |
Default is **14866**. |
11 | 90 |
* [-T|--dbtable]: Change the table name to insert to. Defaults to **netdata**. |
91 |
* [-t|--timeout]: Maximum time in milliseconds to wait for data. Slow |
|
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
92 |
connections may need to increase this from the default **500** ms. |
11 | 93 |
* [-v|--version]: Show version. |
94 |
||
95 |
||
96 |
**Notes** |
|
97 |
||
98 |
Nim option parsing might be slightly different than what you're used to. |
|
99 |
Flags that require arguments must include an '=' or ':' character. |
|
100 |
||
101 |
* --timeout=1000 *valid* |
|
102 |
* --timeout:1000 *valid* |
|
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
103 |
* -t:1000 *valid* |
11 | 104 |
* --timeout 1000 *invalid* |
105 |
* -t 1000 *invalid* |
|
106 |
||
107 |
All database connection options are passed as a key/val string to the |
|
108 |
*dbopts* flag. The default is: |
|
109 |
||
13
e1777929ba15
Remove port and user from the default dbopts, so they instead use the postgresql behavioral default.
Mahlon E. Smith <mahlon@laika.com>
parents:
12
diff
changeset
|
110 |
"host=localhost dbname=netdata application_name=netdata-tsrelay" |
e1777929ba15
Remove port and user from the default dbopts, so they instead use the postgresql behavioral default.
Mahlon E. Smith <mahlon@laika.com>
parents:
12
diff
changeset
|
111 |
|
e1777929ba15
Remove port and user from the default dbopts, so they instead use the postgresql behavioral default.
Mahlon E. Smith <mahlon@laika.com>
parents:
12
diff
changeset
|
112 |
... which uses the default PostgreSQL port, and connects as the running |
e1777929ba15
Remove port and user from the default dbopts, so they instead use the postgresql behavioral default.
Mahlon E. Smith <mahlon@laika.com>
parents:
12
diff
changeset
|
113 |
user. |
11 | 114 |
|
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
115 |
Reference the [PostgreSQL |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
116 |
Documentation](https://www.postgresql.org/docs/current/static/libpq-conn |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
117 |
ect.html#LIBPQ-PARAMKEYWORDS) for all available options (including how |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
118 |
to store passwords in a separate file, enable SSL mode, etc.) |
11 | 119 |
|
120 |
||
121 |
### Daemonizing |
|
122 |
||
123 |
Use a tool of your choice to run this at system |
|
124 |
startup in the background. My personal preference is |
|
125 |
[daemontools](https://cr.yp.to/daemontools.html), but I won't judge you |
|
126 |
if you use something else. |
|
127 |
||
128 |
Here's an example using the simple |
|
129 |
[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: |
|
130 |
||
131 |
# daemon \ |
|
132 |
-o /var/log/netdata_tsrelay.log \ |
|
133 |
-p /var/run/netdata_tsrelay.pid \ |
|
134 |
-u nobody -cr \ |
|
135 |
/usr/local/bin/netdata_tsrelay \ |
|
136 |
--dbopts="dbname=metrics user=metrics host=db-master port=6432 application_name=netdata-tsrelay" |
|
137 |
||
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
138 |
### Scaling |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
139 |
|
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
140 |
Though performant by default, if you're going to be storing a LOT of |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
141 |
data (or have a lot of netdata clients), here are some suggestions for |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
142 |
getting the most bang for your buck: |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
143 |
|
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
144 |
* Use the [pgbouncer](https://pgbouncer.github.io/) connection |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
145 |
pooler. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
146 |
* DNS round robin the hostname where **netdata_tsrelay** lives across |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
147 |
*N* hosts -- you can horizontally scale without any gotchas. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
148 |
* Edit your **netdata.conf** file to only send the metrics you are |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
149 |
interested in. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
150 |
* Decrease the frequency at which netdata sends its data. (When in |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
151 |
"average" mode, it averages over that time automatically.) |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
152 |
* Use [Timescale](http://timescale.com) hypertables. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
153 |
* Add database indexes specific to how you intend to consume the data. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
154 |
* Use the PostgreSQL |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
155 |
[JSON Operators](https://www.postgresql.org/docs/current/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE), |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
156 |
which take advantage of GIN indexing. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
157 |
* Put convenience SQL VIEWs around the data you're fetching later, for |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
158 |
easier graph building with [Grafana](https://grafana.com/) (or whatever.) |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
159 |