Chasing the Skies: Monitoring Flights with InfluxDB

Navigate to:

We’re in an era where every move is monitored, where fans track every step of Taylor Swift’s jet-setting lifestyle. While some may dream of spotting celebrities at 30,000 feet, aviation enthusiasts and tech professionals see a broader horizon for flight traffic and monitoring.

Enter InfluxDB, the robust time series database transforming how we monitor flights in real-time. Whether it’s keeping tabs on a pop star’s private plane or ensuring commercial flights run on schedule, InfluxDB offers unprecedented insights into aviation data.

In this blog post, we’ll learn how to leverage FlightAware and InfluxDB Cloud 3.0 to monitor private/GA flight and airport delays. Then, we’ll use Grafana to build a flight monitoring dashboard. Find the corresponding repo here.

Requirements

To run this example, you’ll need the following:

You’ll also need to gather authentication credentials from your InfluxDB and FlightAware accounts. Follow these docs to learn more about how to get these credentials:

Please note that InfluxDB Cloud 3.0 offers a free tier, but you’ll need to pay for a Standard FlightAware tier to access that API. However, you can also leverage test JSON files and a test python script in the repo to try this example out before paying for live data from FlightAware.

Using the InfluxDB v3 Python Client Library to get flight data

At the core of this example is a Python Script, flightAware.py. This Python script continuously monitors and collects data about flights within specific geographic boundaries using the FlightAware AeroAPI and InfluxDB, a time-series database. The script fetches live flight data every 5 minutes. Here’s a breakdown of its key components:

  1. Environment and Libraries: First, we import all libraries and modules, such as os, requests, pandas, and influxdb_client_3. We also import datetime, timezone, and custom secret modules for secure the handling of sensitive information like API keys.
  2. Configure Variables: Next, we set up variables for database (db), organization (org), and API (url) configuration. We also retrieve authentication tokens (token) and API keys (apikey) using environment variables and a custom secret.py file. This example assumes you created a secret.py and stored your credentials there.
  3. Configure the InfluxDB v3 Python Client: We initialize an InfluxDBClient3 object with the specified host URL, token, and organization details for data storage.
python
influxdbClient = InfluxDBClient3(host=url, token=token, org=org)
  1. API Configuration and Headers: Using the API key, define the FlightAware AeroAPI endpoint and authentication header. Specify the parameters for the API request, including a geographic bounding box for flight tracking and a limit on the number of pages returned.
  2. Time Conversion Function: Include a function convert_to_utc to ensure all timestamps are in UTC. This facilitates easier data management and visualization in Grafana.
  3. Main Loop for Data Collection: This executes a perpetual loop that sends requests to the FlightAware AeroAPI to retrieve flight data within the specified parameters. It also checks if the response is successful and extracts flight details, specifically ignoring flights without a declared destination. For each valid flight, it constructs a detailed dictionary including flight identifiers, timing, geographical coordinates, and other pertinent flight data. The script also handles waypoints, extracting only the first and last for simplicity.
  4. Data Handling and Storage: Here, we merge all collected flight data into a single dictionary and convert it into a Pandas DataFrame. Then, we write this DataFrame to InfluxDB, specifying measurement and tagging configurations.
python
 for d in flight_data:
                        merged_data.update(d)
                    flight_df = pd.DataFrame([merged_data])
                    flight_df['timestamp'] = flight_df['last_position']
                    influxdbClient._write_api.write(bucket=db, record=flight_df, data_frame_measurement_name='flight', data_frame_tag_columns=['ident', 'fa_flight_id'], data_frame_timestamp_column='timestamp')

Visualizing flight data in Grafana

Now you can import the FlightAware Grafana Dashboard JSON to build a Flight Monitoring Dashboard in Grafana. For more information on importing a dashboard from JSON in Grafana please see this documentation. To query data from an InfluxDB Cloud 3.0 free-tier account, leverage the Grafana InfluxDB v3 Data Source.

Here we can see the planes in our specific area, as visualized by the map on the top left panel in this dashboard. For this example, we focus on Las Vegas. We can also look at aircraft types, destination cities, and origin cities (top right panels). We also monitor stats like average altitude, number of flights in the air, and average ground speed. We also have an Airplane Ground speed time series visualization to see how planes land and take off.

I don’t know much about different aircraft, but I imagine larger airplanes have a steeper landing and take-off speed. Finally, we also visualize the flights by major airlines, with Southwest Airlines having the most flights in Las Vegas at that time.

Additional resources and conclusion

We hope this tutorial helps you get started visualizing flight data with InfluxDB. We also want to encourage you to take a look a the following related resources to learn more about how to leverage InfluxDB with Grafana and Python:

Note: Another cool thing about this demo is that the DevRel team at InfluxData can run it entirely with Github Actions, so if you see InfluxData at a conference booth running this demo, it’s likely we’re running it remotely.

As always, get started with InfluxDB Cloud 3.0 here. If you need help, please contact our community site or Slack channel.