mark for influx
This commit is contained in:
parent
e5def9fb33
commit
d3500d195b
22
pom.xml
22
pom.xml
@ -92,17 +92,17 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- influx start-->
|
<!-- influx start-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.springframework.boot</groupId>
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
<!-- <artifactId>spring-boot-actuator-autoconfigure</artifactId>-->
|
||||||
<optional>true</optional>
|
<!-- <optional>true</optional>-->
|
||||||
<exclusions>
|
<!-- <exclusions>-->
|
||||||
<exclusion>
|
<!-- <exclusion>-->
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
|
||||||
<artifactId>jackson-databind</artifactId>
|
<!-- <artifactId>jackson-databind</artifactId>-->
|
||||||
</exclusion>
|
<!-- </exclusion>-->
|
||||||
</exclusions>
|
<!-- </exclusions>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- influx end-->
|
<!-- influx end-->
|
||||||
|
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
package com.cnbm.influx.controller;
|
package com.cnbm.influx.controller;
|
||||||
|
|
||||||
|
import com.cnbm.influx.common.Utils;
|
||||||
import com.cnbm.influx.config.InfluxClient;
|
import com.cnbm.influx.config.InfluxClient;
|
||||||
|
import com.cnbm.influx.param.PageInfo;
|
||||||
|
import com.cnbm.influx.param.QueryDataParam;
|
||||||
|
import com.cnbm.influx.param.Range;
|
||||||
|
import com.cnbm.influx.param.Tag;
|
||||||
import com.cnbm.influx.template.Event;
|
import com.cnbm.influx.template.Event;
|
||||||
import com.influxdb.client.InfluxDBClient;
|
import com.influxdb.client.InfluxDBClient;
|
||||||
import com.influxdb.client.domain.WritePrecision;
|
import com.influxdb.client.domain.WritePrecision;
|
||||||
import com.influxdb.client.write.Point;
|
import com.influxdb.client.write.Point;
|
||||||
|
import com.influxdb.query.FluxRecord;
|
||||||
|
import com.influxdb.query.FluxTable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -12,47 +19,75 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/influx")
|
@RequestMapping("/influx")
|
||||||
public class S7DemoController {
|
public class S7DemoController {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class);
|
private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
InfluxDBClient influxDBClient;
|
|
||||||
|
|
||||||
|
|
||||||
// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
|
|
||||||
// Temperature temperature = new Temperature();
|
|
||||||
// temperature.setLocation("east");
|
|
||||||
// temperature.setValue(106.2D);
|
|
||||||
// temperature.setTime(Instant.now());
|
|
||||||
// writeApi.writeMeasurement(WritePrecision.NS,temperature);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
|
|
||||||
// Point point = Point.measurement("temperature")
|
|
||||||
// .addTag("location","south")
|
|
||||||
// .addTag("owner","wxm")
|
|
||||||
// .addField("wxm",230.8);
|
|
||||||
// writeApi.writePoint(point);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/insertBatch")
|
@PostMapping("/insertBatch")
|
||||||
public void insertBatch() throws InterruptedException {
|
public void insertBatch() throws InterruptedException {
|
||||||
// List<Event> list = new ArrayList<>();
|
List<Event> list = new ArrayList<>();
|
||||||
//
|
|
||||||
// for(int i=0;i<99;i++){
|
for(int i=0;i<99;i++){
|
||||||
// //Thread.sleep(1000);
|
Thread.sleep(100);
|
||||||
// Event event = new Event();
|
Event event = new Event();
|
||||||
// event.time = Instant.now();
|
event.setTime(Instant.now());
|
||||||
// event.transationId = "asas"+i;
|
event.setTransationId("asas"+i);
|
||||||
// event.argName = "arg5";
|
event.setArgName("arg7");
|
||||||
// event.argValue = new Double(i);
|
event.setArgValue(new Double(i));
|
||||||
// list.add(event);
|
list.add(event);
|
||||||
// }
|
}
|
||||||
// influxService.batchInsert(list);
|
InfluxClient.Client.batchInsert(list,"ASProcessCompleteEventAS");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/query")
|
||||||
|
public void query() throws InterruptedException {
|
||||||
|
List<Event> list = new ArrayList<>();
|
||||||
|
|
||||||
|
QueryDataParam queryDataParam = new QueryDataParam();
|
||||||
|
queryDataParam.setBucket("qgs-bucket");
|
||||||
|
queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||||
|
queryDataParam.setDropedTagName("transationId");
|
||||||
|
queryDataParam.setTag(new Tag("argName","arg6"));
|
||||||
|
queryDataParam.setRange(new Range(Utils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||||
|
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||||
|
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||||
|
|
||||||
|
|
||||||
|
for (FluxTable fluxTable : query) {
|
||||||
|
List<FluxRecord> records = fluxTable.getRecords();
|
||||||
|
for (FluxRecord fluxRecord : records) {
|
||||||
|
System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
List<Event> list = new ArrayList<>();
|
||||||
|
|
||||||
|
QueryDataParam queryDataParam = new QueryDataParam();
|
||||||
|
queryDataParam.setBucket("qgs-bucket");
|
||||||
|
queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||||
|
queryDataParam.setDropedTagName("transationId");
|
||||||
|
queryDataParam.setTag(new Tag("argName","arg7"));
|
||||||
|
queryDataParam.setRange(new Range(Utils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||||
|
queryDataParam.setPageInfo(new PageInfo(2,10));
|
||||||
|
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||||
|
|
||||||
|
|
||||||
|
for (FluxTable fluxTable : query) {
|
||||||
|
List<FluxRecord> records = fluxTable.getRecords();
|
||||||
|
for (FluxRecord fluxRecord : records) {
|
||||||
|
System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,8 +106,8 @@ public class S7DemoController {
|
|||||||
event.setTime(Instant.now());
|
event.setTime(Instant.now());
|
||||||
event.setTransationId("asasd11");
|
event.setTransationId("asasd11");
|
||||||
event.setArgName("argName11");
|
event.setArgName("argName11");
|
||||||
event.setArgValue(7d);
|
event.setArgValue(900001d);
|
||||||
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
||||||
influxDBClient.makeWriteApi().writePoint(asProcessCompleteEvent);
|
InfluxClient.Client.insert(event,"ASProcessCompleteEvent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.health;
|
|
||||||
|
|
||||||
import com.influxdb.client.InfluxDBClient;
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link //HealthIndicator} for InfluxDB 2.
|
|
||||||
*
|
|
||||||
* @author Jakub Bednar (bednar@github)
|
|
||||||
*/
|
|
||||||
public class InfluxDB2HealthIndicator extends AbstractHealthIndicator {
|
|
||||||
|
|
||||||
private final InfluxDBClient influxDBClient;
|
|
||||||
|
|
||||||
public InfluxDB2HealthIndicator(final InfluxDBClient influxDBClient) {
|
|
||||||
super("InfluxDBClient 2 health check failed");
|
|
||||||
Assert.notNull(influxDBClient, "InfluxDBClient must not be null");
|
|
||||||
|
|
||||||
this.influxDBClient = influxDBClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doHealthCheck(final Health.Builder builder) {
|
|
||||||
boolean success = this.influxDBClient.ping();
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
builder.up();
|
|
||||||
} else {
|
|
||||||
builder.down();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.health;
|
|
||||||
|
|
||||||
import com.cnbm.influx.influx.InfluxDB2AutoConfiguration;
|
|
||||||
import com.influxdb.client.InfluxDBClient;
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.HealthContributor;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link InfluxDB2HealthIndicator}.
|
|
||||||
*
|
|
||||||
* @author Jakub Bednar
|
|
||||||
*/
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@ConditionalOnClass(InfluxDBClient.class)
|
|
||||||
@ConditionalOnBean(InfluxDBClient.class)
|
|
||||||
@ConditionalOnEnabledHealthIndicator("influx")
|
|
||||||
@AutoConfigureAfter(InfluxDB2AutoConfiguration.class)
|
|
||||||
public class InfluxDB2HealthIndicatorAutoConfiguration
|
|
||||||
extends CompositeHealthContributorConfiguration<InfluxDB2HealthIndicator, InfluxDBClient> {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(name = { "influxDB2HealthIndicator", "influxDB2HealthContributor" })
|
|
||||||
public HealthContributor influxDbHealthContributor(final Map<String, InfluxDBClient> influxDBClients) {
|
|
||||||
return createContributor(influxDBClients);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.influx;
|
|
||||||
|
|
||||||
import com.influxdb.client.InfluxDBClientOptions;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Protocol;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jakub Bednar (04/08/2021 11:41)
|
|
||||||
*/
|
|
||||||
abstract class AbstractInfluxDB2AutoConfiguration {
|
|
||||||
protected final InfluxDB2Properties properties;
|
|
||||||
protected final InfluxDB2OkHttpClientBuilderProvider builderProvider;
|
|
||||||
|
|
||||||
protected AbstractInfluxDB2AutoConfiguration(final InfluxDB2Properties properties,
|
|
||||||
final InfluxDB2OkHttpClientBuilderProvider builderProvider) {
|
|
||||||
this.properties = properties;
|
|
||||||
this.builderProvider = builderProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
protected InfluxDBClientOptions.Builder makeBuilder() {
|
|
||||||
OkHttpClient.Builder okHttpBuilder;
|
|
||||||
if (builderProvider == null) {
|
|
||||||
okHttpBuilder = new OkHttpClient.Builder()
|
|
||||||
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
|
||||||
.readTimeout(properties.getReadTimeout())
|
|
||||||
.writeTimeout(properties.getWriteTimeout())
|
|
||||||
.connectTimeout(properties.getConnectTimeout());
|
|
||||||
} else {
|
|
||||||
okHttpBuilder = builderProvider.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
InfluxDBClientOptions.Builder influxBuilder = InfluxDBClientOptions.builder()
|
|
||||||
.url(properties.getUrl())
|
|
||||||
.bucket(properties.getBucket())
|
|
||||||
.org(properties.getOrg())
|
|
||||||
.okHttpClient(okHttpBuilder);
|
|
||||||
|
|
||||||
if (StringUtils.hasLength(properties.getToken())) {
|
|
||||||
influxBuilder.authenticateToken(properties.getToken().toCharArray());
|
|
||||||
} else if (StringUtils.hasLength(properties.getUsername()) && StringUtils.hasLength(properties.getPassword())) {
|
|
||||||
influxBuilder.authenticate(properties.getUsername(), properties.getPassword().toCharArray());
|
|
||||||
}
|
|
||||||
return influxBuilder;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.influx;
|
|
||||||
|
|
||||||
import com.influxdb.client.InfluxDBClient;
|
|
||||||
import com.influxdb.client.InfluxDBClientFactory;
|
|
||||||
import com.influxdb.client.InfluxDBClientOptions;
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for InfluxDB 2.
|
|
||||||
*
|
|
||||||
* @author Jakub Bednar (bednar@github) (06/05/2019 13:09)
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass(InfluxDBClient.class)
|
|
||||||
@EnableConfigurationProperties(InfluxDB2Properties.class)
|
|
||||||
public class InfluxDB2AutoConfiguration extends AbstractInfluxDB2AutoConfiguration {
|
|
||||||
|
|
||||||
public InfluxDB2AutoConfiguration(final InfluxDB2Properties properties,
|
|
||||||
final ObjectProvider<InfluxDB2OkHttpClientBuilderProvider> builderProvider) {
|
|
||||||
super(properties, builderProvider.getIfAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnProperty("influx.url")
|
|
||||||
@ConditionalOnMissingBean(InfluxDBClient.class)
|
|
||||||
public InfluxDBClient influxDBClient() {
|
|
||||||
|
|
||||||
InfluxDBClientOptions.Builder influxBuilder = makeBuilder();
|
|
||||||
|
|
||||||
return InfluxDBClientFactory.create(influxBuilder.build()).setLogLevel(properties.getLogLevel());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.influx;
|
|
||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provide the {@link OkHttpClient.Builder OkHttpClient.Builder} to use to
|
|
||||||
* customize the auto-configured {@link com.influxdb.client.InfluxDBClient} instance.
|
|
||||||
*
|
|
||||||
* @author Jakub Bednar (bednar@github) (06/05/2019 13:11)
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface InfluxDB2OkHttpClientBuilderProvider extends Supplier<OkHttpClient.Builder> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.cnbm.influx.influx;
|
|
||||||
|
|
||||||
import com.cnbm.influx.constant.Constant;
|
|
||||||
import com.influxdb.LogLevel;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration properties for InfluxDB 2.
|
|
||||||
*
|
|
||||||
* @author Jakub Bednar (bednar@github) (06/05/2019 12:54)
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "influx")
|
|
||||||
public class InfluxDB2Properties {
|
|
||||||
|
|
||||||
// public InfluxDB2Properties{
|
|
||||||
// this.bucket = Constant.bucket;
|
|
||||||
// this.url = Constant.url;
|
|
||||||
// this.org = Constant.org;
|
|
||||||
// this.token = Constant.token;
|
|
||||||
// this.username = Constant.username;
|
|
||||||
// this.password = Constant.password;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static final int DEFAULT_TIMEOUT = 10_000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* URL to connect to InfluxDB.
|
|
||||||
*/
|
|
||||||
private String url = Constant.url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Username to use in the basic auth.
|
|
||||||
*/
|
|
||||||
private String username = Constant.username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Password to use in the basic auth.
|
|
||||||
*/
|
|
||||||
private String password = Constant.password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Token to use for the authorization.
|
|
||||||
*/
|
|
||||||
private String token = Constant.token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destination organization for writes and queries.
|
|
||||||
*/
|
|
||||||
private String org = Constant.org;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destination bucket for writes.
|
|
||||||
*/
|
|
||||||
private String bucket = Constant.bucket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The log level for logging the HTTP request and HTTP response.
|
|
||||||
*/
|
|
||||||
private LogLevel logLevel = LogLevel.NONE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read timeout for {@code OkHttpClient}.
|
|
||||||
*/
|
|
||||||
private Duration readTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write timeout for {@code OkHttpClient}.
|
|
||||||
*/
|
|
||||||
private Duration writeTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connection timeout for {@code OkHttpClient}.
|
|
||||||
*/
|
|
||||||
private Duration connectTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(final String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(final String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(final String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToken(final String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogLevel getLogLevel() {
|
|
||||||
return logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLogLevel(final LogLevel logLevel) {
|
|
||||||
this.logLevel = logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOrg() {
|
|
||||||
return org;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrg(final String org) {
|
|
||||||
this.org = org;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBucket() {
|
|
||||||
return bucket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBucket(final String bucket) {
|
|
||||||
this.bucket = bucket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getReadTimeout() {
|
|
||||||
return readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(final Duration readTimeout) {
|
|
||||||
this.readTimeout = readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getWriteTimeout() {
|
|
||||||
return writeTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWriteTimeout(final Duration writeTimeout) {
|
|
||||||
this.writeTimeout = writeTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getConnectTimeout() {
|
|
||||||
return connectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectTimeout(final Duration connectTimeout) {
|
|
||||||
this.connectTimeout = connectTimeout;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
influx:
|
|
||||||
url: http://192.168.0.170:8086 # URL to connect to InfluxDB.
|
|
||||||
username: caixiang # Username to use in the basic auth.
|
|
||||||
password: 251128856 # Password to use in the basic auth.
|
|
||||||
token: lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw== # Token to use for the authorization.
|
|
||||||
org: qgs # Default destination organization for writes and queries.
|
|
||||||
bucket: qgs-bucket # Default destination bucket for writes.
|
|
||||||
logLevel: BODY # The log level for logging the HTTP request and HTTP response. (Default: NONE)
|
|
||||||
readTimeout: 5s # Read timeout for OkHttpClient. (Default: 10s)
|
|
||||||
writeTimeout: 5s # Write timeout for OkHttpClient. (Default: 10s)
|
|
||||||
connectTimeout: 5s # Connection timeout for OkHttpClient. (Default: 10s)
|
|
||||||
|
|
||||||
# management.health.influx.enabled=true # Whether to enable InfluxDB 2.x health check.
|
|
||||||
management:
|
|
||||||
health:
|
|
||||||
influxdb:
|
|
||||||
enabled: true
|
|
Loading…
Reference in New Issue
Block a user