From 54a96fc04017c8dd423090669621d5c508bdb851 Mon Sep 17 00:00:00 2001 From: Kristina Robinson Date: Thu, 28 Jan 2021 11:19:10 -0600 Subject: [PATCH] feat:Added template for Air Quality --- airquality/README.md | 65 +++++++++++ airquality/airquality.yml | 226 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+) create mode 100644 airquality/README.md create mode 100644 airquality/airquality.yml diff --git a/airquality/README.md b/airquality/README.md new file mode 100644 index 00000000..27c9cdcd --- /dev/null +++ b/airquality/README.md @@ -0,0 +1,65 @@ +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.yaml + +InfluxCLI + +If you have your InfluxDB credentials configured in teh CLI, you can install this template with: +```influx apply -u https://rawgithubusercontent.com/influxdata/community-templates/master/airquality/airquality.yaml``` + + +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. +Inside InfluxDB, click Data, Telegraf and edit the airquality-telegraf-config file. Under the `[[inputs.http]]` section, paste the url value copied from the previous step where it says "CHANGEME". +* Remove the date parameter from the URL string, to always retrieve the current date. +Save your Telegraf config file. + +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 + +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 + +Start Telegraf on your local machine with the instructions provided from the Setup Instructions popup (click Data, Telegraf, Setup Instructions). + + +Contact + +Author: Kristina + +Email: kristina@influxdata.com + +GitHub: @kristinarobinson + +Slack: @Kristina Robinson diff --git a/airquality/airquality.yml b/airquality/airquality.yml new file mode 100644 index 00000000..37936b16 --- /dev/null +++ b/airquality/airquality.yml @@ -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. CHANGE THIS if you want to write to a different bucket + bucket = "airquality" + # 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 = [] + + ## 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"] \ No newline at end of file