-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelios_service_status
185 lines (133 loc) · 4.14 KB
/
helios_service_status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env perl
use 5.008;
use strict;
use warnings;
use Getopt::Long;
use Sys::Hostname ();
use Helios::Service;
our $VERSION = '2.82';
our $Service_Name = '';
our $Hostname = '';
our $Help_Mode = 0;
our $OPT_Epoch_Time = 0;
GetOptions(
"service=s" => \$Service_Name,
"H|hostname=s" => \$Hostname,
"epoch-time" => \$OPT_Epoch_Time,
"help" => \$Help_Mode,
);
# help mode
if ($Help_Mode) {
require Pod::Usage;
Pod::Usage::pod2usage(-verbose => 2, -exitstatus => 0);
}
# this is a little old school, but we'll
# instantiate the base Helios::Service to
# get a collective database connection
my $s = Helios::Service->new();
$s->prep();
my $dbh = $s->dbConnect();
my @placeholders;
my $sql = q{
SELECT
worker_class,
worker_version,
host,
process_id,
start_time,
register_time
FROM
helios_worker_registry_tb
WHERE
register_time > ?
};
push(@placeholders, time() - 300 );
if ($Service_Name) {
$sql .= ' AND worker_class = ? ';
push(@placeholders, $Service_Name);
}
if ($Hostname && $Hostname ne '*') {
$sql .= ' AND host = ? ';
push(@placeholders, $Hostname);
} elsif ($Hostname eq '*'){
# do nothing
} else {
# --hostname wasn't specified, default to the localhost
$sql .= ' AND host = ? ';
push(@placeholders, Sys::Hostname::hostname());
}
my $rs;
eval {
$rs = $dbh->selectall_arrayref($sql, undef, @placeholders);
1;
} or do {
my $E = $@;
warn "$0: ERROR: $E\n";
exit(1);
};
foreach (@$rs) {
print 'Service: ',$_->[0],"\n";
if (!defined($_->[1]) || $_->[1] eq '') {
print "Version: (none)\n";
} else {
print 'Version: ',$_->[1],"\n";
}
print 'Host: ',$_->[2],"\n";
print 'PID: ',$_->[3],"\n";
print "Online Since: ", $OPT_Epoch_Time ? $_->[4] : scalar localtime($_->[4]),"\n";
print 'Last Registered: ', $OPT_Epoch_Time ? $_->[5] : scalar localtime($_->[5]),"\n";
print "\n";
}
$dbh->disconnect();
exit(0);
=head1 NAME
helios_service_status - check the status of services running in a Helios collective
=head1 SYNOPSIS
helios_service_status [--service=<service name>] [--hostname=<hostname>] [--epoch-time]
# list status of all service instances running on current host
helios_service_status
# list status of all service instances running on host wrkhost1
helios_service_status --hostname=wrkhost1
# list status of all service instances running on all hosts in the collective
helios_service_status --hostname=*
# list status of all instances of MyService
# -H is shortcut for --hostname
helios_service_status --service=MyService -H=*
# list information on the MyService instance running on wrkhost1
# report the start and last check in times in epoch seconds
helios_service_status -s MyService -H wrkhost1 --epoch-time
=head1 DESCRIPTION
The helios_service_status command reports status information on services
running in a Helios collective. You can use this command for general
administration purposes or to build monitoring scripts for services.
The helios_service_status command currently reports 6 key pieces of
information:
=over 4
=item Service
name of the service.
=item Version
the version of the service, if one is set.
=item Host
the hostname of the host on which the service is running.
=item PID
The process id of the service daemon.
=item Online Since
the start time of the service daemon.
=item Last Registered
the last time the service daemon "checked in" to the collective. How often
this happens is controlled by the "registration_interval" configuration
parameter. The default is 60 sec, which should be fine for most purposes.
=back
This command basically reports the same type of information as the
Helios::Panoptes Collective Admin view, but having it available at the
command line adds convenience and enhances the Helios system's scriptability.
=head1 AUTHOR
Andrew Johnson, E<lt>lajandy at cpan dot orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013-4 by Logical Helion, LLC.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.0 or,
at your option, any later version of Perl 5 you may have available.
=head1 WARRANTY
This software comes with no warranty of any kind.
=cut