forked from gluster/gstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgstatus.py
executable file
·226 lines (162 loc) · 8.19 KB
/
gstatus.py
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
from optparse import OptionParser # command line option parsing
from datetime import datetime
import gstatus.gstatuscfg.config as cfg
from gstatus.libutils.utils import display_bytes, version_ok
from gstatus.libgluster.cluster import Cluster
def console_mode():
""" Produce the output to the users console - stdout """
if cluster.messages:
status_msg = "%s(%d)" % (cluster.status.upper(), len(cluster.messages))
else:
status_msg = cluster.status.upper()
# General Status Header
print (" Product: %s Capacity:%s(raw bricks)" % (cluster.product_shortname.ljust(17),
display_bytes(cluster.raw_capacity, display_units).rjust(11)))
print (" Status: %s %s(raw used)" % (status_msg.ljust(17),
display_bytes(cluster.used_capacity, display_units).rjust(11)))
print (" Glusterfs: %s%s%s(usable from volumes)" % (cluster.glfs_version.ljust(17),
" " * 11,
display_bytes(cluster.usable_capacity, display_units).rjust(
11)))
if cluster.snapshot_capable:
snap_msg = "Snapshots: %s" % (str(cluster.snapshot_count).rjust(3))
else:
snap_msg = ""
print (" OverCommit: %s%s%s" % (cluster.over_commit.ljust(3), " " * 15, snap_msg))
# Component Status
if state_request:
print ("\n Nodes :%3d/%3d\t\t Volumes: %2d Up"
% (cluster.nodes_active, cluster.node_count,
cluster.volume_summary['up']))
print (" Self Heal :%3d/%3d\t\t %2d Up(Degraded)"
% (cluster.sh_active, cluster.sh_enabled,
cluster.volume_summary['degraded']))
print (" Bricks :%3d/%3d\t\t %2d Up(Partial)"
% (cluster.bricks_active, cluster.brick_count,
cluster.volume_summary['partial']))
print (" Connections :%3d/%4d%s%2d Down" %
(cluster.num_clients,
cluster.num_connections,
" " * 20,
cluster.volume_summary['down']))
# Volume Breakdown
if volume_request:
print "\nVolume Information"
for vol_name in sorted(cluster.volume):
if len(volume_list) == 0 or vol_name in volume_list:
vol = cluster.volume[vol_name]
(up_bricks, all_bricks) = vol.brick_states()
task_list_str = ", ".join(vol.task_list) if vol.task_list else 'None'
print ("\t%s %s - %d/%d bricks up - %s"
% (vol_name.ljust(16, ' '),
vol.volume_state.upper(),
up_bricks, all_bricks,
vol.typeStr))
print ("\t" + " " * 17 +
"Capacity: (%d%% used) %s/%s (used/total)"
% (vol.pct_used,
display_bytes(vol.used_capacity, display_units),
display_bytes(vol.usable_capacity, display_units)))
if cluster.snapshot_capable:
print "\t" + " " * 17 + "Snapshots: %d" % vol.snapshot_count
print ("\t" + " " * 17 + "Self Heal: %s" % vol.self_heal_string)
print ("\t" + " " * 17 + "Tasks Active: %s" % task_list_str)
print ("\t" + " " * 17 + "Protocols: glusterfs:%s NFS:%s SMB:%s"
% (vol.protocol['NATIVE'],
vol.protocol['NFS'],
vol.protocol['SMB']))
print ("\t" + " " * 17 +
"Gluster Connectivty: %d hosts, %d tcp connections"
% (vol.num_clients,
vol.num_connections))
if volume_layout:
print
vol.print_layout()
print
if state_request:
print "\nStatus Messages"
if cluster.messages:
# Add the current cluster state as the first message to display
cluster.messages.insert(0, "Cluster is %s" % cluster.status.upper())
for info in cluster.messages:
print " - " + info
else:
print " - Cluster is HEALTHY, all_bricks checks successful"
print
def log_mode():
""" produce the output suitable for later processing by logstash,
or splunk et al """
now = datetime.now()
print "%s %s" % (now, str(cluster))
def main():
if cluster.output_mode == 'console':
# add some spacing to make the output stand out more
print " "
# setup up the cluster object structure
cluster.initialise()
# run additional commands to get current state
cluster.update_state(self_heal_backlog)
# use the bricks to determine overall cluster disk capacity
cluster.calc_capacity()
# perform checks on the clusters state
cluster.health_checks()
# Now with the object model complete, we can provide the info
# to the user
if cluster.output_mode == 'console':
console_mode()
elif cluster.output_mode in ['json', 'keyvalue']:
log_mode()
if __name__ == '__main__':
# initialise any global variables
cfg.init()
usageInfo = "usage: %prog [options]"
parser = OptionParser(usage=usageInfo, version="%prog 0.66")
parser.add_option("-s", "--state", dest="state", action="store_true", help="show highlevel health of the cluster")
parser.add_option("-v", "--volume", dest="volumes", action="store_true",
help="volume info (default is ALL, or supply a volume name)")
parser.add_option("-b", "--backlog", dest="selfheal", action="store_true", default=False,
help="Look deeper at self heal state (Use with -a)")
parser.add_option("-a", "--all", dest="everything", action="store_true", default=False,
help="show all cluster information (-s with -v)")
parser.add_option("-u", "--units", dest="units", choices=['bin', 'dec'],
help="display capacity units in DECimal or BINary format (GB vs GiB)")
parser.add_option("-l", "--layout", dest="layout", action="store_true", default=False,
help="show brick layout when used with -v, or -a")
parser.add_option("-o", "--output-mode", dest="output_mode", default='console',
choices=['console', 'json', 'keyvalue'],
help="produce output in different formats - json, keyvalue or console(default)")
parser.add_option("-D", "--debug", dest="debug_on", action="store_true", help="turn on debug mode")
parser.add_option("-w", "--without-progress", dest="progress", action="store_true", default=False,
help="turn off progress updates to user during data gathering")
parser.add_option("-t", "--timeout", dest="timeout", help="gluster command timeout value (secs)")
(options, args) = parser.parse_args()
if options.timeout:
cfg.CMD_TIMEOUT = int(options.timeout)
cfg.debug = True if options.debug_on else False
cfg.no_progress_msgs = options.progress
state_request = options.state
volume_request = options.volumes
volume_layout = options.layout
self_heal_backlog = options.selfheal
display_units = options.units if options.units else 'bin'
volume_list = [] # empty list of vols = show them all
# default behaviours
if volume_request and args:
volume_list = args
if state_request:
self_heal_backlog = False
if options.everything:
state_request = True
volume_request = True
if options.output_mode != 'console':
self_heal_backlog = False
# Create a cluster object. This simply creates the structure of
# the object and populates the glusterfs version
cluster = Cluster()
cluster.output_mode = options.output_mode
if version_ok(cluster.glfs_version, cfg.min_version):
main()
else:
print "gstatus is not compatible with this version of glusterfs %s" % cluster.glfs_version
exit(16)