This repository has been archived on 2023-09-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
awesome-scripts/node_exporter/active-sessions.sh

11 lines
427 B
Bash

#!/bin/bash
ALL_SESSIONS=$(netstat -tnp | grep sshd -c)
SU_SESSIONS=$(ps aux | grep ' [s][u] ' -c)
ROOT_SESSIONS=$(netstat -tnp | grep sshd | grep root -c)
echo "# HELP node_active_sessions active sessions by type."
echo "# TYPE node_active_sessions gauge"
echo "node_active_sessions{type=\"all\"} $ALL_SESSIONS"
echo "node_active_sessions{type=\"su\"} $SU_SESSIONS"
echo "node_active_sessions{type=\"root\"} $ROOT_SESSIONS"