author | Mahlon E. Smith <mahlon@laika.com> |
Thu, 10 Dec 2020 17:20:37 -0800 | |
changeset 21 | a2fe9ec4cdf2 |
parent 19 | 1f09cfb560e0 |
child 25 | 970ca83c849b |
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 |
|
14
717e89280a20
Update README Timescale example for v0.9.0.
Mahlon E. Smith <mahlon@laika.com>
parents:
13
diff
changeset
|
47 |
like this, if you're running v0.9.0 or better: |
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 |
14
717e89280a20
Update README Timescale example for v0.9.0.
Mahlon E. Smith <mahlon@laika.com>
parents:
13
diff
changeset
|
50 |
SELECT create_hypertable( 'netdata', 'time', migrate_data => true, chunk_time_interval => '1 week'::interval ); |
3
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 |
|
19 | 61 |
example configuration for `exporting.conf` -- season this to taste (what |
11 | 62 |
charts to send and frequency.) |
1 | 63 |
|
19 | 64 |
Note: This example uses the "exporting" module introduced in |
65 |
Netdata v1.23. If your netdata is older than that, you'll be using |
|
66 |
the deprecated "backend" instead in the main `netdata.conf` file. |
|
67 |
||
1 | 68 |
``` |
19 | 69 |
[exporting:global] |
21
a2fe9ec4cdf2
Fix docs: exporting.conf example and help verbose/version typo.
Mahlon E. Smith <mahlon@laika.com>
parents:
19
diff
changeset
|
70 |
enabled = yes |
a2fe9ec4cdf2
Fix docs: exporting.conf example and help verbose/version typo.
Mahlon E. Smith <mahlon@laika.com>
parents:
19
diff
changeset
|
71 |
hostname = your-hostname |
19 | 72 |
|
73 |
[json:timescale] |
|
74 |
enabled = yes |
|
75 |
data source = average |
|
76 |
destination = localhost:14866 |
|
77 |
prefix = netdata |
|
78 |
update every = 10 |
|
79 |
buffer on failures = 10 |
|
80 |
send charts matching = !cpu.cpu* !ipv6* !users.* nfs.rpc net.* net_drops.* net_packets.* !system.interrupts* system.* disk.* disk_space.* disk_ops.* mem.* |
|
1 | 81 |
``` |
82 |
||
11 | 83 |
|
84 |
Running the Relay |
|
85 |
----------------- |
|
86 |
||
87 |
### Options |
|
88 |
||
89 |
* [-q|--quiet]: Quiet mode. No output at all. Ignored if -d is supplied. |
|
90 |
* [-d|--debug]: Debug mode. Show incoming data. |
|
19 | 91 |
* [-D|--dropconn]: Drop the TCP connection to netdata between samples. |
92 |
This may be more efficient depending on your environment and |
|
93 |
number of clients. Defaults to false. |
|
94 |
* [-o|--dbopts]: PostgreSQL connection information. (See below for more details.) |
|
11 | 95 |
* [-h|--help]: Display quick help text. |
19 | 96 |
* [-a|--listen-addr]: A specific IP address to listen on. Defaults to **INADDR_ANY**. |
97 |
* [-p|--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
|
98 |
Default is **14866**. |
19 | 99 |
* [-P|--persistent]: Don't disconnect from the database between samples. This may be |
100 |
more efficient with a small number of clients, when not using a |
|
101 |
pooler, or with a very high sample size/rate. Defaults to false. |
|
11 | 102 |
* [-T|--dbtable]: Change the table name to insert to. Defaults to **netdata**. |
103 |
* [-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
|
104 |
connections may need to increase this from the default **500** ms. |
11 | 105 |
* [-v|--version]: Show version. |
106 |
||
107 |
||
19 | 108 |
|
11 | 109 |
**Notes** |
110 |
||
111 |
Nim option parsing might be slightly different than what you're used to. |
|
112 |
Flags that require arguments must include an '=' or ':' character. |
|
113 |
||
114 |
* --timeout=1000 *valid* |
|
115 |
* --timeout:1000 *valid* |
|
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
116 |
* -t:1000 *valid* |
11 | 117 |
* --timeout 1000 *invalid* |
118 |
* -t 1000 *invalid* |
|
119 |
||
120 |
All database connection options are passed as a key/val string to the |
|
121 |
*dbopts* flag. The default is: |
|
122 |
||
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
|
123 |
"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
|
124 |
|
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
|
125 |
... 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
|
126 |
user. |
11 | 127 |
|
19 | 128 |
Reference the [PostgreSQL Documentation](https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS) |
129 |
for all available options (including how to store passwords in a |
|
130 |
separate file, enable SSL mode, etc.) |
|
11 | 131 |
|
132 |
||
133 |
### Daemonizing |
|
134 |
||
135 |
Use a tool of your choice to run this at system |
|
136 |
startup in the background. My personal preference is |
|
137 |
[daemontools](https://cr.yp.to/daemontools.html), but I won't judge you |
|
138 |
if you use something else. |
|
139 |
||
140 |
Here's an example using the simple |
|
141 |
[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: |
|
142 |
||
143 |
# daemon \ |
|
144 |
-o /var/log/netdata_tsrelay.log \ |
|
145 |
-p /var/run/netdata_tsrelay.pid \ |
|
146 |
-u nobody -cr \ |
|
147 |
/usr/local/bin/netdata_tsrelay \ |
|
148 |
--dbopts="dbname=metrics user=metrics host=db-master port=6432 application_name=netdata-tsrelay" |
|
149 |
||
12
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
150 |
### Scaling |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
151 |
|
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
getting the most bang for your buck: |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
155 |
|
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
156 |
* 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
|
157 |
pooler. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
158 |
* 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
|
159 |
*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
|
160 |
* 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
|
161 |
interested in. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
162 |
* 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
|
163 |
"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
|
164 |
* Use [Timescale](http://timescale.com) hypertables. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
165 |
* 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
|
166 |
* Use the PostgreSQL |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
167 |
[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
|
168 |
which take advantage of GIN indexing. |
450df27eaeec
Fix typos, add small "scaling" section.
Mahlon E. Smith <mahlon@laika.com>
parents:
11
diff
changeset
|
169 |
* 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
|
170 |
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
|
171 |