Given I run a number of Onion services, it'd probably be prudent to monitor the tor daemon.
I've had a quick search around on the net and there doesn't seem to be a tor plugin for telegraf.
However, it should be possible to create an exec
plugin based on Tor's controlspec that pulls statistics out
Activity
11-May-22 08:06
assigned to @btasker
11-May-22 08:18
OK, as step 1, let's enable ControlPort on a tor instance.
Generate a password hash
Edit
torrc
to enable the controlport and set the passwordWe can then netcat in and authenticate
11-May-22 08:32
We can pull
total bytes read (downloaded) and written (uploaded)
Daemon uptime
Current software version
Whether tor is currently active
List of circuits and their status (would need further parsing)
List of entry guards and their status
Whether self tests against the ORPort worked (will report success if orport not configured)
Get state for both ORPort and DirPort checks
Get text status of current tor version
Assessment of network state (up/down)
11-May-22 08:39
So, breaking those down into tag vs fields, I'm inclined to say
tags
fields
entry-guards would get broken down into the following fields
circuit-status needs further analysis. Section 4.1.1 of the spec details it
Will look at putting a script together later to connect in and collect these
11-May-22 18:03
Within the plugin, most of the stats to be collected are defined within a list:
The first entry in each is the command to pass with
GETINFO
into the controlport, the second is the field/tag name we provide to telegraf.type
should be one ofint
,float
,string
(I guess we should addbool
). It's ignored for tags (as they're always strings)The final index is whether it should be treated as a tag or a field.
This covers most of the items listed above - we still need to break down and parse
entry-guards
11-May-22 18:38
This is now mostly built.
Default configuration is at the top of the plugin and can be overridden via environment variable
We return some additional tags if we failed to connect (or authenticate) with the Tor daemon
Assuming that all is well, though, we return LP like this
The next step then is probably to configure this in a telegraf instance and check it all works
11-May-22 18:50
The following config can be used
Currently, it isn't possible to override env vars from within Telegraf's config, but when this is included in a release, it'll be possible to do something like
I now have data appearing in my DB - will look at creating some dashboards once there's a decent amount of data to work with
11-May-22 19:59
mentioned in commit github-mirror/telegraf-plugins@fa1995e59596784ef022d7a4cdd24da1051bfa54
Message
Report a counter of how many stats have failed to fetch. See utilities/telegraf-plugins#1
11-May-22 19:59
mentioned in commit github-mirror/telegraf-plugins@ef590847215243757dac97389708d423be018ab0
Message
Start implementing a telegraf-plugin to monitor tor for utilities/telegraf-plugins#1
This currently collects some simple stats via control port
11-May-22 19:59
mentioned in commit github-mirror/telegraf-plugins@2787c195c8c625f2e2b965b0fd80bb4455b80e8b
Message
Add file header and README for utilities/telegraf-plugins#1
11-May-22 19:59
mentioned in commit github-mirror/telegraf-plugins@2d256804d0b40f2e6887a8e73e9724bcc5419cf0
Message
Add ability to add counters based around multiline responses. see utilities/telegraf-plugins#1
12-May-22 08:15
OK, starting with the most obvious graph: network throughput
12-May-22 08:27
Graph to show an overview of guard statuses
12-May-22 08:32
Daemon uptime in minutes
12-May-22 08:45
Maximum observed upload
With it's counterpart, highest observed download rate
12-May-22 08:51
Kibibytes downloaded
12-May-22 08:57
Turning the network liveness result into a hot/cold gauge
12-May-22 09:09
Doing the same for software version assessment
12-May-22 10:16
mentioned in issue #2
13-May-22 11:13
I've published a writeup at https://www.bentasker.co.uk/posts/documentation/general/monitoring-tor-daemon-with-telegraf.html