What is the easiest way to find out the "Last Seen" timestamp for a device without a browser?

I have a simple monitoring system based on Conky. (GitHub - brndnmtthws/conky: Light-weight system monitor for X.)

I would like to output the date of the last sync to conky, and in order to do that, I need the “Last Seen” timestamp at the “devices” pane in the Syncthing web ui.

I tried to play a bit with curl’ing the web interface and grepping for “Last Seen”, but to no avail, it’s all javascript, and I don’t know how to pipe that javascript into Node.js, or something.

What is the recommended way of getting the last sync date programmatically?

Thanks a lot!

Do some curl’ing of the rest api :slight_smile:

The last seen info for a device is available at /rest/stats/file: REST API — Syncthing v1 documentation

That’s a huge step forward for me! However, it says “CSRF Error”, even though I am accessing it from localhost.

Did you set the api key? Example curl command in this section: REST API — Syncthing v1 documentation

I ended up using the following command:

curl -X GET -H “X-API-Key: mykey” -s ‘http://localhost:8384/rest/stats/device’ | sed ‘s/[^[:print:]]//g’ | jq -Mar -c ‘.“DEV-ID”.“lastSeen”’ | cut -c 2-36

There is one problem with it, however: the date that the command is returning, varies from run to run:

2021-03-11T21:10:02.48504855+08:00" 2021-03-11T21:11:11.084428411+08:00"

Would it be possible to make it be of a fixed length?

1 Like

The sub-second precision is useless here - we should truncate that to seconds. Can you open an issue on github please (or a PR :wink: ).

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.