influxdata / docs-v2

InfluxData Documentation that covers InfluxDB Cloud, InfluxDB OSS 2.x, InfluxDB OSS 1.x, InfluxDB Enterprise, Telegraf, Chronograf, Kapacitor, and Flux.
https://docs.influxdata.com
MIT License
73 stars 275 forks source link

Update example config for "Use the HTTP input plugin #1303

Closed sjwang90 closed 2 years ago

sjwang90 commented 4 years ago

Update this... https://v2.docs.influxdata.com/v2.0/write-data/no-code/use-telegraf/use-telegraf-plugins/use-http-plugin/#example-configuration

with this...

[[inputs.http]]

  # URL for NYC's Citi Bike station data in JSON format
  urls = ["https://gbfs.citibikenyc.com/gbfs/en/station_status.json"]

  # Overwrite measurement name from default `http` to `citibikenyc`
  name_override = "citibike"

  # Exclude url and host items from tags
  tagexclude = ["url", "host"]

  # Data from HTTP in JSON format
  data_format = "json"

  # Parse data in `data.stations` path only
  json_query = "data.stations"

  #Set station metadata as tags
  tag_keys = ["station_id"]

  # JSON values to set as string fields
  json_string_fields = []

  # Latest station information reported at `lastCommunicationTime`
  json_time_key = "last_reported"

  # Time is reported in Golang "reference time" format
  json_time_format = "unix"

...to address broken link

sjwang90 commented 4 years ago

Oh and update the sample output with this:

> citibike,station_id=3771 is_installed=1,is_renting=1,is_returning=1,num_bikes_available=29,num_bikes_disabled=1,num_docks_available=0,num_docks_disabled=0,num_ebikes_available=0 1597346896000000000
> citibike,station_id=3772 is_installed=1,is_renting=1,is_returning=1,num_bikes_available=8,num_bikes_disabled=0,num_docks_available=11,num_docks_disabled=0,num_ebikes_available=3 1597345539000000000
> citibike,station_id=3773 is_installed=1,is_renting=1,is_returning=1,num_bikes_available=18,num_bikes_disabled=1,num_docks_available=1,num_docks_disabled=0,num_ebikes_available=0 1597346389000000000
> citibike,station_id=3774 is_installed=1,is_renting=1,is_returning=1,num_bikes_available=20,num_bikes_disabled=0,num_docks_available=3,num_docks_disabled=0,num_ebikes_available=0 1597346929000000000
caleb15 commented 4 years ago

to prevent the link from changing again or the format from changing I would suggest pointing the link to a free github pages website that is hardcoded to return the appropriate JSON.

caleb15 commented 4 years ago

I tested @sjwang90 's config and it worked as expected :)

Also I just realized instead of a github pages website I can do a even easier method: github gist

https://gist.githubusercontent.com/caleb15/dddc22420e7ea27a8a54258687eb578f/raw/070d1362c7186b6b290d735107d0a6cd6020733e/citibike.json

If the gist ever gets deleted a partial JSON blob (not all is needed) is below:

{
    "data": {
        "stations": [
            {
                "is_renting": 1,
                "num_bikes_disabled": 1,
                "is_installed": 1,
                "num_bikes_available": 10,
                "legacy_id": "72",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 2,
                "station_id": "72",
                "last_reported": 1604455485,
                "num_docks_disabled": 0,
                "num_docks_available": 44,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 2,
                "is_installed": 1,
                "num_bikes_available": 25,
                "legacy_id": "79",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 0,
                "station_id": "79",
                "last_reported": 1604455168,
                "num_docks_disabled": 0,
                "num_docks_available": 6,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 1,
                "is_installed": 1,
                "num_bikes_available": 17,
                "legacy_id": "82",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 0,
                "station_id": "82",
                "last_reported": 1604456065,
                "num_docks_disabled": 0,
                "num_docks_available": 9,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 0,
                "is_installed": 1,
                "num_bikes_available": 43,
                "legacy_id": "83",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 1,
                "station_id": "83",
                "last_reported": 1604454968,
                "num_docks_disabled": 0,
                "num_docks_available": 19,
                "station_status": "active"
            },
            {
                "is_renting": 0,
                "num_bikes_disabled": 0,
                "is_installed": 0,
                "num_bikes_available": 0,
                "legacy_id": "116",
                "is_returning": 0,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 0,
                "station_id": "116",
                "last_reported": 86400,
                "num_docks_disabled": 0,
                "num_docks_available": 0,
                "station_status": "out_of_service"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 1,
                "is_installed": 1,
                "num_bikes_available": 43,
                "legacy_id": "119",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 1,
                "station_id": "119",
                "last_reported": 1604455328,
                "num_docks_disabled": 0,
                "num_docks_available": 9,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 1,
                "is_installed": 1,
                "num_bikes_available": 2,
                "legacy_id": "120",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 2,
                "station_id": "120",
                "last_reported": 1604456296,
                "num_docks_disabled": 0,
                "num_docks_available": 16,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 2,
                "is_installed": 1,
                "num_bikes_available": 29,
                "legacy_id": "127",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 0,
                "station_id": "127",
                "last_reported": 1604456402,
                "num_docks_disabled": 0,
                "num_docks_available": 0,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 1,
                "is_installed": 1,
                "num_bikes_available": 48,
                "legacy_id": "128",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 2,
                "station_id": "128",
                "last_reported": 1604456459,
                "num_docks_disabled": 0,
                "num_docks_available": 7,
                "station_status": "active"
            },
            {
                "is_renting": 1,
                "num_bikes_disabled": 0,
                "is_installed": 1,
                "num_bikes_available": 10,
                "legacy_id": "143",
                "is_returning": 1,
                "eightd_has_available_keys": false,
                "num_ebikes_available": 1,
                "station_id": "143",
                "last_reported": 1604455187,
                "num_docks_disabled": 0,
                "num_docks_available": 14,
                "station_status": "active"
            }
        ]
    },
    "last_updated": 1604456515,
    "ttl": 5
}
noramullen1 commented 2 years ago

Closed by https://github.com/influxdata/docs-v2/pull/3640