@@ -326,20 +326,23 @@ Follow the setup instructions of `openwisp-controller
326
326
327
327
# Make sure you change them in production
328
328
# You can select one of the backends located in openwisp_monitoring.db.backends
329
- TIMESERIES_DATABASE = {
329
+ INFLUXDB_1x_DATABASE = {
330
330
' BACKEND' : ' openwisp_monitoring.db.backends.influxdb' ,
331
331
' USER' : ' openwisp' ,
332
332
' PASSWORD' : ' openwisp' ,
333
333
' NAME' : ' openwisp2' ,
334
- ' HOST' : ' localhost ' ,
334
+ ' HOST' : ' influxdb ' ,
335
335
' PORT' : ' 8086' ,
336
- ' OPTIONS' : {
337
- # Specify additional options to be used while initializing
338
- # database connection.
339
- # Note: These options may differ based on the backend used.
340
- ' udp_writes' : True ,
341
- ' udp_port' : 8089 ,
342
- }
336
+ ' OPTIONS' : {' udp_writes' : False , ' udp_port' : 8089 },
337
+ }
338
+
339
+ INFLUXDB_2x_DATABASE = {
340
+ ' BACKEND' : ' openwisp_monitoring.db.backends.influxdb2' ,
341
+ ' TOKEN' : ' my-super-secret-auth-token' ,
342
+ ' ORG' : ' openwisp' ,
343
+ ' BUCKET' : ' openwisp2' ,
344
+ ' HOST' : ' influxdb2' ,
345
+ ' PORT' : ' 9999' ,
343
346
}
344
347
345
348
``urls.py ``:
@@ -1413,56 +1416,109 @@ Settings
1413
1416
| **default **: | see below |
1414
1417
+--------------+-----------+
1415
1418
1419
+ Timeseries Database Configuration
1420
+ ---------------------------------
1421
+
1422
+ The ``TIMESERIES_DATABASE `` setting allows configuring the timeseries
1423
+ database backend used by OpenWISP Monitoring. The configuration supports
1424
+ both InfluxDB 1.x and 2.x versions.
1425
+
1426
+ Configuration for InfluxDB 1.x
1427
+ ------------------------------
1428
+
1416
1429
.. code-block :: python
1417
1430
1418
- TIMESERIES_DATABASE = {
1431
+ INFLUXDB_1x_DATABASE = {
1419
1432
' BACKEND' : ' openwisp_monitoring.db.backends.influxdb' ,
1420
1433
' USER' : ' openwisp' ,
1421
1434
' PASSWORD' : ' openwisp' ,
1422
1435
' NAME' : ' openwisp2' ,
1423
- ' HOST' : ' localhost ' ,
1436
+ ' HOST' : ' influxdb ' ,
1424
1437
' PORT' : ' 8086' ,
1425
- ' OPTIONS' : {
1426
- ' udp_writes' : False ,
1427
- ' udp_port' : 8089 ,
1428
- }
1438
+ ' OPTIONS' : {' udp_writes' : False , ' udp_port' : 8089 },
1429
1439
}
1430
1440
1431
- The following table describes all keys available in ``TIMESERIES_DATABASE ``
1432
- setting:
1433
-
1434
- +---------------+--------------------------------------------------------------------------------------+
1435
- | **Key ** | ``Description `` |
1436
- +---------------+--------------------------------------------------------------------------------------+
1437
- | ``BACKEND `` | The timeseries database backend to use. You can select one of the backends |
1438
- | | located in ``openwisp_monitoring.db.backends `` |
1439
- +---------------+--------------------------------------------------------------------------------------+
1440
- | ``USER `` | User for logging into the timeseries database |
1441
- +---------------+--------------------------------------------------------------------------------------+
1442
- | ``PASSWORD `` | Password of the timeseries database user |
1443
- +---------------+--------------------------------------------------------------------------------------+
1444
- | ``NAME `` | Name of the timeseries database |
1445
- +---------------+--------------------------------------------------------------------------------------+
1446
- | ``HOST `` | IP address/hostname of machine where the timeseries database is running |
1447
- +---------------+--------------------------------------------------------------------------------------+
1448
- | ``PORT `` | Port for connecting to the timeseries database |
1449
- +---------------+--------------------------------------------------------------------------------------+
1450
- | ``OPTIONS `` | These settings depends on the timeseries backend: |
1451
- | | |
1452
- | | +-----------------+----------------------------------------------------------------+ |
1453
- | | | ``udp_writes `` | Whether to use UDP for writing data to the timeseries database | |
1454
- | | +-----------------+----------------------------------------------------------------+ |
1455
- | | | ``udp_port `` | Timeseries database port for writing data using UDP | |
1456
- | | +-----------------+----------------------------------------------------------------+ |
1457
- +---------------+--------------------------------------------------------------------------------------+
1458
-
1459
- **Note: ** UDP packets can have a maximum size of 64KB. When using UDP for writing timeseries
1460
- data, if the size of the data exceeds 64KB, TCP mode will be used instead.
1461
-
1462
- **Note: ** If you want to use the ``openwisp_monitoring.db.backends.influxdb `` backend
1463
- with UDP writes enabled, then you need to enable two different ports for UDP
1464
- (each for different retention policy) in your InfluxDB configuration. The UDP configuration
1465
- section of your InfluxDB should look similar to the following:
1441
+ Configuration for InfluxDB 2.x
1442
+ ------------------------------
1443
+
1444
+ .. code-block :: python
1445
+
1446
+ INFLUXDB_2x_DATABASE = {
1447
+ ' BACKEND' : ' openwisp_monitoring.db.backends.influxdb2' ,
1448
+ ' TOKEN' : ' my-super-secret-auth-token' ,
1449
+ ' ORG' : ' openwisp' ,
1450
+ ' BUCKET' : ' openwisp2' ,
1451
+ ' HOST' : ' influxdb2' ,
1452
+ ' PORT' : ' 9999' ,
1453
+ }
1454
+
1455
+ Dynamic Configuration Based on Environment
1456
+ ------------------------------------------
1457
+
1458
+ You can dynamically switch between InfluxDB 1.x and 2.x configurations
1459
+ using environment variables:
1460
+
1461
+ .. code-block :: python
1462
+
1463
+ import os
1464
+
1465
+ if os.environ.get(' USE_INFLUXDB2' , ' False' ) == ' True' :
1466
+ TIMESERIES_DATABASE = INFLUXDB_2x_DATABASE
1467
+ else :
1468
+ TIMESERIES_DATABASE = INFLUXDB_1x_DATABASE
1469
+
1470
+ if TESTING :
1471
+ if os.environ.get(' TIMESERIES_UDP' , False ):
1472
+ TIMESERIES_DATABASE [' OPTIONS' ] = {' udp_writes' : True , ' udp_port' : 8091 }
1473
+
1474
+ Explanation of Settings
1475
+ -----------------------
1476
+
1477
+ +---------------+---------------------------------------------------------------+
1478
+ | **Key ** | **Description ** |
1479
+ +-------------------------------------------------------------------------------+
1480
+ | ``BACKEND `` | The timeseries database backend to use. You can select one |
1481
+ | | of the backends located in ``openwisp_monitoring.db.backends``|
1482
+ +---------------+---------------------------------------------------------------+
1483
+ | ``USER `` | User for logging into the timeseries database (only for |
1484
+ | | InfluxDB 1.x) |
1485
+ +---------------+---------------------------------------------------------------+
1486
+ | ``PASSWORD `` | Password of the timeseries database user (only for InfluxDB |
1487
+ | | 1.x) |
1488
+ +---------------+---------------------------------------------------------------+
1489
+ | ``NAME `` | Name of the timeseries database (only for InfluxDB 1.x) |
1490
+ +---------------+---------------------------------------------------------------+
1491
+ | ``TOKEN `` | Authentication token for InfluxDB 2.x |
1492
+ +---------------+---------------------------------------------------------------+
1493
+ | ``ORG `` | Organization name for InfluxDB 2.x |
1494
+ +---------------+---------------------------------------------------------------+
1495
+ | ``BUCKET `` | Bucket name for InfluxDB 2.x |
1496
+ +---------------+---------------------------------------------------------------+
1497
+ | ``HOST `` | IP address/hostname of machine where the timeseries |
1498
+ | | database is running |
1499
+ +---------------+---------------------------------------------------------------+
1500
+ | ``PORT `` | Port for connecting to the timeseries database |
1501
+ +---------------+---------------------------------------------------------------+
1502
+ | ``OPTIONS `` | Additional options for the timeseries backend |
1503
+ | | |
1504
+ | | +-----------------+-----------------------------------------+ |
1505
+ | | | ``udp_writes `` | Whether to use UDP for writing data | |
1506
+ | | | | to the timeseries database | |
1507
+ | | +-----------------+-----------------------------------------+ |
1508
+ | | | ``udp_port `` | Timeseries database port for writing | |
1509
+ | | | | data using UDP | |
1510
+ | | +-----------------+-----------------------------------------+ |
1511
+ +---------------+---------------------------------------------------------------+
1512
+
1513
+ UDP Configuration for InfluxDB 1.x
1514
+ ----------------------------------
1515
+
1516
+ If you want to use the ``openwisp_monitoring.db.backends.influxdb `` backend
1517
+ with UDP writes enabled, you need to enable two different ports for UDP
1518
+ (each for a different retention policy) in your InfluxDB configuration.
1519
+
1520
+ Here is an example of the UDP configuration section in your InfluxDB
1521
+ configuration file:
1466
1522
1467
1523
.. code-block :: text
1468
1524
@@ -1479,6 +1535,13 @@ section of your InfluxDB should look similar to the following:
1479
1535
database = "openwisp2"
1480
1536
retention-policy = 'short'
1481
1537
1538
+ **Note: ** UDP packets can have a maximum size of 64KB. When using UDP for
1539
+ writing timeseries data, if the size of the data exceeds 64KB, TCP mode
1540
+ will be used instead.
1541
+
1542
+ Deploying with Ansible
1543
+ ----------------------
1544
+
1482
1545
If you are using `ansible-openwisp2 <https://github.com/openwisp/ansible-openwisp2 >`_
1483
1546
for deploying OpenWISP, you can set the ``influxdb_udp_mode `` ansible variable to ``true ``
1484
1547
in your playbook, this will make the ansible role automatically configure the InfluxDB UDP listeners.
0 commit comments