DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Pivot and Join Time Series Data in Flux
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?
  • Fixing Common Oracle Database Problems

Trending

  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  • Google Cloud Document AI Basics
  • Emerging Data Architectures: The Future of Data Management
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to: Building Flux Queries in Chronograf

How to: Building Flux Queries in Chronograf

Building Flux queries in Chronograf has never been easier.

By 
David G. Simmons user avatar
David G. Simmons
DZone Core CORE ·
Nov. 19, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
10.9K Views

Join the DZone community and get the full member experience.

Join For Free

As you all may or may not know (and if you don't, you haven't been reading my posts!), I've built an embedded IoT gateway proof of concept device that runs (of course) InfluxDB-really the entire TICK Stack-and collects data from connected Bluetooth, Wi-Fi, and LoRa sensors.

The latest releases of InfluxDB and Chronograf are now available, and with each of these, comes the technical preview of Flux, the new query language for working with time series data. I thought it might be instructive to see how difficult it was going to be to convert the queries that I use to build my dashboard from InfluxQL to Flux and generally explore the language itself. So here goes.

The Dashboard

That's all the sensor data. The radiation sensor is off-line right now and how it looks on-screen. Each of those dashboard elements is created and updated via an InfluxQL query via Chronograf. So, let's look at some of the queries and what they look like in the Chronograf Dashboard Builder today. We'll start with that CO2 reading at the upper left.

To be perfectly clear: I did not have to write that query. I simply started exploring the database, clicking on measurements, tags and values, and adjusting the settings until I got the visualization I was looking for. Easy enough.

So, let's try building that same query in using InfluxDB 1.7, Chronograf 1.7, and using the new Flux Builder along with the Schema Explorer:

Wow! That was easy!

It's very, very similar. In the Flux example, we start with where we're going to get the data-the 'from bucket,' and then give it the time interval, and finally, we filtered it by the measurement and field.

Next, we add the window(every: autoInterval) to the query. Flux's window() function groups records based on a time value. Using the every: parameter along with autoInterval allows Chronograf to dynamically determine the size of the window based on the screen real-estate that is available for visualizing the results.

And here's what the Flux query looks like in the end:

from ( bucket: "telegraf/autogen" )
   |> range(start: dashboardTime)
   |> filter (fn: (r) => r._measurement == "k30_reader" and (r_field == "co2" )) 
   |> window (every: autoInterval)


Flux takes input tables, performs a function, and produces one or more output tables. So far, we've defined an input table. Now, we add the mean() aggregate function to get the mean CO2 reading within each window. Each window is returned as an output table. By adding the group() function with the none:true parameter, we remove the window partitions and combine the aggregates into a single output table.

The resulting query looks like this:

from(bucket: “telegraf/autogen”)
  |> range(start: dashboardTime)
  |> filter(fn:(r =>r._measurement == “k30_reader” and (r._field == “co2”))
  |> window(every: autoInterval)
  |> mean()
  |> group(none:true)


The original query used the template variable :dashboardTime: to allow the user to adjust the time range of the query through the user interface controls provided within Chronograf, without forcing them to re-adjust the query itself. This same functionality is supported within Flux, too. The ScriptWizard drops this into the |> range filter by default.

Now, we can visually compare the results by flipping back and forth between the InfluxQL and the Flux version of these queries to see that they indeed yield the same results!

What About FILL?

In the technical preview of Flux, the fill functionality hasn't been implemented. We understand this is an important part of how to visualize sparse data, and, rest assured, we are working to implement this in a future update.

Database Flux (machine-learning framework)

Published at DZone with permission of David G. Simmons, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Pivot and Join Time Series Data in Flux
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?
  • Fixing Common Oracle Database Problems

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!