File tree 1 file changed +14
-14
lines changed
1 file changed +14
-14
lines changed Original file line number Diff line number Diff line change 150
150
"prometheus_scripts/logged_in_users_exporter.sh" = {
151
151
mode = "0555" ;
152
152
text = ''
153
- #!/bin/bash
154
- OUTPUT_FILE="/var/lib/node_exporter/textfile_collector/logged_in_users.prom"
155
- > "$OUTPUT_FILE"
156
- loginctl list-sessions --no-legend | while read -r session_id uid user seat leader class tty idle since; do
157
- if [[ $class == "user " ]]; then
158
- state=$(loginctl show-session "$session_id" -p State --value)
159
- if [[ $state == "active" ]]; then
160
- locked_status="unlocked"
161
- else
162
- locked_status="locked"
163
- fi
164
- echo "node_logged_in_user{name=\"$user\", state=\"$locked_status\"} 1" > $OUTPUT_FILE
165
- fi
166
- done
153
+ #!/bin/bash
154
+ OUTPUT_FILE="/var/lib/node_exporter/textfile_collector/logged_in_users.prom"
155
+ > "$OUTPUT_FILE"
156
+ loginctl list-sessions --no-legend | while read -r session_id uid user seat leader class tty idle since; do
157
+ if [[ $class == "user" ]] && [[ $seat == "seat0" ]] && [[ $idle == "no " ]]; then
158
+ state=$(loginctl show-session "$session_id" -p State --value)
159
+ if [[ $state == "active" ]]; then
160
+ locked_status="unlocked"
161
+ else
162
+ locked_status="locked"
163
+ fi
164
+ echo "node_logged_in_user{name=\"$user\", state=\"$locked_status\"} 1" > $OUTPUT_FILE
165
+ fi
166
+ done
167
167
'' ;
168
168
} ;
169
169
} ;
You can’t perform that action at this time.
0 commit comments