Skip to content

Device connection state metric #9527

Closed

Description

@DerRockWolf

Feature description

A new metric that exposes the connection state of each device as a gauge value (e.g., 0 = disconnected; 1 = connected, ...).

Problem or use case

I have an android device where the operating system frequently kills the syncthing app.
I want to monitor, using prometheus, whether the device is connected with my central syncthing node and get alerted if it is disconnected for an extended period of time.

Alternatives or workarounds

Create a custom exporter that uses the syncthing API.


If this is something you would be interested into having, I can try to open a PR for it.

Activity

  1. added
    enhancement
    needs-triage
    on May 3, 2024
  2. calmh commented on May 3, 2024

    @calmh
    Member

    Sounds reasonable. I'd probably make it a gauge on the number of connections, so zero is disconnected and then positive numbers for connected devices.

  3. DerRockWolf commented on May 3, 2024

    @DerRockWolf
    ContributorAuthor

    Sounds reasonable. I'd probably make it a gauge on the number of connections, so zero is disconnected and then positive numbers for connected devices.

    Oh, then I probably didn't phrase it good enough 😅

    My plan was to do it specific to the device ID, e.g.,

    # specific device connected:
    syncthing_protocol_connection_state{device="DEVICE-A"} 1
    # specific device not connected:
    syncthing_protocol_connection_state{device="DEVICE-B"} 0
    
  4. calmh commented on May 3, 2024

    @calmh
    Member

    I agree, but a single device can have an arbitrary number of active connections nowadays. So, what you're proposing, but 1 can also become 3 or 28.

    syncthing_protocol_connections_active{device="DEVICE-A"} 28 # connected, large number of concurrent data connections
    syncthing_protocol_connections_active{device="DEVICE-b"} 0 # disconnected
    
  5. DerRockWolf commented on May 3, 2024

    @DerRockWolf
    ContributorAuthor

    I agree, but a single device can have an arbitrary number of active connections nowadays. So, what you're proposing, but 1 can also become 3 or 28.

    syncthing_protocol_connections_active{device="DEVICE-A"} 28 # connected, large number of concurrent data connections
    syncthing_protocol_connections_active{device="DEVICE-b"} 0 # disconnected
    

    Got it, thanks for clarifying.

    I'll try to implement it and open a PR 🙂

  6. DerRockWolf commented on May 4, 2024

    @DerRockWolf
    ContributorAuthor

    After looking around a bit I found connections.accountAddedConnection & connections.accountRemovedConnection as functions where I can add the Inc & Dec calls. The connections package currently doesn't have its own metrics.go, so I would add one.

    I however don't know if this is the best location. I've also found protocol.NewConnection & protocol.internalClose and model.AddConnection & model.Closed.
    It would be great if you could point me to the location you would consider to be suitable.

  7. calmh commented on May 4, 2024

    @calmh
    Member

    I think the accounting functions you found are a good place. There's probably some map or slice there that has the number of connections you can get the length of, or just pair the inc/dec as you say.

  8. added 2 commits that reference this issue on May 4, 2024
    43c6b10
    02c4118
  9. added 2 commits that reference this issue on May 4, 2024
    debbe72
    e2d1963
  10. added this to the v1.27.8 milestone on May 22, 2024
  11. added a commit that references this issue on May 24, 2024
    14bbd3a
  12. LinuxOnTheDesktop commented on Jun 5, 2024

    @LinuxOnTheDesktop

    So (if I may) how does one use this new functionality? I am not even clear whether the new feature is GUI or CLI.

  13. er-pa commented on Jun 5, 2024

    @er-pa
    Member

    So (if I may) how does one use this new functionality? I am not even clear whether the new feature is GUI or CLI.

    Syncthing exposes a bunch of metrics on .../metrics (e.g. 127.0.0.1:8384/metrics) which can be handled by some prometheus instance or alike. And this change simply exposes one more metric there.

    https://docs.syncthing.net/users/metrics.html

  14. added 2 commits that reference this issue on Jul 7, 2024
    685d17e
    199e176
  15. added
    frozen-due-to-age
    on May 5, 2025
  16. locked and limited conversation to collaborators on May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrozen-due-to-ageneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions