Skip to content

Commit

Permalink
add support influxdb2
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat authored and frenck committed Mar 14, 2023
1 parent eda9066 commit 77f96e3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 20 deletions.
64 changes: 52 additions & 12 deletions glances/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ influxdb:
enabled: false
host: a0d7b954-influxdb
port: 8086
interval: 60
ssl: false
prefix: localhost
version: 1 # Either 1 or 2

# Version 1
username: glances
password: "!secret glances_influxdb_password"
database: glances
prefix: localhost
interval: 60
ssl: false

# Version 2
token: "!secret glances_influxdb2_token"
bucket: glances
org: myorg
```
**Note**: _This is just an example, don't copy and paste it! Create your own!_
Expand Down Expand Up @@ -119,37 +127,69 @@ use `a0d7b954-influxdb` as the hostname._

The port on which InfluxDB is listening.

#### Option `influxdb`: `interval`

Defines the interval (in seconds) on how often Glances exports data to InfluxDB.

#### Option `influxdb`: `ssl`

Adding this option will allow SSL to be used on the InfluxDB connection. If not
set will default to `false` which is the required setting for the Community
InfluxDB add-on.

#### Option `influxdb`: `prefix`

The hostname to append for exported data.

**Note**: _For the Grafana Glances dashboard set this to `localhost`._

#### Option `influxdb`: `version`

The influxdb version to connecting. Either **1** or **2**.

#### Option `influxdb`: `username`

> Applied to version 1 only

The username that you have created for Glances to authenticate against
InfluxDB.

#### Option `influxdb`: `password`

> Applied to version 1 only

The password for the above username option.

#### Option `influxdb`: `database`

> Applied to version 1 only

The name of the database to store all Glances information into.

**Note**: _It is strongly recommended to create a separate database for glances
and not store this in the same database name as Home Assistant._

#### Option `prefix`: `localhost`
#### Option `influxdb`: `token`

The hostname to append for exported data.
> Applied to version 2 only

**Note**: _For the Grafana Glances dashboard set this to `localhost`._
An InfluxDB token with permissions to write to the given bucket. This should
look like `t9iHPiGQyg0ds4K1IlBrCyBsNGh71dkdR6u8Y9eeR37UzfGuFukFCdbMI4YA9EtKb4zr5coFXKw67tbBEP7CPw==`

#### Option `influxdb`: `interval`
#### Option `influxdb`: `bucket`

Defines the interval (in seconds) on how often Glances exports data to InfluxDB.
> Applied to version 1 only

#### Option `influxdb`: `ssl`
The name of the bucket to store all Glances information into.

Adding this option will allow SSL to be used on the InfluxDB connection. If not
set will default to `false` which is the required setting for the Community
InfluxDB add-on.
**Note**: _It is strongly recommended to create a separate bucket for glances
and not store this in the same bucket as Home Assistant._

#### Option `influxdb`: `organization`

> Applied to version 1 only

The InfluxDB organization that owns the given bucket.

## Adding Glances as a sensor into Home Assistant

Expand Down
7 changes: 6 additions & 1 deletion glances/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ options:
enabled: false
host: a0d7b954-influxdb
port: 8086
interval: 60
ssl: false
version: 1
username: glances
password: ""
database: glances
prefix: localhost
interval: 60
token: ""
bucket: glances
org: myorg
schema:
log_level: list(trace|debug|info|notice|warning|error|fatal)
process_info: bool
Expand Down
1 change: 1 addition & 0 deletions glances/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bottle==0.12.25
docker==6.0.1
glances==3.3.1.1
influxdb==5.3.1
influxdb-client==1.21.0
netifaces==0.11.0
paho-mqtt==1.6.1
psutil==5.9.4
Expand Down
29 changes: 23 additions & 6 deletions glances/rootfs/etc/cont-init.d/glances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Home Assistant Community Add-on: Glances
# Configures Glances
# ==============================================================================
declare protocol
declare header protocol
bashio::require.unprotected

# Ensure the configuration exists
Expand All @@ -23,15 +23,32 @@ if bashio::config.true 'influxdb.enabled'; then
if bashio::config.true 'influxdb.ssl'; then
protocol='https'
fi

header='influxdb'
if bashio::config.equals 'influxdb.version' '2'; then
header='influxdb2'
fi

# Modify the configuration
{
echo "[influxdb]"
echo "[${header}]"
echo "protocol=${protocol}"
echo "host=$(bashio::config 'influxdb.host')"
echo "port=$(bashio::config 'influxdb.port')"
echo "user=$(bashio::config 'influxdb.username')"
echo "password=$(bashio::config 'influxdb.password')"
echo "db=$(bashio::config 'influxdb.database')"
echo "prefix=$(bashio::config 'influxdb.prefix')"
echo "protocol=${protocol}"
} >> /etc/glances.conf

if bashio::config.equals 'influxdb.version' '1'; then
{
echo "user=$(bashio::config 'influxdb.username')"
echo "password=$(bashio::config 'influxdb.password')"
echo "db=$(bashio::config 'influxdb.database')"
} >> /etc/glances.conf
elif bashio::config.equals 'influxdb.version' '2'; then
{
echo "org=$(bashio::config 'influxdb.organization')"
echo "bucket=$(bashio::config 'influxdb.bucket')"
echo "token=$(bashio::config 'influxdb.token')"
} >> /etc/glances.conf
fi
fi
9 changes: 8 additions & 1 deletion glances/rootfs/etc/services.d/influxdb/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
# Runs Glances InfluxDB Export
# ==============================================================================
declare -a options
declare exporter

if bashio::config.false 'influxdb.enabled'; then
bashio::exit.ok
fi


exporter='influxdb'
if bashio::config.equals 'influxdb.version' '2'; then
exporter='influxdb2'
fi

options+=(-C /etc/glances.conf)
options+=(--export influxdb)
options+=(--export "${exporter}")
options+=(--quiet)

options+=(--time "$(bashio::config 'refresh_time')")
Expand Down

0 comments on commit 77f96e3

Please sign in to comment.