Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

InfluxDB Client Libraries and Applications | Miroslav Malecha | Bonitoo

1,023 views

Published on

InfluxDB comes with a new set of client libraries to allow you to insert time series data from your applications into the new InfluxDB 2.0. In this session, Miroslav will walk you through how to use the new client library to access InfluxDB 2.0.

Published in: Technology
  • I like this service ⇒ www.WritePaper.info ⇐ from Academic Writers. I don't have enough time write it by myself.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • If you’re looking for a great essay service then you should check out ⇒ www.HelpWriting.net ⇐. A friend of mine asked them to write a whole dissertation for him and he said it turned out great! Afterwards I also ordered an essay from them and I was very happy with the work I got too.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

InfluxDB Client Libraries and Applications | Miroslav Malecha | Bonitoo

  1. 1. Miroslav Malecha / Product Manager Bonitoo.io InfluxDB Client Libraries and Applications
  2. 2. © 2019 InfluxData. All rights reserved. 2 SW Engineering Company ● InfluxData consulting partner Delivered Client Libraries and other deliverables ● End-to-end R&D Services (architecture, agile development, documentation, support, hosting, operation) ● Strong team of professionals (development for SaaS Startups, Enterprise Software, Mobile applications) Technologies ● Java, JS, C#, Python, SQL, ML https://github.com/bonitoo-io
  3. 3. © 2019 InfluxData. All rights reserved. 3 ● Client Libraries ○ Java & Spring integration ○ C# ○ Python ● Embedded analytics Agenda
  4. 4. InfluxDB Client Libraries
  5. 5. © 2019 InfluxData. All rights reserved. 5 Clustered InfluxDB Data Flow InfluxDB 2 Time Series Database Telegraf Agent for Collecting and Reporting Metrics and Events 210+ plugins System Stats Databases Networking Message Queues Apps Apps/IoT Apps/ IoT InfluxDB Client Java .NET Python HTTP GET/POST 1. 2. 3.
  6. 6. © 2019 InfluxData. All rights reserved. 6 Benefits of Client Libraries ● Performance/Reliability ○ Client write ~50 times faster* than HTTP POST approach ○ Batching, Jittering, Retriable, Backpressure ● Customization & Easy to use ○ Interface vs study format and build API messages manually ○ Error handling - HTTP codes vs standard exceptions and listeners ○ 3rd party application monitoring systems integration (Micrometer.io) ● Management API Support ○ Configure InfluxData Cloud ● Compatibility ○ Stable libraries interface developed by InfluxData *) InfluxDB Java Client, 2 CPUs, 16GB RAM, 2.000 threads, 100 lines per write for both methods
  7. 7. InfluxDB 2 Java Client Library
  8. 8. © 2019 InfluxData. All rights reserved. 8 Java Client Library NEW Client for InfluxDB 2 (replacement of Java Client for InfluxDB 1.x) ● Github repo: https://github.com/influxdata/influxdb-client-java ● Capabilities: Query, Write, Management, Security, Reactive streams ● Uses RxJava library (automated Batching, Jittering, Retriable, Backpressure) ● Improved data types support Extensions ● Support Kotlin, Scala (Akka Streams) ● Flux queries support for InfluxDB 1.7+ ● Flux-DSL query builder (Flux language in Java code) Replaces custom fast ingress solutions such as Hystrix, etc. Flux sampleFlux = Flux.from("telegraf") .range(-1L, ChronoUnit.DAYS) .filter( Restrictions.and( Restrictions.measurement().equal("cpu"), Restrictions.field().equal("usage_system")) ) .sample(5, 1);
  9. 9. © 2019 InfluxData. All rights reserved. 9 Write API Configuration Configuration parameters similar to Telegraf InfluxDBClient client = InfluxDBClientFactory.create("http://localhost:9999", "my-token".toCharArray()); WriteApi writeApi = client.getWriteApi(WriteOptions.builder() .batchSize(5000) .flushInterval(1000) .jitterInterval(1000) .bufferLimit(10000) .retryInterval(5000) .backpressureStrategy(BackpressureOverflowStrategy.DROP_OLDEST) .build());
  10. 10. © 2019 InfluxData. All rights reserved. 10 Write Data Write by POJO (annotated measures) Write By Point Write Line Protocol Temperature temperature = new Temperature(); temperature.setLocation("south"); temperature.setValue(62D); temperature.setTime(Instant.now()); writeApi.writeMeasurement("my-bucket", "my-org", WritePrecision.NS, temperature); Point point = Point.measurement("temperature") .addTag("location","west") .addField("value", 55D) .time(Instant.now().toEpochMilli(), WritePrecision.NS); writeApi.writePoint("my-bucket", "my-org", point); String record = "temperature,location=north value=60.0"; writeApi.writeRecord("my-bucket", "my-org", WritePrecision.NS, record);
  11. 11. © 2019 InfluxData. All rights reserved. 11 Query InfluxDB Asynchronous querying using Flux InfluxDBClientOptions clientOptions = InfluxDBClientOptions.builder() .url("http://localhost:9999").authenticate Token("my-token".toCharArray()).org("my-org") .build(); InfluxDBClient client = InfluxDBClientFactory.create(clientOptions); String fluxQuery = "from(bucket: "my-bucket")n" + " |> range(start: -1d)" + " |> filter(fn: (r) => (r._measurement == "cpu" and r._field == "usage_system"))" + " |> sample(n: 5, pos: 1)"; QueryApi queryApi = client.getQueryApi(); queryApi.query( fluxQuery, (cancellable, record) -> { // process the flux query result record System.out.println( record.getTime() + ": " + record.getValue()); }, error -> { // error handling while processing result error.printStackTrace(); }, () -> { // on complete System.out.println("Query completed"); });
  12. 12. © 2019 InfluxData. All rights reserved. 12 Advanced Configuration Set organization, bucket, permissions and authorization InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://localhost:9999", "my- token".toCharArray()); Organization medicalGMBH = influxDBClient.getOrganizationsApi().createOrganization("Medical Corp"); Bucket temperatureBucket = influxDBClient.getBucketsApi().createBucket("temperature-sensors", medicalGMBH); PermissionResource resource = new PermissionResource(); resource.setId(temperatureBucket.getId()); resource.setOrgID(medicalGMBH.getId()); resource.setType(PermissionResource.TypeEnum.BUCKETS); Permission readBucket = new Permission(); readBucket.setResource(resource); readBucket.setAction(Permission.ActionEnum.READ); Permission writeBucket = new Permission(); writeBucket.setResource(resource); writeBucket.setAction(Permission.ActionEnum.WRITE); Authorization authorization = influxDBClient.getAuthorizationsApi() .createAuthorization(medicalGMBH, Arrays.asList(readBucket, writeBucket)); String token = authorization.getToken(); System.out.println("The token to write to temperature-sensors bucket " + token);
  13. 13. Spring Integration
  14. 14. © 2019 InfluxData. All rights reserved. 14 InfluxDB integrated into Spring framework Application framework for Java Supported autoconfiguration based on class path presence 1) Add Maven dependency Package com.influxdb.spring.influx - Auto configuration, Health check, Metrics exporter 2) Define Client configuration (application.properties) <dependency> <groupId>org.influxdata</groupId> <artifactId>influxdb-spring</artifactId> <version>${influxdb-spring.version}</version> </dependency> spring.influx2.url=http://localhost:9999 spring.influx2.org=03ea32773f1d0000 spring.influx2.bucket=my-bucket spring.influx2.token=my-token-123 spring.influx2.username=my-user
  15. 15. © 2019 InfluxData. All rights reserved. 15 Monitor Spring Application using Micrometer.io Micrometer: metrics collection library included in Spring ● Provides timers, gauges, counters, distribution summaries in your JVM application ● Preconfigured metrics support 1) Define new dependency into the pom.xml 2) Add properties to the application.properties <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-influx2</artifactId> <version>${micrometer.version}</version> </dependency> management.metrics.export.influx2.enabled=true management.metrics.export.influx2.uri=http://localhost:9999/api/v2 management.metrics.export.influx2.org=my-org management.metrics.export.influx2.bucket=micrometer-bucket management.metrics.export.influx2.autoCreateBucket=false management.metrics.export.influx2.token=my-token-123 management.metrics.export.influx2.step=10s
  16. 16. © 2019 InfluxData. All rights reserved. 16 InfluxDB Visualizing APM Data
  17. 17. InfluxDB 2 C# Client Library
  18. 18. © 2019 InfluxData. All rights reserved. 18 C# Client Library ● NEW since InfluxDB 2 ● Github Repository: https://github.com/influxdata/influxdb-client-csharp ● Same API as the Java Client ● Compatible with Windows IoT Core ● Query API ● Write API - Line Protocol, Data Point, POCO ● Management API - Sources, buckets, tasks, permissions, health check ● Flux queries support for InfluxDB 1.7+
  19. 19. © 2019 InfluxData. All rights reserved. 19 Write Data influxDB = InfluxDBClientFactory.Create("http://localhost:9999", authorization.Token.ToCharArray()); var writeOptions = WriteOptions .CreateNew() .BatchSize(5000) .FlushInterval(1000) .JitterInterval(1000) .RetryInterval(5000) .Build(); using (var writeClient = influxDB.GetWriteApi(writeOptions)) { // Write by POCO var temperature = new Temperature {Location = "south", Value = 62D, Time = DateTime.UtcNow}; writeClient.WriteMeasurement("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, temperature); // Write by Point var point = PointData.Measurement("temperature") .Tag("location", "west") .Field("value", 55D) .Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns); writeClient.WritePoint("temperature-sensors", medicalGMBH.Id, point); // Write by LineProtocol var record = "temperature,location=north value=60.0"; writeClient.WriteRecord("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, record); writeClient.Flush(); }
  20. 20. © 2019 InfluxData. All rights reserved. 20 Query InfluxDB var options = InfluxDBClientOptions.Builder.CreateNew() .Url("http://localhost:9999").Org("my-org") .AuthenticateToken("my-token".ToCharArray()).Build(); var client = InfluxDBClientFactory.Create(options); var fluxQuery = "from(bucket: "my-bucket")n" + " |> range(start: -1d)" + " |> filter(fn: (r) => (r._measurement == "cpu" and r._field == "usage_system"))" + " |> sample(n: 5, pos: 1)"; var queryApi = client.GetQueryApi(); await queryApi.Query<Cpu>(fluxQuery, (cancellable, cpu) => // process the flux query records Console.WriteLine(cpu.ToString()); }, (error) => { // error handling while processing result Console.WriteLine(error.ToString()); }, () => { // on complete Console.WriteLine("Query completed"); } );
  21. 21. InfluxDB 2 Python Client Library (Alpha)
  22. 22. © 2019 InfluxData. All rights reserved. 22 ● NEW since InfluxDB 2 ● Github Repository: https://github.com/influxdata/influxdb-client-python ● Same API as the Java Client ● Capabilities: Query, Write, Management, Security ● Uses RxPY library Python Library
  23. 23. © 2019 InfluxData. All rights reserved. 23 Write import codecs from datetime import datetime from influxdb_client import WritePrecision, InfluxDBClient, Point client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org") write_api = client.write_api() p = Point("my_measurement").tag("location", "Prague").field("temperature",25.3).time(datetime.now(), WritePrecision.MS) write_api.write(org="my-org", bucket="my-bucket", record=p)
  24. 24. © 2019 InfluxData. All rights reserved. 24 Query import codecs from datetime import datetime from influxdb_client import WritePrecision, InfluxDBClient, Point client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org") query_api = client.query_api() query = ''' from(bucket:"my-bucket") |> range(start: -1m) |> filter(fn: (r) => (r._measurement == "cpu" and r._field == "usage_system")) ''' tables = query_api.query(query) for table in tables: print(table) for record in table.records: print(record.values)
  25. 25. Embedded Analytics with InfluxDB
  26. 26. © 2019 InfluxData. All rights reserved. 26 Demo Application Github repo: https://github.com/bonitoo-io/influxdata-iot-petstore Demo Application InfluxDB 2 Java Client InfluxDB 2 Application Data Spring Services Vaadin Web Framework +Vaadin Charts Library OpenAPI swagger generated from Java using SpringFox Micrometer.io push internal app metric to InfluxDB App MetricsData InfluxDB 2 Application Monitoring micrometer-registry-influx
  27. 27. © 2019 InfluxData. All rights reserved. 27 Predefined UI ● Filters ● Responsive - Mobile devices ● Various chart options - Vaadin End Users UI
  28. 28. © 2019 InfluxData. All rights reserved. 28 Data Analyst View Custom Data Explorer ● Visual Flux Builder ● Generates internally Flux queries ● Visualises data from(bucket: “my-bucket”) |> range (start: -2d,stop: now() ) |> filter(fn: (r) => r._measurement == “air” ) |> filter(fn: (r) => r._field == “temperature” ) |> filter(fn: (r) => r.location == “Prerov” ) Generated Flux Query
  29. 29. © 2019 InfluxData. All rights reserved. 29 IoT On Device Display Realtime values internal sensors data Aggregated values Using Flux from InfluxDB 2 Github repo: https://github.com/bonitoo-io/BuildAzure.IoT.Adafruit.BME280
  30. 30. © 2019 InfluxData. All rights reserved. 30 Summary & THANK YOU New Client Libraries ● For InfluxDB 2 ● Java, C#, Python (alpha), Scala and Kotlin Support ○ Query, Write, Management API ○ High performance/reliability write and query ○ Easy to use ● Github repo: https://github.com/influxdata Embedded analytics ● InfluxDB Client libraries (Query API) ● Demo github repo: https://github.com/bonitoo-io/influxdata-iot-petstore

×