What You'll Learn
Use Grafana's time range in API queries
Query production runs with OEE metrics
Transform API responses with JSONata
Query downtimes for analysis
Completed Tutorial 4.1 (Introduction to Infinity)
Understanding of GET requests and JSONPath
In the previous tutorial, you learned to make basic GET requests. Now we'll cover:
Dynamic time ranges – Connect Grafana's time picker to API queries
Production runs – Query runs with built-in OEE metrics
Response transformation – Extract and reshape nested data with JSONata
Downtimes – Query machine downtime records
Dynamic Time Ranges
Hard-coded dates aren't useful for real dashboards. Let's connect queries to Grafana's time picker.
Grafana Time Variables
Grafana provides built-in variables for the selected time range:
Variable
Description
Example Value
Start time (milliseconds)
These variables update automatically when users change the dashboard time picker.
Production Runs
The production-runs endpoint returns not just run information, but also OEE metrics for each run.
What's in a Production Run?
Each production run includes:
uuid, machine, product, production_order
quantity_total, quantity_yield, quantity_scrap
productivity, availability, performance, quality
average_throughput, maximum_run_speed
Query Parameters
Filter runs starting from (ISO format)
Filter runs up to (ISO format)
Filter by product external ID
Your First Time-Filtered Query
Let's create a panel showing production runs for the selected time range.
Step 1: Create a Panel
Create a new panel with Table visualization
Select Infinity data source
Step 3: Add Time-Filtered URL
Use Grafana's time variables in the URL query parameters:
[SCREENSHOT: Infinity query with time variables in URL]
Step 4: Set Root Selector
Step 5: Test Time Filtering
Set dashboard time range to "Last 7 days"
Check that the panel shows production runs for that period
[SCREENSHOT: Production runs table with time picker]
Understanding the Response
The production-runs response includes nested OEE data:
Notice that OEE metrics and quantities are nested objects. We'll use JSONata to extract these values.
Extracting Nested Values with JSONata
JSONata is a query language for transforming JSON. It goes beyond JSONPath and lets you reshape data.
Basic Extraction
To extract OEE scores from production runs, use this root selector:
Result:
production_order
start
end
productivity
availability
performance
quality
[SCREENSHOT: Clean production runs table with OEE scores]
Common Patterns
Extract single value:
Extract quantity values:
Handle missing data:
Calculate values:
Adding Columns for Better Display
Instead of using JSONata to reshape everything, you can also use Columns in the Infinity query to select specific fields.
Step 1: Add Columns
Scroll to the Columns section and add:
[SCREENSHOT: Columns configuration]
In Field overrides, add formatting:
Override fields matching /score$/ (regex):
Override "Yield" field:
Unit: Use the unit from your data (e.g., kg, m)
Visualizing OEE in Tables
For OEE scores, gauge cells provide great visualization:
Add override for fields matching /score$/
[SCREENSHOT: Production runs table with gauge cells]
Colored Background
Alternatively, use colored backgrounds:
Set Cell type to Colored background
Set Color mode to Background (gradient)
Stat Panels for Single Values
Show the latest production run's OEE as a stat panel:
Step 1: Create Stat Panel
Add new panel with Stat visualization
Configure Infinity query for production-runs
Step 2: Extract Single Value
Use JSONata to get just the productivity score from the most recent run:
Root selector:
Red < 0.6, Yellow < 0.8, Green >= 0.8
[SCREENSHOT: OEE stat panel]
Query machine downtime records for analysis.
downtimes?machine={uuid}&start=${__from:date:iso}&end=${__to:date:iso}
Query Parameters
Filter by machine UUID(s)
Filter downtimes starting from
Example: Recent Downtimes
Calculating Downtime Duration
Use JSONata to calculate duration in minutes:
Combining Production Runs from Multiple Machines
Using Computed Columns
When querying multiple machines, add a machine name column:
Query A (Kiefel):
URL: production-runs?machine=141e0927-62b3-4e76-8398-ad82d20f397f&start=${__from:date:iso}&end=${__to:date:iso}
In Computed columns, add:
Selector: "Kiefel" (literal string in quotes)
Query B (Macchi):
URL: production-runs?machine=cc0d2dcb-564b-48cd-a342-71765a536058&start=${__from:date:iso}&end=${__to:date:iso}
In Computed columns, add:
Merging Results
Add a Merge transformation to combine both queries into one table.
[SCREENSHOT: Multi-machine production runs table]
Joining with Product Data
Production runs contain a product field with a UUID, but not the product name or external ID. To display the product's external ID (from your ERP/MES), you need to join with the products endpoint.
The production-runs response only contains:
But you want to display:
Use multiple queries and Grafana's Join transformation.
Step 1: Create Two Queries
Query A (Production Runs):
production-runs?machine=141e0927-62b3-4e76-8398-ad82d20f397f&start=${__from:date:iso}&end=${__to:date:iso}
Add columns:
Query B (Products):
Add columns:
Important: The join field must have the same column name in both queries (product_uuid).
[SCREENSHOT: Two queries configured for join]
Add Join by field transformation
[SCREENSHOT: Join transformation configuration]
Step 3: Clean Up with Organize
Add Organize fields transformation to:
Hide the duplicate product_uuid column
Reorder columns as desired
Order
Product ID
Product Name
Start
OEE
[SCREENSHOT: Final joined table with product information]
Only rows with matches in both queries
All rows from both queries
All rows from first query, matches from second
All rows from second query, matches from first
For production runs + products, use OUTER or LEFT to keep all runs even if product data is missing.
Error Handling and Debugging
Verify endpoint and machine UUID
Missing column extraction
Add Columns or use JSONata
Check Network Tab
Open browser DevTools (F12)
Check request URL and response
Test with Table First
Always start with Table visualization
Easier to see raw data structure
Switch to other visualizations after data works
Simplify Root Selector
Then add JSONata transformations
Use Debug Transformation
See exactly what data Grafana receives
Practical Exercise
Build a production overview dashboard:
Production Runs Table
Query production-runs for Kiefel machine
Filter by dashboard time range
Extract: order, start, end, OEE scores, yield
Display OEE as gauge cells
Latest Run Stats
Four stat panels: Productivity, Availability, Performance, Quality
Extract from most recent run with $.data[0]
Use thresholds for color coding
Downtimes Table
Query downtimes for same machine and time range
Show start, end, calculated duration
You've learned to query production data with dynamic time ranges:
Use ${__from:date:iso} and ${__to:date:iso} in URL parameters
Query production runs with built-in OEE metrics
Extract nested values with JSONata
Visualise OEE with gauge cells and stat panels
Query and analyse downtimes
Continue with:
Quick Reference
JSONata Cheat Sheet
Endpoint
Method
Description
Production history with OEE