mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
add flag to configure scanning interval
This commit is contained in:
@@ -29,7 +29,7 @@ var bannerLines = []string{
|
|||||||
|
|
||||||
var helpText = `
|
var helpText = `
|
||||||
pspy monitors the system for file system events and new processes.
|
pspy monitors the system for file system events and new processes.
|
||||||
It prints out these envents to the console.
|
It prints these envents to the console.
|
||||||
File system events are monitored with inotify.
|
File system events are monitored with inotify.
|
||||||
Processes are monitored by scanning /proc, using file system events as triggers.
|
Processes are monitored by scanning /proc, using file system events as triggers.
|
||||||
pspy does not require root permissions do operate.
|
pspy does not require root permissions do operate.
|
||||||
@@ -56,12 +56,14 @@ var defaultRDirs = []string{
|
|||||||
"/opt",
|
"/opt",
|
||||||
}
|
}
|
||||||
var defaultDirs = []string{}
|
var defaultDirs = []string{}
|
||||||
|
var triggerInterval int
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().BoolVarP(&logPS, "procevents", "p", true, "print new processes to stdout")
|
rootCmd.PersistentFlags().BoolVarP(&logPS, "procevents", "p", true, "print new processes to stdout")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&logFS, "fsevents", "f", false, "print file system events to stdout")
|
rootCmd.PersistentFlags().BoolVarP(&logFS, "fsevents", "f", false, "print file system events to stdout")
|
||||||
rootCmd.PersistentFlags().StringArrayVarP(&rDirs, "recursive_dirs", "r", defaultRDirs, "watch these dirs recursively")
|
rootCmd.PersistentFlags().StringArrayVarP(&rDirs, "recursive_dirs", "r", defaultRDirs, "watch these dirs recursively")
|
||||||
rootCmd.PersistentFlags().StringArrayVarP(&dirs, "dirs", "d", defaultDirs, "watch these dirs")
|
rootCmd.PersistentFlags().StringArrayVarP(&dirs, "dirs", "d", defaultDirs, "watch these dirs")
|
||||||
|
rootCmd.PersistentFlags().IntVarP(&triggerInterval, "interval", "i", 100, "scan every 'interval' milliseconds for new processes")
|
||||||
|
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
}
|
}
|
||||||
@@ -75,7 +77,7 @@ func root(cmd *cobra.Command, args []string) {
|
|||||||
LogPS: logPS,
|
LogPS: logPS,
|
||||||
LogFS: logFS,
|
LogFS: logFS,
|
||||||
DrainFor: 1 * time.Second,
|
DrainFor: 1 * time.Second,
|
||||||
TriggerEvery: 100 * time.Millisecond,
|
TriggerEvery: time.Duration(triggerInterval) * time.Millisecond,
|
||||||
}
|
}
|
||||||
fsw := fswatcher.NewFSWatcher()
|
fsw := fswatcher.NewFSWatcher()
|
||||||
defer fsw.Close()
|
defer fsw.Close()
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) String() string {
|
func (c Config) String() string {
|
||||||
return fmt.Sprintf("Printing events: processes=%t | file-system-events=%t ||| Watching directories: %+v (recursive) | %+v (non-recursive)", c.LogPS, c.LogFS, c.RDirs, c.Dirs)
|
return fmt.Sprintf("Printing events: processes=%t | file-system-events=%t ||| Scannning for processes every %v and on inotify events ||| Watching directories: %+v (recursive) | %+v (non-recursive)", c.LogPS, c.LogFS, c.TriggerEvery, c.RDirs, c.Dirs)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user