Skip to content

Commit f539d41

Browse files
committed
Adds multipathd_metrics.sh
1 parent b36a2ea commit f539d41

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

multipathd_metrics.sh

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/bin/bash
2+
3+
# Author: Nick Galtry
4+
# Usage: Script that jq queries against JSON output of multipathd show multipaths command, formats results for Promtheus textfile collector
5+
# Requires: jq
6+
7+
set -e
8+
9+
# Function for handling errors, "scrubs the multipathd.prom file"
10+
error_trap() {
11+
local error_msg="$1"
12+
echo "$error_msg"
13+
exit 1
14+
}
15+
16+
if ! command -v jq &> /dev/null; then
17+
error_trap "Error: jq is not installed."
18+
fi
19+
20+
# Variable set for command to run with jq
21+
if ! command_output=$(multipathd show multipaths json)
22+
then
23+
error_trap "Error: Failed to run multipathd show multipaths"
24+
fi
25+
26+
if echo "$command_output" | jq -e '.maps | length == 0' >/dev/null 2>/dev/null; then
27+
exit 0
28+
fi
29+
30+
node_multipath_paths_dm_st=$(echo "$command_output" |
31+
jq -c -r '.maps[] |
32+
{
33+
name: .name,
34+
uuid: .uuid,
35+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
36+
prod: .prod,
37+
count: [.path_groups[].paths[] | select(.dm_st == "active")] | length
38+
}' |
39+
sed -E 's/^/node_multipath_paths_dm_st/;
40+
s/"name"/name/;
41+
s/"uuid"/uuid/;
42+
s/"vend"/vend/;
43+
s/"prod":"([^"]*)"/prod:"\1",state="active"/;
44+
s/,"count":([0-9]+)}/\}\1/g;
45+
s/:/=/g'
46+
)
47+
48+
if [ -z "$node_multipath_paths_dm_st" ]; then
49+
error_trap "Error processing node_multipath_paths_dm_st metric"
50+
else
51+
echo "# HELP node_multipath_paths_dm_st A count of paths with active state in path_groups"
52+
echo "# TYPE node_multipath_paths_dm_st gauge"
53+
echo "${node_multipath_paths_dm_st}"
54+
fi
55+
56+
node_multipath_paths_chk_st=$(echo "$command_output" |
57+
jq -c -r '.maps[] |
58+
{
59+
name: .name,
60+
uuid: .uuid,
61+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
62+
prod: .prod,
63+
count: [.path_groups[].paths[] | select(.chk_st == "ready")] | length
64+
}' |
65+
sed -E 's/^/node_multipath_paths_chk_st/;
66+
s/"name"/name/;
67+
s/"uuid"/uuid/;
68+
s/"vend"/vend/;
69+
s/"prod":"([^"]*)"/prod:"\1",state="ready"/;
70+
s/,"count":([0-9]+)}/\}\1/g;
71+
s/:/=/g'
72+
)
73+
74+
if [ -z "$node_multipath_paths_chk_st" ]; then
75+
error_trap "Error processing node_multipath_paths_chk_st metric"
76+
else
77+
echo "# HELP node_multipath_paths_chk_st A count of paths with chk_st ready in path_groups"
78+
echo "# TYPE node_multipath_paths_chk_st gauge"
79+
echo "${node_multipath_paths_chk_st}"
80+
fi
81+
82+
node_multipath_paths_dev_st=$(echo "$command_output" |
83+
jq -c -r '.maps[] |
84+
{
85+
name: .name,
86+
uuid: .uuid,
87+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
88+
prod: .prod,
89+
count: [.path_groups[].paths[] | select(.dev_st == "running")] | length
90+
}' |
91+
sed -E 's/^/node_multipath_paths_dev_st/;
92+
s/"name"/name/;
93+
s/"uuid"/uuid/;
94+
s/"vend"/vend/;
95+
s/"prod":"([^"]*)"/prod:"\1",state="running"/;
96+
s/,"count":([0-9]+)}/\}\1/g;
97+
s/:/=/g'
98+
)
99+
if [ -z "$node_multipath_paths_dev_st" ]; then
100+
error_trap "Error processing node_multipath_paths_dev_st metric"
101+
else
102+
echo "# HELP node_multipath_paths_dev_st A count of paths with dev_st running in path_groups"
103+
echo "# TYPE node_multipath_paths_dev_st gauge"
104+
echo "${node_multipath_paths_dev_st}"
105+
fi
106+
107+
node_multipath_dm_st=$(echo "$command_output" |
108+
jq -c -r '.maps[] |
109+
{
110+
name: .name,
111+
uuid: .uuid,
112+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
113+
prod: .prod,
114+
count: [select(.dm_st == "active")] | length
115+
}' |
116+
sed -E 's/^/node_multipath_dm_st/;
117+
s/"name"/name/;
118+
s/"uuid"/uuid/;
119+
s/"vend"/vend/;
120+
s/"prod":"([^"]*)"/prod:"\1",state="active"/;
121+
s/,"count":([0-9]+)}/\}\1/g;
122+
s/:/=/g'
123+
)
124+
if [ -z "$node_multipath_dm_st" ]; then
125+
error_trap "Error processing node_multipath_dm_st metric"
126+
else
127+
echo "# HELP node_multipath_dm_st A count of active dm_st per multipath device"
128+
echo "# TYPE node_multipath_dm_st gauge"
129+
echo "${node_multipath_dm_st}"
130+
fi
131+
132+
node_multipath_path_nr=$(echo "$command_output" |
133+
jq -c -r '.maps[] |
134+
{
135+
name: .name,
136+
uuid: .uuid,
137+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
138+
prod: .prod,
139+
count: .paths
140+
}' |
141+
sed -E 's/^/node_multipath_path_nr/;
142+
s/"name"/name/;
143+
s/"uuid"/uuid/;
144+
s/"vend"/vend/;
145+
s/"prod"/prod/;
146+
s/,"count":([0-9]+)}/\}\1/g;
147+
s/:/=/g' |
148+
sed 's/ "count"://'
149+
)
150+
if [ -z "$node_multipath_path_nr" ]; then
151+
error_trap "Error processing node_multipath_path_nr metric"
152+
else
153+
echo "# HELP node_multipath_path_nr A count of paths per multipath device"
154+
echo "# TYPE node_multipath_path_nr gauge"
155+
echo "${node_multipath_path_nr}"
156+
fi
157+
158+
node_multipath_path_faults=$(echo "$command_output" |
159+
jq -c -r '.maps[] |
160+
{
161+
name: .name,
162+
uuid: .uuid,
163+
vend: (.vend | sub("^[[:space:]]+"; "") | sub("[[:space:]]+$"; "")),
164+
prod: .prod,
165+
count: .path_faults
166+
}' |
167+
sed -E 's/^/node_multipath_path_faults/;
168+
s/"name"/name/;
169+
s/"uuid"/uuid/;
170+
s/"vend"/vend/;
171+
s/"prod"/prod/;
172+
s/,"count":([0-9]+)}/\}\1/g;
173+
s/:/=/g' |
174+
sed 's/ "count"://'
175+
)
176+
if [ -z "$node_multipath_path_faults" ]; then
177+
error_trap "Error processing node_multipath_path_faults metric"
178+
else
179+
echo "# HELP node_multipath_path_faults A count of faults reported per multipath device"
180+
echo "# TYPE node_multipath_path_faults gauge"
181+
echo "${node_multipath_path_faults}"
182+
fi

0 commit comments

Comments
 (0)