lib/App/ProcTrends/Config.pm

filter: Statementstmt 100% 11 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 15 / 15 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/script/server.pl ↑ Summary
1 package App::ProcTrends::Config;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 use Carp;
8  
9 =head1 NAME
10  
11 App::ProcTrends::Config - The great new App::ProcTrends::Config!
12  
13 =head1 VERSION
14  
15 Version 0.03
16  
17 =cut
18  
19 our $VERSION = '0.03';
20  
21 =head1 SYNOPSIS
22  
23 use App::ProcTrends::Config;
24  
25 my $cfg = App::ProcTrends::Config->new();
26 my $value = $cfg->some_key();
27  
28 =head1 SUBROUTINES/METHODS
29  
30 =head2 new
31  
32 The constructor.
33  
34 =cut
35  
36 sub new {
37 my $class = shift;
38 my $self = {
39 RRD_DIR => '/tmp',
40 CRON_TIMEOUT => 60,
41 CRON_PS_CMD => find_cron_ps_cmd(),
42 CRON_CPU_CORES => find_cpu_cores(),
43 CRON_CPU_THRESHOLD => 0,
44 CRON_RSS_THRESHOLD => 0,
45 CRON_RSS_UNIT => 'mb',
46 CRON_RRD_RRA => [ qw/
47 --step=60
48 RRA:AVERAGE:0.5:1:23040
49 RRA:AVERAGE:0.5:10:9216
50 RRA:AVERAGE:0.5:60:18432
51 / ],
52 CRON_RRD_DS => "GAUGE:120:0:U",
53 COMMANDLINE_START => '-1d',
54 COMMANDLINE_END => 'now',
55 COMMANDLINE_INTERVAL => 30,
56 COMMANDLINE_PROCS => undef,
57 COMMANDLINE_COMMAND => 'table',
58 RRD_START => '-1d',
59 RRD_END => 'now',
60 RRD_LINE => 'AREA',
61 RRD_STACK => 'STACK',
62 RRD_IMGFORMAT => 'PNG',
63 RRD_TITLE => "<%METRIC%> for <%PROCESS%>",
64 RRD_WIDTH => 800,
65 RRD_HEIGHT => 600,
66 };
67
68 __PACKAGE__->mk_ro_accessors( keys %{ $self } );
69 return bless $self, $class;
70 }
71  
72 =head2 find_cron_ps_cmd
73  
74 Tries to find ps then construct the ps command to use
75  
76 =cut
77  
78 sub find_cron_ps_cmd {
79 chomp( my $ps = `which ps` );
80 if ( $ps && -x $ps ) {
81 return "$ps axo pcpu,rss,args";
82 }
83 croak "ps not found";
84 }
85  
86 =head2 find_cpu_cores
87  
88 Tries to determine the # of cores on the system. If it could not detect, it will default to 1.
89  
90 =cut
91  
92 sub find_cpu_cores {
93 my $file = "/proc/cpuinfo";
94
95 if ( -f $file ) {
96 open( my $fh, "<", $file ) or die "Couldn't open $file: $!\n";
97 my @lines = <$fh>;
98 my $count = grep( /core id/, @lines );
99 return $count;
100 }
101 return 1;
102 }
103  
104 =head1 AUTHOR
105  
106 Satoshi Yagi, C<< <satoshi.yagi at yahoo.com> >>
107  
108 =head1 BUGS
109  
110 Please report any bugs or feature requests to C<bug-app-proctrends-cron at rt.cpan.org>, or through
111 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ProcTrends-Cron>. I will be notified, and then you'll
112 automatically be notified of progress on your bug as I make changes.
113  
114  
115  
116  
117 =head1 SUPPORT
118  
119 You can find documentation for this module with the perldoc command.
120  
121 perldoc App::ProcTrends::Config
122  
123  
124 You can also look for information at:
125  
126 =over 4
127  
128 =item * RT: CPAN's request tracker (report bugs here)
129  
130 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ProcTrends-Cron>
131  
132 =item * AnnoCPAN: Annotated CPAN documentation
133  
134 L<http://annocpan.org/dist/App-ProcTrends-Cron>
135  
136 =item * CPAN Ratings
137  
138 L<http://cpanratings.perl.org/d/App-ProcTrends-Cron>
139  
140 =item * Search CPAN
141  
142 L<http://search.cpan.org/dist/App-ProcTrends-Cron/>
143  
144 =back
145  
146  
147 =head1 ACKNOWLEDGEMENTS
148  
149  
150 =head1 LICENSE AND COPYRIGHT
151  
152 Copyright 2013 Satoshi Yagi.
153  
154 This program is free software; you can redistribute it and/or modify it
155 under the terms of either: the GNU General Public License as published
156 by the Free Software Foundation; or the Artistic License.
157  
158 See http://dev.perl.org/licenses/ for more information.
159  
160  
161 =cut
162  
163 1; # End of App::ProcTrends::Config
« blib/script/server.pl ↑ Summary