Activity Tracker is a powerful library designed to monitor various activities on your machine using customizable, pluggable handlers. It sends periodic updates, allowing developers to take action based on real-time activity changes. Simple to install and integrate, this tool enhances responsiveness and functionality in software applications.
Activity Tracker is a versatile library designed for monitoring specific activities on your machine, providing real-time updates about user interactions. This powerful tool introduces a heartbeat functionality that periodically reports changes in activities, allowing users to respond proactively.
Key Features
- Pluggable Handlers: Easily add or remove handlers for different types of activities based on custom needs. Supported activities include mouse movements, clicks, screen changes, and system sleep/wake events.
- Customizable Intervals: Configure the heartbeat interval and worker interval to optimize performance according to specific tracking requirements, enabling precision monitoring in various scenarios.
Usage
To utilize the Activity Tracker, initiate the tracking process by configuring the heartbeat and worker intervals. Here is a simple usage example:
heartbeatInterval := 60 // interval in seconds
workerInterval := 5 // seconds
activityTracker := &tracker.Instance{
HeartbeatInterval: heartbeatInterval,
WorkerInterval: workerInterval,
LogLevel: logging.Info,
}
heartbeatCh := activityTracker.Start()
select {
case heartbeat := <-heartbeatCh:
if !heartbeat.WasAnyActivity {
logger.Infof("no activity detected in the last %v seconds", int(heartbeatInterval))
} else {
logger.Infof("activity detected in the last %v seconds.", int(heartbeatInterval))
logger.Infof("Activity type:\n")
for activityType, times := range heartbeat.ActivityMap {
logger.Infof("activityType : %v times: %v\n", activityType, len(times))
}
}
}
In this example, a tracker is set up with both mouse-click and cursor movement handlers, allowing detailed activity logging every 60 seconds.
How It Works
The Activity Tracker operates based on two primary configurations:
- HeartbeatInterval: Defines the frequency at which activity reports are generated.
- WorkerInterval: Sets how often the tracker queries the handlers to fetch activity data. Understanding the relationship between these intervals is crucial for effective monitoring.
Output from the tracker includes detailed activity logs, showcasing the count of specific activities detected during each heartbeat period. For instance:
INFO[2019-03-30T15:53:01-07:00] activity detected in the last 60 seconds.
INFO[2019-03-30T15:53:01-07:00] Activity type:
INFO[2019-03-30T15:53:01-07:00] activityType : mouse-click times: 10
INFO[2019-03-30T15:53:01-07:00] activityType : cursor-move times: 12
Custom Handlers
New activity handlers can be created easily by implementing the Handler
interface, which allows for seamless integration of custom activities into the tracking system. Activities can include monitoring new actions depending on user needs, thereby extending the library's functionality.
Supported Activities
The library currently supports a range of activities:
MouseCursorMovement Type = "cursor-move"
MouseClick Type = "mouse-click"
ScreenChange Type = "screen-change"
MachineSleep Type = "machine-sleep"
MachineWake Type = "machine-wake"
Explore the full potential of the Activity Tracker by implementing it in projects that require monitoring and analysis of user interactions on various platforms.
No comments yet.
Sign in to be the first to comment.