Modifications to support to InfluxDB v2.x
This commit is contained in:
parent
8f4fbc6a93
commit
46fd9d7671
17
README.md
17
README.md
|
@ -149,7 +149,7 @@ Use the gradle build tool, which will download all required dependencies:
|
||||||
|
|
||||||
### Local Testing
|
### Local Testing
|
||||||
|
|
||||||
#### InfluxDB
|
#### InfluxDB v1.x
|
||||||
|
|
||||||
Start a InfluxDB container:
|
Start a InfluxDB container:
|
||||||
|
|
||||||
|
@ -163,6 +163,18 @@ Create the *hmci* database:
|
||||||
docker exec -i influxdb influx -execute "CREATE DATABASE hmci"
|
docker exec -i influxdb influx -execute "CREATE DATABASE hmci"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### InfluxDB v2.x
|
||||||
|
|
||||||
|
Start a InfluxDB container:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker pull influxdb:latest
|
||||||
|
docker run --name=influxdb --rm -d -p 8086:8086 influxdb:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
- Then use the Web UI to create an initial user (for the web UI), an organization and bucket: http://localhost:8086/
|
||||||
|
- Then create an API token with RW access to your bucket.
|
||||||
|
|
||||||
|
|
||||||
#### Grafana
|
#### Grafana
|
||||||
|
|
||||||
|
@ -174,4 +186,7 @@ docker run --name grafana --link influxdb:influxdb --rm -d -p 3000:3000 grafana/
|
||||||
|
|
||||||
Setup Grafana to connect to the InfluxDB container by defining a new datasource on URL *http://influxdb:8086* named *hmci*.
|
Setup Grafana to connect to the InfluxDB container by defining a new datasource on URL *http://influxdb:8086* named *hmci*.
|
||||||
|
|
||||||
|
If you are [connecting](https://docs.influxdata.com/influxdb/v2.7/tools/grafana/) to InfluxDB v2.x, then add a custom http header, enter bucket as database and disable authorization.
|
||||||
|
- Authorization = Token abcdef_random_token_from_nfluxdb==
|
||||||
|
|
||||||
Import dashboards from the [doc/dashboards/](doc/dashboards/) folder.
|
Import dashboards from the [doc/dashboards/](doc/dashboards/) folder.
|
||||||
|
|
|
@ -3,14 +3,23 @@
|
||||||
|
|
||||||
###
|
###
|
||||||
### Define one InfluxDB to save metrics into
|
### Define one InfluxDB to save metrics into
|
||||||
|
### There must be only one and it should be named [influx]
|
||||||
###
|
###
|
||||||
|
|
||||||
|
# InfluxDB v1.x example
|
||||||
|
#[influx]
|
||||||
|
#url = "http://localhost:8086"
|
||||||
|
#username = "root"
|
||||||
|
#password = ""
|
||||||
|
#database = "hmci"
|
||||||
|
|
||||||
|
|
||||||
|
# InfluxDB v2.x example
|
||||||
[influx]
|
[influx]
|
||||||
url = "http://localhost:8086"
|
url = "http://localhost:8086"
|
||||||
username = "root"
|
org = "myOrg"
|
||||||
password = ""
|
token = "rAnd0mT0k3nG3neRaT3dByInF1uxDb=="
|
||||||
database = "hmci"
|
bucket = "hmci"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -7,6 +7,7 @@ When installed Grafana listens on [http://localhost:3000](http://localhost:3000)
|
||||||
- Configure Grafana to use InfluxDB as a new datasource
|
- Configure Grafana to use InfluxDB as a new datasource
|
||||||
- Name the datasource **hmci** to make it obvious what it contains.
|
- Name the datasource **hmci** to make it obvious what it contains.
|
||||||
- You would typically use *http://localhost:8086* without any credentials.
|
- You would typically use *http://localhost:8086* without any credentials.
|
||||||
|
- For InfluxDB add a custom header: Authorization = Token myTokenFromInfluxDB
|
||||||
- The name of the database would be *hmci* (or another name you used when creating it)
|
- The name of the database would be *hmci* (or another name you used when creating it)
|
||||||
- **NOTE:** set *Min time interval* to *30s* or *1m* depending on your HMCi *refresh* setting.
|
- **NOTE:** set *Min time interval* to *30s* or *1m* depending on your HMCi *refresh* setting.
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ public final class InfluxClient {
|
||||||
private final static Logger log = LoggerFactory.getLogger(InfluxClient.class);
|
private final static Logger log = LoggerFactory.getLogger(InfluxClient.class);
|
||||||
|
|
||||||
final private String url;
|
final private String url;
|
||||||
|
final private String org; // v2 only
|
||||||
final private String token;
|
final private String token;
|
||||||
final private String org;
|
final private String bucket; // Bucket in v2, Database in v1
|
||||||
final private String database; // Bucket in v2
|
|
||||||
|
|
||||||
|
|
||||||
private InfluxDBClient influxDBClient;
|
private InfluxDBClient influxDBClient;
|
||||||
|
@ -47,9 +47,21 @@ public final class InfluxClient {
|
||||||
|
|
||||||
InfluxClient(InfluxConfiguration config) {
|
InfluxClient(InfluxConfiguration config) {
|
||||||
this.url = config.url;
|
this.url = config.url;
|
||||||
this.token = config.username + ":" + config.password;
|
if(config.org != null) {
|
||||||
this.org = "hmci"; // In InfluxDB 1.x, there is no concept of organization.
|
this.org = config.org;
|
||||||
this.database = config.database;
|
} else {
|
||||||
|
this.org = "hmci"; // In InfluxDB 1.x, there is no concept of organization.
|
||||||
|
}
|
||||||
|
if(config.token != null) {
|
||||||
|
this.token = config.token;
|
||||||
|
} else {
|
||||||
|
this.token = config.username + ":" + config.password;
|
||||||
|
}
|
||||||
|
if(config.bucket != null) {
|
||||||
|
this.bucket = config.bucket;
|
||||||
|
} else {
|
||||||
|
this.bucket = config.database;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +78,7 @@ public final class InfluxClient {
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
log.debug("Connecting to InfluxDB - {}", url);
|
log.debug("Connecting to InfluxDB - {}", url);
|
||||||
influxDBClient = InfluxDBClientFactory.create(url, token.toCharArray(), org, database);
|
influxDBClient = InfluxDBClientFactory.create(url, token.toCharArray(), org, bucket);
|
||||||
influxDBClient.version(); // This ensures that we actually try to connect to the db
|
influxDBClient.version(); // This ensures that we actually try to connect to the db
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(influxDBClient::close));
|
Runtime.getRuntime().addShutdownHook(new Thread(influxDBClient::close));
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ package biz.nellemann.hmci.dto.toml;
|
||||||
public class InfluxConfiguration {
|
public class InfluxConfiguration {
|
||||||
|
|
||||||
public String url;
|
public String url;
|
||||||
|
public String org;
|
||||||
|
public String token;
|
||||||
|
public String bucket;
|
||||||
|
|
||||||
public String username;
|
public String username;
|
||||||
public String password;
|
public String password;
|
||||||
public String database;
|
public String database;
|
||||||
|
|
Loading…
Reference in a new issue