Coder Social home page Coder Social logo

ifluxdbinjector's Introduction

ifluxdbInjector

import java.time.Instant;
import java.util.List;

import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import com.influxdb.query.FluxTable;

public class DemoApplication {

	@Measurement(name = "mem")
	public static class Mem {
		@Column(tag = true)
		String host;
		@Column
		Double used_percent;
		@Column(timestamp = true)
		Instant time;
	}

	public static void main(String[] args) {

		String token = "NYLjUVZf37Y0_3pN4fVMYSDnyF30_tW5tLlW0LTL_172aGKJ6e3Ynhdn-ch3TDPNmzZJOS5_EdIBiP043ESb8g==";
		String bucket = "initialBucket";
		String org = "hsbc";

		InfluxDBClient client = InfluxDBClientFactory.create("http://localhost:8086", token.toCharArray());

		System.out.println(client);

		String data = "mem,host=host1 used_percent=23.43234543";
		try (WriteApi writeApi = client.getWriteApi()) {
			writeApi.writeRecord(bucket, org, WritePrecision.NS, data);
		}

		/**
		 * 
		 */

		Mem mem = new Mem();
		mem.host = "host1234";
		mem.used_percent = 110.43234543;
		mem.time = Instant.now();

		try (WriteApi writeApi = client.getWriteApi()) {
			writeApi.writeMeasurement(bucket, org, WritePrecision.NS, mem);
		}

		/**
		 * 
		 */

		Point point = Point.measurement("mem").addTag("host", "host1").addField("used_percent", 23.43234543)
				.time(Instant.now(), WritePrecision.NS);

		try (WriteApi writeApi = client.getWriteApi()) {
			writeApi.writePoint(bucket, org, point);
		}

		/**
		 * 
		 */

		String query = String.format("from(bucket: \"%s\") |> range(start: -1h)", bucket);
		List<FluxTable> tables = client.getQueryApi().query(query, org);
		System.out.println(tables);


	}

}
<dependency>
	<groupId>com.influxdb</groupId>
	<artifactId>influxdb-client-java</artifactId>
	<version>2.0.0</version>
</dependency>

ifluxdbinjector's People

Contributors

anil14349 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.