root/lib/Core/File.pm

Revision a822bf280c9c70382c3b2c3c29a1726ae6c4f93b, 2.2 kB (checked in by Mark Harrison <mark@omniti.com>, 5 years ago)

Core::File module - stats for a single file

Replaces the following modules:

FILEAGE
FILESIZE

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@349 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Core::File;
2
3 use strict;
4 use warnings;
5
6 use base 'Resmon::Module';
7
8 use Resmon::ExtComm qw(run_command cache_command);
9
10 =pod
11
12 =head1 NAME
13
14 Core::File - information about a single file
15
16 =head1 SYNOPSIS
17
18  Core::File {
19      /path/to/filename: noop
20  }
21
22 =head1 DESCRIPTION
23
24 This module retrieves metrics on a single file such as file age and file size.
25
26 =head1 CONFIGURATION
27
28 =over
29
30 =item check_name
31
32 The check name specifies which file to monitor.
33
34 =back
35
36 =head1 METRICS
37
38 =over
39
40 =item present
41
42 Does the file exist? 1 for yes, 0 for no. If the file does not exist, the
43 other metrics will not be present.
44
45 =item permissions
46
47 The file's permissions in numeric format: e.g. 0777.
48
49 =item hardlinks
50
51 The number of hard links to the file.
52
53 =item uid, gid
54
55 The user and group ids of the file.
56
57 =item size
58
59 The file size in bytes.
60
61 =item atime, mtime, ctime
62
63 The file's access time, modification time, and inode change time respectively.
64 All of these are in seconds since the epoch.
65
66 =item aage, mage, cage
67
68 How long ago in seconds the file was accessed, modified, and changed
69 respectively.
70
71 The difference between mtime/mage and ctime/cage is that mtime only changes
72 when the file's contents change. Ctime changes when anything about the file
73 (permissions etc) change.
74
75 =back
76
77 =cut
78
79 sub handler {
80     my $self = shift;
81     my $config = $self->{config}; # All configuration is in here
82     my $file = $self->{check_name}; # The check name is in here
83     my @statinfo = stat($file);
84
85     if (!@statinfo) {
86         # File is missing
87         return {
88             "present" => [0, "i"]
89         }
90     } else {
91         my $now = time;
92         return {
93             "present" =>    [1, "i"],
94             "permissions" => [sprintf("%04o", $statinfo[2] & 07777), "s"],
95             "hardlinks" =>  [$statinfo[3], "i"],
96             "uid" =>        [$statinfo[4], "s"],
97             "gid" =>        [$statinfo[5], "s"],
98             "size" =>       [$statinfo[7], "i"],
99             "atime" =>      [$statinfo[8], "i"],
100             "mtime" =>      [$statinfo[9], "i"],
101             "ctime" =>      [$statinfo[10], "i"],
102             "aage" =>       [$now - $statinfo[8], "i"],
103             "mage" =>       [$now - $statinfo[9], "i"],
104             "cage" =>       [$now - $statinfo[10], "i"]
105         };
106     };
107 };
108
109 1;
Note: See TracBrowser for help on using the browser.