How to get the percentage of synchronization from several devices

I have application written on C# as a server with one shared folder in SendOnly mode that send files to clients (they works in RecieveOnly mode). How can server knows about completion synchronize in percent of all clients? I think I should use /rest/db/completion on server side?

It seems you’ve answered you own question.

Ok. 1 - On server side I should use next request for one folder and all my client

var res = Get($"/db/completion?folder={folder}&device={deviceId}");

devices? Then I should calculate sum of all percents? 2 - How often do I send a request, f.e with 500 ms delay beetwen request?

You can send them serially without delay most likely.

You can the the ui code how it computes the completion I guess.

It required Send request to all client devices (all deviceID of all clients)?

Where I can find the ui code example that computes the completion?

The code is here:

You can look around for the word compeltion in that file to see what’s happening. Fields starting with an underscore are artificial fields we compute and are not returned by the API.

1 Like

OK, Thank you! I will take a look

Hello again!

1 - If I don’t do synchronization and try to call the api function GET / rest/db/completion. Does the function return me 0%?

2 - If I synchronize files and call the api function GET /rest/db/completion, will I get 0-100% progress?

3 - If the files have already been synchronized and I call the api function GET /rest/db/completion, will the value be 0 or 100%?

It shows how much of the global state is present on the device (in bytes, except when it only needs to delete files to get to the global state, then it’s 95%).

So If I don’t do synchronization or files have already been synchronized and I will try to call the api function GET / rest/db/completion I will get 0%?

I don’t understand what you mean by “don’t do synchronization”. If you have synchronized, and thus the folder is up-to-date (has the same state as the global state), then it’s 100%. If it has any less than the full global state, it’s less than a 100% (possibly 0% if it has nothing). If you don’t know the concept of “global state”, read, it’s key to understand completion (there it’s “global version” instead of state: state is the collection of all items at the global version).

1 Like

Thanks! It’s very helpful information!

Ok. I try to sync files between two devices. First device sharing folder in send only mode, second device enabled in recieve only. On recieve side I send REST request via POSTMAN and getting completion and other data = 0… But on ui I see progress…

The completion call is for information about other devices. The thing you’re looking at in the UI is for the local device. To get info about the folder locally, use /rest/db/status.


And Syncthing doesn’t return an error when you don’t specify a device at all or give an unknown device to /rest/db/completion. It just pretends that device has nothing. An appropriate error value would likely be more helpful here.


@imsodin ok. I added folder and current device ID. But I didn’t see completion data, only bytes and items!

UPD: I change device id from current device to device which I need to sync and get the completion…

@calmh is it some way to calculate progress dynamicly on current device? Could I use algorithm for calculate sync progress?

You can’t give the local (I guess that’s what you mean by current) device id to db/completion as Jakob wrote above, that’s only for remote devices (that’s admittedly non-intuitive, but that’s how it is right now). For information about the local device, use db/status. There we indeed don’t expose a percentage on the db/status endpoint, but I mean the info is there: The percentage would be needBytes / globalBytes.

1 Like

Ok! Thank you all! Could I ask you one more time please? How to calculate 100 % sync? I saw source in GitHub main repo and find:

if (total == 0) {
            $scope.completion[device]._total = 100;
            $scope.completion[device]._needBytes = 0;
            $scope.completion[device]._needItems = 0;
        } else {
            $scope.completion[device]._total = Math.floor(100 * (1 - needed / total));
            $scope.completion[device]._needBytes = needed;
            $scope.completion[device]._needItems = items + deletes;

I don’t understand how it works in if statement - When the global bytes will equal zero? F.e I get data some like this -

“globalBytes”: 105750155, I try next formula for test from your last post:

double needed = 102750155;
double total = 105750155;
double result;
result = (int)Math.Floor(Convert.ToDouble(100 * (needed / total)));

I think I get numbers similar to percentages (97 in my example)