01 - InfluxDB: First Steps and Guide-Lines
Inhaltsverzeichnis
InfluxLine Protocol
InfluxDB line protocol is a text based format for writing points to InfluxDB.
Syntax
<measurement>,<tag_key>=<tag_value>,<tag_key>=<tag_value> <field_key>=<field_value>,<field_key>=<field_value> <timestamp>
The whitespace between the tags and the fields are required!
Example:
win_process_usage,ProcessName=ClusSvc,ID=1333 Handles=200,PagedmemorySize=102400,CPU=7
Measurement = win_process_usace
Tags = ProcessName, ID
Fields = Handles, PagedmemorySize, CPU
Syntax description
Element | Optional/Required | Description | Type |
---|---|---|---|
Measurement | Required | The measurement name. InfluxDB accepts one measurement per point. | String |
Tag set | Optional | All tag key-value pairs for the point. | Tag keys and tag values are both strings. |
Field set | Required. Points must have at least one field. | All field key-value pairs for the point. | Field keys are strings. Field values can be floats, integers, strings, or Booleans. |
Timestamp | Optional. InfluxDB uses the server’s local nanosecond timestamp in UTC if the timestamp is not included with the point. | The timestamp for the data point. InfluxDB accepts one timestamp per point. | Unix nanosecond timestamp. Specify alternative precisions with the InfluxDB API. |
PowerShell-Example to write metrics directly to an InfluxDB v1.x
Invoke-WebRequest 'http://<your_InfluxDB_server>:8086/write?db=<yourdb>' -Method POST -Body 'test_measurement_cpu,host=server01,os=windows cpuload=33 1587646932000000000'
If the response statuscode is 204 this means, it was a success!
The Timestamp is optional. (1587646932000000000 means 23. April 2020, 14:02:12.)
PowerShell-Example to write metrics directly to an InfluxDB v2.x
$Header = @{Authorization = "Token <YOUR_AUTH_TOKEN>"} Invoke-WebRequest -Uri 'http://<your_InfluxDB_server>:8086/api/v2/write?org=<INFLUX_YOUR_ORG>&bucket=<YOUR_BUCKET>' -Header $Header -Method POST -Body 'test_measurement_cpu,host=server01,os=windows cpuload=33 1587646932000000000'
If the response statuscode is 204 this means, it was a success!
The Timestamp is optional. (1587646932000000000 means 23. April 2020, 14:02:12.)
PowerShell-Example to write metrics with the Telegraf Agent to an InfluxDB
Telegraf configuration name "inputs.exec.process.conf"
[[inputs.exec]] commands = ['powershell -NoProfile -file "C:\Program Files\Telegraf\scripts\input.process.ps1"'] timeout = "1m" data_format = "influx"
PowerShell-Skript named "input.process.ps1"
$Processes = Get-Process -Name * | Select-Object ProcessName, Id, Handles, PagedmemorySize, CPU ForEach ($Process in $Processes) { Write-Output "win_process_usage,ProcessName=$($Process.ProcessName) ID=$($Process.Id),Handles=$($Process.Handles),PagedmemorySize=$($Process.PagedmemorySize),CPU=$($Process.CPU)" }
Testing the Telegraf configuration and the PowerShell script
telegraf.exe --config "C:\Program Files\Telegraf\telegraf.d\inputs.exec.process.conf" --test
More informations: https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_reference/