Skip to content

Commit

Permalink
Merge pull request influxdata#223 from influxdata/airquality
Browse files Browse the repository at this point in the history
feat: Air Quality community template
  • Loading branch information
mhall119 authored Jan 28, 2021
2 parents 38f72a4 + 465fc01 commit 1a95c32
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Start by reading [how to use a template](docs/use_a_template.md), then check eac

| Template | Description | Author |
|----------------------|-------------|:------:|
| [Air Quality](airquality/) | Retrieve air quality statistics from the US EPA website | [Kristina Robinson](https://github.com/kristinarobinson) |
| [Algorithmia](algorithmia/) | Monitor machine learning model performance metrics | [@koverholt](https://github.com/koverholt) |
| [Apex Legends](apex_legends/) | Collect player metrics from the game Apex Legends | [@b3vis](https://github.com/b3vis) |
| [AWS Cloudwatch Monitoring](aws_cloudwatch/) | Monitor AWS EC2 and ELB | [bonitoo.io](.) |
Expand Down
66 changes: 66 additions & 0 deletions airquality/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Provided by: Kristina Robinson

Air Quality (Ozone and Small Particulates per Million) by zipcode from the U.S. EPA AirNow.gov API.

Quick Install

InfluxDB UI

In the InfluxDB UI, go to Settings-> Templates and enter this URL: http://raw.githubusercontent.com/influxdata/community-templates/master/airquality/airquality.yml

InfluxCLI

If you have your InfluxDB credentials configured in teh CLI, you can install this template with:
```influx apply -u https://raw.githubusercontent.com/influxdata/community-templates/master/airquality/airquality.yml```


Included Resources

* 1 Bucket: `airquality`, 30 day retention (or you may use your own bucket)
* 1 Label: `airquality`
* 1 Telegraf Configuration `airquality-telegraf-config`
* 1 Dashboard: `Air Quality`
* 1 Variable: `bucket` (allows any bucket to be used)

Setup Instructions

Go to https://docs.airnowapi.org/account/request/ to request account access.
Go to https://docs.airnowapi.org/forecastsbyzip/query, and build your URL as follows:
* Enter the zip code of interest
* Select `application/json` from the Format dropdown
* Click `Build`
* Copy the URL string.
* Create an environment variable call `INFLUX_AIRQUAL_URL` and use the copied URL string, but remove the date parameter (this allows the call to always retrieve the current date).

Example URL String:
```
"https://www.airnowapi.org/aq/forecast/zipCode/?format=application/json&zipCode=99999&distance=25&API_KEY=A1B2C3D4-A1B2-A1B2-A1B1-A1B2C3D4E5F6"
```

Telegraf Configuration requires the following environment variables:

INFLUX_TOKEN - The token with the permissions to read Telegraf configs and write data to the telegraf bucket. You can just use your operator token to get started.
INFLUX_ORG - The name of your Organization
INFLUX_HOST - The url of the cloud instance where InfluxDB runs
INFLUX_BUCKET - The name of the bucket to put data into. Default is `airquality`.
INFLUX_AIRQUAL_URL - The constructed URL to call the airnow API. Instructions above.
You MUST set these environment variables before running Telegraf using something similar to the following commands

* This can be found on the Load Data > Tokens page in your browser: export INFLUX_TOKEN=TOKEN
* Your Organization name can be found on the Settings page in your browser: export INFLUX_ORG=my_org
* The host is the base URL of your cloud instance: export INFLUX_HOST=https://my-cloud.cloud2.influxdata.com
* INFLUX_BUCKET is the bucket to store the Air Quality data. export INFLUX_BUCKET=airquality
* INFLUX_AIRQUAL_URL should be set to the airnow API URL, without a date param. export INFLUX_AIRQUAL_URL=https://www.airnowapi.org/aq/forecast/zipCode/?format=application/json&zipCode=99999&distance=25&API_KEY=A1B2C3D4-A1B2-A1B2-A1B1-A1B2C3D4E5F6

Start Telegraf on your local machine with the instructions provided from the Setup Instructions popup (click Data, Telegraf, Setup Instructions).


Contact

Author: Kristina Robinson

Email: [email protected]

GitHub: @kristinarobinson

Slack: @Kristina Robinson
226 changes: 226 additions & 0 deletions airquality/airquality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
name: flamboyant-leakey-f37001
spec:
color: '#67d74e'
name: airquality
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: ridiculous-keller-caf001
spec:
associations:
- kind: Label
name: flamboyant-leakey-f37001
language: flux
name: bucket
query: |-
buckets()
|> filter(fn: (r) => r.name !~ /^_/)
|> rename(columns: {name: "_value"})
|> keep(columns: ["_value"])
type: query
---
apiVersion: influxdata.com/v2alpha1
kind: Bucket
metadata:
name: musing-grothendieck-f37005
spec:
associations:
- kind: Label
name: flamboyant-leakey-f37001
name: airquality
retentionRules:
- everySeconds: 2.592e+06
type: expire
---
apiVersion: influxdata.com/v2alpha1
kind: Dashboard
metadata:
name: serene-yonath-337001
spec:
associations:
- kind: Label
name: flamboyant-leakey-f37001
charts:
- colors:
- hex: '#7CE490'
id: "0"
name: honeydew
type: min
- hex: '#FFD255'
id: 32aeb4df-7946-405e-bd74-ec9336d1b26a
name: thunder
type: threshold
value: 51
- hex: '#F48D38'
id: 91f149f0-3060-4ac1-91c1-66c38139b9aa
name: tiger
type: threshold
value: 101
- hex: '#F95F53'
id: 63cc456e-8de9-4954-b9a1-3d35ae1e72a3
name: curacao
type: threshold
value: 151
- hex: '#513CC6'
id: 6ff114b1-61d3-480e-b9d5-0319c847df6e
name: planet
type: threshold
value: 201
- hex: '#BF3D5E'
id: ed566b2f-9cf5-4d32-a94b-bcfc4defd011
name: ruby
type: threshold
value: 301
- hex: '#BF3D5E'
id: "1"
name: ruby
type: max
value: 500
decimalPlaces: 2
height: 4
kind: Gauge
name: Current PM2.5 Gauge
queries:
- query: |-
from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["ParameterName"] == "PM2.5")
|> filter(fn: (r) => r["_field"] == "AQI")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "last")
width: 4
- axes:
- base: "10"
name: x
scale: linear
- base: "10"
name: y
scale: linear
colors:
- hex: '#31C0F6'
id: 9a009419-c2b6-47ce-bc5e-bec960ccc1c9
name: Nineteen Eighty Four
type: scale
- hex: '#A500A5'
id: 4696c34e-fc79-4ba1-a6a1-2c93b864f47e
name: Nineteen Eighty Four
type: scale
- hex: '#FF7E27'
id: 9664276e-2f02-4749-af44-113ca213def0
name: Nineteen Eighty Four
type: scale
geom: line
height: 4
hoverDimension: auto
kind: Xy
legendOpacity: 1
legendOrientationThreshold: 10
name: Air Quality Trends
position: overlaid
queries:
- query: |-
from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["ParameterName"] == "O3" or r["ParameterName"] == "PM2.5")
|> filter(fn: (r) => r["_field"] == "AQI")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "last")
width: 8
xCol: _time
yCol: _value
yPos: 4
- colors:
- hex: '#4ED8A0'
id: "0"
name: rainforest
type: min
- hex: '#FFD255'
id: 901cb28f-0c21-4dd8-a946-860cc23bb589
name: thunder
type: threshold
value: 51
- hex: '#F48D38'
id: 056816bd-08d4-4882-b667-772f050c8b63
name: tiger
type: threshold
value: 101
- hex: '#F95F53'
id: 91f149f0-3060-4ac1-91c1-66c38139b9aa
name: curacao
type: threshold
value: 151
- hex: '#513CC6'
id: 63cc456e-8de9-4954-b9a1-3d35ae1e72a3
name: planet
type: threshold
value: 201
- hex: '#BF3D5E'
id: 6ff114b1-61d3-480e-b9d5-0319c847df6e
name: ruby
type: threshold
value: 301
- hex: '#BF3D5E'
id: "1"
name: ruby
type: max
value: 500
decimalPlaces: 2
height: 4
kind: Gauge
name: Current Ozone Quality
queries:
- query: |-
from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["ParameterName"] == "O3")
|> filter(fn: (r) => r["_field"] == "AQI")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "last")
width: 5
xPos: 4
name: Air Quality
---
apiVersion: influxdata.com/v2alpha1
kind: Telegraf
metadata:
name: airquality-telegraf
spec:
associations:
- kind: Label
name: flamboyant-leakey-f37001
name: airquality-telegraf-config
config: |
[[outputs.influxdb_v2]]
## The URLs of the InfluxDB cluster nodes.
urls = ["$INFLUX_HOST"]
## Token for authentication.
token = "$INFLUX_TOKEN"
## Organization is the name of the organization you wish to write to; must exist.
organization = "$INFLUX_ORG"
## Destination bucket to write into. Default should be set to 'airquality'
bucket = "$INFLUX_BUCKET"
# interval at which the API is called. air quality is only updated 1-2 times per day
[agent]
interval = "12h"
# Read formatted metrics from one or more HTTP endpoints
[[inputs.http]]
## One or more URLs from which to read formatted metrics
urls = ["$INFLUX_AIRQUAL_URL"]
## HTTP method
method = "GET"
## List of success status codes
success_status_codes = [200]
## Data format to consume.
data_format = "json"
json_time_key = ["DateForecast"]
json_time_format = "2006 01 02 "
tag_keys = ["Category_Name", "ParameterName", "Latitude", "Longitude", "ReportingArea"]
json_string_fields = ["ActionDay"]

0 comments on commit 1a95c32

Please sign in to comment.