I am attempting to create a telegraf plugin to pull data from OpenWeatherMap and place it in a weatherDB bucket. Here is what I have done so far:
[[inputs.openweathermap]]
## OpenWeatherMap API key.
app_id = "My_API_Key"
## City ID's to collect weather data from.
city_id = ["My_City_ID"]
## Language of the description field. Can be one of "ar", "bg",
## "ca", "cz", "de", "el", "en", "fa", "fi", "fr", "gl", "hr", "hu"
lang = "en"
## APIs to fetch; can contain "weather" or "forecast".
fetch = ["weather", "forecast"]
## OpenWeatherMap base URL
# base_url = "https://api.openweathermap.org/"
## Timeout for HTTP response.
# response_timeout = "5s"
## Preferred unit system for temperature and wind speed. Can be one of
## "metric", "imperial", or "standard".
units = "imperial"
## Query interval; OpenWeatherMap weather data is updated every 10
## minutes.
interval = "10m"
[[outputs.influxdb_v2]]
## The URLs of the InfluxDB cluster nodes.
urls = ["http://192.168.69.205:8086"]
## API token for authentication.
token = "My_weatherDB_read/write_API"
## Organization is the name of the organization you wish to write to; must exist.
organization = "homelab"
## Destination bucket to write into.
bucket = "weatherDB"
I have saved this into
/etc/telegraf/telegraf.d/openweathermap.conf
as I figured this would be the correct way to keep things simple for me (I hope it was correct).
Error: failed to lookup org with name “homelab”: 401 Unauthorized: unauthorized access
I feel like I must be the only one as I have yet to find another post after searching online for a while now. I am very new at this and would love to get this finally working!!
Am I required to have all configurations (inputs/outputs) in telegraf.conf, then? When I run your command, it starts telegraf, but runs it “up front”. So I checked your link and it says I have to start the service, which was already running. I restarted it and noticed the following in the status command:
Feb 18 20:21:44 debianDB telegraf[10167]: 2022-02-19T02:21:44Z E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):
There are quite a few of those lines and I am not sure what it is in reference to. My telegraf.conf should not have any edits to it.
It does appear, though, that my weatherDB bucket only received one dataset. Something is writing a lot of data to it, though. I am not sure where they are coming from.
I am running a Debian LXC (systemd).
Thank you for your assistance!
Sorry to keep editing this, I keep realizing I am wrong and need to correct what I wrote.
Did you get that error when you used the --test flag to print your line protocol points to stdout?
Or when you just tried to run the config?
in the agent portion of the config can you please change the line to debug = true from debug = false.
Thank you!
I was able to get it working by removing around 9,000 lines from telegraf.conf and only including:
# Configuration for telegraf agent
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
###############################################################################
# PROCESSOR PLUGINS #
###############################################################################
###############################################################################
# AGGREGATOR PLUGINS #
###############################################################################
###############################################################################
# INPUT PLUGINS #
###############################################################################
# Read metrics about cpu usage
[[inputs.cpu]]
## Whether to report per-cpu stats or not
percpu = true
## Whether to report total system cpu stats or not
totalcpu = true
## If true, collect raw CPU time metrics
collect_cpu_time = false
## If true, compute and report the sum of all non-idle CPU states
report_active = false
# Read metrics about disk usage by mount point
[[inputs.disk]]
## By default stats will be gathered for all mount points.
## Set mount_points will restrict the stats to only the specified mount points.
# mount_points = ["/"]
## Ignore mount points by filesystem type.
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
# Read metrics about disk IO by device
[[inputs.diskio]]
# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# Read metrics about memory usage
[[inputs.mem]]
# Get the number of processes and group them by status
[[inputs.processes]]
# Read metrics about swap memory usage
[[inputs.swap]]
# Read metrics about system load & uptime
[[inputs.system]]
Once I removed all those lines, it finally started to put information into my bucket.
I am a bit confused, though. You asked if I tried using the --test flag. Since that does not test outputs, it did not give any errors.