I'm trying https://github.com/percona/mongodb_exporter with InfluxDB scraper. I found out it's inserted as double
.
My goal is to get last data point and convert it to dateTime:RFC3339
.
ENV:
- influxdb:v2.0.1
- mongodb_exporter:v0.20.1
mongodb_exporter metrics
# HELP mongodb_mongod_replset_member_election_date The timestamp the node was elected as replica leader
# TYPE mongodb_mongod_replset_member_election_date gauge
mongodb_mongod_replset_member_election_date{name="mongo-sh0-0.mongo-sh0.default.svc.cluster.local:27017",set="rs0",state="PRIMARY"} 1.611023449e+09
I tried many ways but all of them don't work.
Try 1
from(bucket: "mongo-swag")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mongodb_mongod_replset_member_election_date")
|> filter(fn: (r) => r["_field"] == "gauge")
|> last()
|> toInt()
|> toTime()
Wrong. Get 1970-01-01T00:00:01.611023449Z
. It should be 2021-01-19T02:30:49+00:00
in this case.
Try 2
from(bucket: "mongo-swag")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mongodb_mongod_replset_member_election_date")
|> filter(fn: (r) => r["_field"] == "gauge")
|> last()
|> toString()
|> toTime()
error:
runtime error @8:6-8:14: toTime: failed to evaluate map function: parsing time "1611023449" as "2006-01-02": cannot parse "023449" as "-"
Try 3
from(bucket: "mongo-swag")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mongodb_mongod_replset_member_election_date")
|> filter(fn: (r) => r["_field"] == "gauge")
|> last()
|> map(fn:(r) => ({ r with _value: time(v: r._value) }))
error:
runtime error @6:6-6:59: map: failed to evaluate map function: cannot convert float to time
question from:
https://stackoverflow.com/questions/65899429/influxdb-2-0-how-to-convert-double-to-datetimerfc3339 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…