Focus Exporter is a Prometheus Exporter for Windows, designed to collect and monitor metrics about your time spent on Windows.
Inspired by Windows-Exporter, Focus Exporter uses a combination of Windows API calls to collect and expose metrics about active windows, user inactivity, and focused window durations.
By default, exposes a prometheus metrics endpoint at http://localhost:9183/metrics
Microsoft Viva Insights offers great metrics, but they are part of a broader suite of services through office 365. Focus Exporter is my effort to collect a subset of these metrics independently. This project is my first project in Golang, any feedback is very appreciated.
- Collects metrics about focused windows and user inactivity.
- Attempts to track time spent in meetings for applications like Microsoft Teams and Zoom.
- Exposes metrics through a Prometheus endpoint.
- Configurable through command-line parameters.
- privacy mode to avoid exposing sensitive window titles.
Focus Exporter exposes the following metrics:
Metric Name | Description | Labels | Type |
---|---|---|---|
focused_window_pid |
Process ID of the currently focused window | hostname , username , window_title , process_name |
Gauge |
focus_inactivity_seconds_total |
Total seconds of user inactivity | hostname , username |
Counter |
focused_window_changes_total |
Total number of times the focused window has changed | hostname , username |
Counter |
focused_window_duration_seconds |
Duration in seconds the window has been focused | hostname , username , process_name |
Counter |
meeting_duration_seconds |
Duration in seconds spent in a meeting | hostname , username , meeting_subject |
Counter |
go_* |
Standard suite of Go application metrics | Various | Various |
Serves an endpoint at http://$host:$port/metrics
that must be scraped by a Prometheus metrics server. Data can be visualized in a program such as Grafana. Example dashboards coming soon.
This does not need to be ran as a Priviledged user.
A scheduled task can be used to run this service at logon.
-inactivityThreshold
: The threshold in seconds for detecting user inactivity (default: 60 seconds).-interface
: The network interface to listen on (default: all interfaces).-port
: The port to listen on (default: 9183).-private
: When true, the window title will be replaced with the process name for increased privacy.-debug
: When true, output all values to the console.
>./focus-exporter
This will start a server at http://localhost:9183/metrics
and expose all metrics.
>./focus-exporter -inactivityThreshold 120
This will start a server at http://localhost:9183/metrics
with an inactivity threshold of 2 minutes.
>./focus-exporter -interface 192.168.1.1 -port 9090
This will start a server at http://localhost:9000/metrics
and expose all metrics.
>./focus-exporter -private
This will start a server at http://localhost:9183/metrics
and will not expose the full Window_Title in metric labels.
>./focus-exporter -debug
This will start a server with debugging, which prints collected values to the console.
-
Clone the repository:
>git clone https://github.com/yourusername/focus-exporter.git
-
Navigate to the project directory:
>cd focus-exporter
-
Build the project:
>go build -ldflags -H=windowsgui exporter.go
-
Run the exporter:
>./exporter.exe
(with optional flags):
>./exporter.exe -debug -interface <ip or hostname> -port <port> --inactivityThreshold -private
This project wouldn't have been possible without the help of several AI tools and open-source libraries:
- GitHub Copilot
- Google AI Studio
- ChatGPT
- Prometheus Client Golang: For metrics collection and exposition.
- golang/sys/windows: For Windows system calls and API interactions.
Special thanks to the authors of these libraries and the broader open-source community.