Repository navigation
Closed
Labels
enhancementNew features or improvements of some kind, as opposed to a problem (bug)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussion
Milestone
Description
Currently we do a hash benchmark. We track transfer rates. There are often support issues on sync being slow, and narrowing down the cause is tricky. To help that out we could sample our operations to perhaps be able to present useful data. Things we could measure:
- Per device block request data; time taken for each request-response and the amount of data thus transferred. (This would aggregate to per-device and total transfer rates.)
- Per block write stats. Time taken to write a block (and size) and the operation that caused it (copy or transferred).
- Per block read stats. Time to read a block (and size) and why (copy, incoming request, etc).
- Per block verification stats. Time to verify block hashes.
- Per block database lookup stats. Time to iterate or look up candidate blocks from database.
- General database stats: time per get/set operation. (Timing iterations is trickier.)
- etc
We already keep some counters for block actions, but not fine grained and not with timing metrics.
One way to expose this could be as a prometheus endpoint, which then also buys us the data types for tracking histograms or percentiles of these things.
Actually showing, interpreting and understanding the data is another issue. Having it accessible as an endpoint that can be viewed (and included in a future "support bundle" thing) could be a good start.
Reacted by Script Mak3r, Dmitry Gorohov, sisu4syncthing, Aurélien Rainone and Peter Hoeg
Reacted by h1z1
Metadata
Metadata
Assignees
Labels
enhancementNew features or improvements of some kind, as opposed to a problem (bug)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussion
Activity
h1z1 commentedon Sep 10, 2018
Unless it were completely optional - and default off - that kind of data would indicate what kind of hardware is behind a node. See #5160
calmh commentedon Sep 11, 2018
It can also reveal aspects about the data being synced. I’m not proposing to send these metrics somewhere, merely making them available for the user.
h1z1 commentedon Sep 11, 2018
Is that not what prometheus would enable?
calmh commentedon Sep 11, 2018
"Enable" as in for anyone who can talk to the REST API, sure. If the enemy has your API key you have already lost.
h1z1 commentedon Sep 12, 2018
Completely agree which is why the stats shouldn't be enabled by default :)
otbutz commentedon Feb 26, 2019
https://godoc.org/github.com/syndtr/goleveldb/leveldb#DBStats ?
arl commentedon Jul 21, 2019
I'd like to tackle this issue.
So from what I understand:
Exposing a local Prometheus HTTP endpoint, disabled by default, and maybe a script to run a Prometheus instance in a local docker container.
I don't know the code base really well but metrics being a transversal issue, a separate package could propose a simple api to create gauge, counters, etc. Then the core syncthing code would call that package when and where in need of instrumentation.
Does somebody has something else in mind?
Is it the right place to discuss this?
AudriusButkevicius commentedon Jul 21, 2019
Prometheus does not make it easy for it to be consumed by anything else than prometheus tho.
arl commentedon Jul 21, 2019
Yes I guess you're right. I believe you are referring to the the fact that metrics are pulled by the prom server, as opposed to other instrumentation stacks, which require clients to push their own metrics to the server.
However a prometheus server is very easily set up and running, scraping the metrics of a local syncthing instance is trivial, has its own (somewhat basic but nonetheless powerful) UI served locally.
If the objective of this issue is to have a kind of support/dev bundle one can use without prior knowledge of metrics it could be the right tool for the job, but I'm sure there are others. This is the one I know best though.
@AudriusButkevicius do you have something else in mind?
AudriusButkevicius commentedon Jul 21, 2019
I think it's ok to have prometheus support, but I think we shouls wrap prometheus in our own library, and expose N minutes of last scrapes so we could draw charts in the UI of what was happening on the device in last N minutes.
AudriusButkevicius commentedon Jul 21, 2019
Potentially use something like https://github.com/prometheus/prom2json in terms of the format we return, so that it's easy to embed into the UI.
arl commentedon Jul 21, 2019
Ok so to sum it up, and to so ensure I got the idea.
Any syncthing code that wishes to produce some metrics would do so by using the API provided by a new
metricssub-package. For client code of this API, metrics are format-agnostic, I mean they are just counter, gauges, etc. they are not prometheus counters, gauges, etc...Metrics production:
Using the package should be as simple as creating a metric of a specific type (list of types TDB), let's say a
metric.Counter, and calling some methods over that counter instance (examples would beCounter.Add(n int)orCounter.Increment().Metrics being disabled by default,
metrics.Counter(and friends) could be interfaces, so by default a no-op implementation ofmetrics.Counterand friends would be used.To enable/disable metrics, you'd have to restart syncthing.
Metrics consumption:
When metrics are enabled, syncthing would both expose:
Overall how do you envision the interaction with the UI? I mean, would the UI periodically request the last N minutes or would it be a one time thing?
AudriusButkevicius commentedon Jul 21, 2019
This is a very generic dump of thoughts:
I am not sure how we should structure the code.
My gut says dependency injection, as lib/syncthing is now a thing, and keeping it a library without any global state is a nice, so perhaps we should inject some sort of metrics provider and push it down where needed, or start pushing down context.WithValue everywhere (again, this is a larger change), where components would check presence of subcomponents if they are around and act on them. This would make fixing logging and other global things in the future easier.
It would be nice to be able to toggle most settings without requiring a restart. I guess we could do
metrics.Init(config.Wrapper)orconfig.OnChange(metrics.SetEnabled)(somewhere in cmd/syncthing before moving to lib/syncthing) to do that if we really wanted to, and keeping it global is still something we'd want to do.As for the actual exposure, it would be nice to show transfer rates for folders over time and simillar things.
We could have a mini timeseries as you say, which we'd have to poll periodically to receive updates, or we could create a new event subscription (like we have for disk events), where we do time based rather than count based retention, and publish new events as we receive recordings on the counters and gauges. This way a page refresh can get "all the events available" which will be last N seconds of points, and subscribe from there. We'd have to make sure that certain things tick often enough to have some starting data, or we write a library in a way which allows the gauges to query the current value from a reporter, oppose to the reporter reporting when the value changes, when we could check the reporters once a second.
Alternatively, we could do some mini timeseries plus followup from websocket magic or something along those lines.
I think we'll still concepts like labels, as you'll want to track per folder, per device or per folder per device metrics, so we need to add some additional dimensions.
I guess this could be just part of the metric name, but given we're piggy backing on prometheus, it would make sense to keep supporting that.
arl commentedon Jul 21, 2019
Ok
Got it.
Yes, that makes sense.
Very basic roadmap
Thanks for the briefing. It will probably take some time, that's why I wanted to establish a very basic roadmap and start to split the task into smaller ones.
metricscreation/production API, with in mind the fact that it could be enabled/disabled at runtime. IMHO it should be thought, as far as possible, as an autonomous package, and be TSDB-agnostic from the outside.There are probably a bunch of holes, but this is a start...
There's something to keep in mind for all subtasks, it's the fact that the feature should be enabled/disabled at runtime.
See you around, I'm sure I'll have many other questions.
Feel free to issue any objection, doubts, advise regarding the roadmap.
AudriusButkevicius commentedon Jul 21, 2019
I think the enabling disabling at runtime is a fairly trivial problem once you have the rest solved, you can just make counter.Add noop etc.
lapo-luchini commentedon Mar 16, 2021
There seems to be an existing external Syncthing exporter, converting current data from API to Prometheus format.
mmokrejs commentedon Dec 21, 2022
I would appreaciate if the statistics collected the delays and timeouts. Note, my system has set European timezone GMT+1 on OpenWRT router but the
1.19.2syncthing daemon has evidently got the timezone wrong. Then the timepoint is set to the past (2022-12-20 17:22:35vs.2022-12-20 17:13:53.112136263 +0000 UTC):There is no GUI settings entry nor config file entry to ensure syncthing knows local timezone.
Definitely, the connection attempts via IPv6 are just useless in my situation and just slowering the speed because my upstream WAN network does not support it. But, provided the routers kernel and syncthing binary supports IPv6 it still sttempts the connection and keeps track of locally annouced IPv6 addresses.
Merge branch 'main' into multicon
all: Add Prometheus-style metrics to expose some internal performance…