September 17, 2019 · 4 min read · IT / Observability

IdleTimeWatcher

How I built IdleTimeWatcher — a Zabbix + Grafana solution that tracks real-time workstation activity across a networked office.

Features

  • Visual real-time user activity monitoring when workstation is in use
  • Time counter showing inactivity duration in seconds when workstation is inactive
  • Email alerts when users log in and log out of their machines

Background

I had a LAMP server already, with Zabbix and Grafana monitoring the network already. I needed to find out when employees logged into their computers and when they left for the day. I extracted the value of the last time there was interaction with the computer using the Windows GetLastInput API function, then created a loop with a sleep interval between 2 and 10 seconds to send this value to Zabbix with the Zabbix_Sender.

Requirements

  • LAMP Server
  • Zabbix Server
  • Grafana Server

Installation Instructions

Download the source code on GitHub or grab the master.zip.

In Zabbix, create a new item on the host you want to monitor. The key name must be idletime and the units should be set to seconds.

Modify Settings

Copy the program to C:\IdleTime\ on the target workstation. Open IdleTime.exe.config and set the following three values:

ZabbixSenderLocation — path to zabbix_sender.exe

ZabbixServerLocation — IP address of your Zabbix server

ZabbixLogLocation — default: C:\zabbix\IdleTime.log

Create a Scheduled Task

Open Task Scheduler and create a new task. Use the following settings across each tab:

General

  • Name: IdleTime
  • User account: your Windows username
  • Select Run only when user is logged on

Triggers

  • Begin the task: At logon
  • Repeat task every: 5 minutes, for a duration of Indefinitely

Actions

  • Action: Start a program
  • Program/script: browse to idletime.exe

Conditions

  • Network: Run only if connected to the network

Settings

  • Restart every: 1 minute
  • Uncheck: Stop the task if it runs longer than
  • If the task is already running: Do not start a new instance

Triggers

Create a Zabbix trigger on the host to alert when the workstation stops reporting. Use the following expression:

{MyHostname:idletime.nodata(5m)}=1

Set the messages as follows:

  • Problem: {HOST.NAME} Has Logged out.
  • Recovery: {HOST.NAME} Has Logged In.

Optional — Grafana Panel Setup & Email Alerting

Email Alerting for Attendance Notifications

Zabbix can fire email notifications on trigger state changes. Wire the trigger above to a Zabbix media type with your SMTP settings. You'll get an email when any workstation logs in or out — a lightweight attendance log without any dedicated HR software.

Grafana Panel Setup

In Grafana, add a Singlestat panel pointing at your idletime Zabbix item. Use the following settings:

  • Unit: Time → seconds or hh:mm:ss
  • Thresholds: 300, 1800 — green under 5 min, orange 5–30 min, red over 30 min
  • Value mapping: nullOut (shows when host is offline)
  • History: 5 minutes recommended

Each workstation gets its own panel. At a glance you can see the whole office: who is active, who has stepped away, and for how long. The panels update every few seconds and turn red after the configured inactivity threshold — useful for catching machines left unattended.