Hi, I actually had little progress.
First, I used this script to pull epoch nano timestamp from influxDB.
Timestamp.sh
#!/bin/bash
timestamp=$(curl -I 10.10.91.130:8086/ping 2>/dev/null | grep Date: | sed ‘s/Date: //g’)
epoch=$(date -d “$timestamp” +%s)
epoch_ns=$(($epoch * 1000000000))
#echo $epoch_ns > /etc/telegraf/script/time.txt
echo $epoch_ns
And then, this is my current config file.
[agent]
interval = “10s”
round_interval = true
metric_batch_size = 1_000
metric_buffer_limit = 10_000
collection_jitter = “0s”
flush_interval = “10s”
flush_jitter = “10s”
precision = “”
hostname = “test-db-1”
omit_hostname = false
[[outputs.influxdb]]
urls = [ “http://10.10.91.130:8086” ]
database = “Default”
retention_policy = “autogen”
write_consistency = “any”
[[inputs.cpu]]
percpu = false
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.exec]]
commands = [“/etc/telegraf/script/timestamp.sh”]
timeout = “5s”
data_format = “value”
data_type = “integer”
name_override = “timestamp”
[[processors.starlark]]
source = ‘’’
def apply(metric):
if metric.name == “timestamp” and “value” in metric.fields:
metric.time = metric.fields[“value”]
return metric
‘’’
If I test this config, this will show new influxdb line, named timestamp, generated and it’s timestamp changed.
But I couldn’t change cpu data’s timestamp, already collected with telegraf.
root@shan-db-1:/etc/telegraf# telegraf --config ./telegraf.conf --test
2024-11-02T00:08:48Z I! Starting Telegraf 1.23.0
2024-11-02T00:08:48Z I! Loaded inputs: cpu exec
2024-11-02T00:08:48Z I! Loaded aggregators:
2024-11-02T00:08:48Z I! Loaded processors: starlark
2024-11-02T00:08:48Z W! Outputs are not used in testing mode!
2024-11-02T00:08:48Z I! Tags enabled: host=test-db-1
timestamp,host=test-db-1 value=1732001797000000000i 1732001797000000000
cpu,cpu=cpu-total,host=test-db-1 usage_guest=0,usage_guest_nice=0,usage_idle=98.99999997625127,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=0.9999999995334292,usage_user=0 1730506129000000000
I tried golbal variable, but it seems starlark doesn’t support it.
how can I use epoch timestamp collected from exec plugin, and use it to replace timestamp collected from other plugin?