Skip to content

Instantly share code, notes, and snippets.

@liushuainudt
Last active April 3, 2023 14:59
Show Gist options
  • Select an option

  • Save liushuainudt/1024b06958db3474cb7e78f37a4a15f3 to your computer and use it in GitHub Desktop.

Select an option

Save liushuainudt/1024b06958db3474cb7e78f37a4a15f3 to your computer and use it in GitHub Desktop.
Designed to monitor and report the temperature values of a SAS controller (SAS2308) and a 10GB network interface card (NIC) in a remote system. The script is intended to be used as a custom plugin for the Netdata monitoring system.-helped by Chatgpt
#!/bin/sh
# Define the name of the chart and its type
temperature_chart="Devices.temperature"
chart_type="line"
# Define the SSH connection details
ssh_user="root"
ssh_host="192.168.0.108"
ssh_key="/var/log/netdata/.ssh/id_rsa"
# Define the command to get the NIC temperature
get_sas_temp_cmd="(mpsutil show all | awk -F ': ' '/Temp/ {gsub(/ C/, \"\", \$2); print \$2}')"
get_inc_temp_cmd="mget_temp -d pci0:4:0:0"
# Define priority and update interval
temperature_priority=60000
temperature_update_every=5
# Global variable to store temperature value
temperature_nic_value=
temperature_sas_value=
# Check function to ensure the script can run
temperature_check() {
# Test the SSH connection
ssh -i "$ssh_key" "$ssh_user@$ssh_host" "ls -l" >/dev/null 2>&1
return $?
}
# Create function to define the chart
temperature_create() {
# Define the chart and dimension
# CHART type.id name title units [family [context [charttype [priority [update_every [options [plugin [module]]]]]]]]
echo "CHART ${temperature_chart} '' 'Temperature' 'Temperature (°C)' 'Temperature' temperature ${chart_type} ${temperature_priority} ${temperature_update_every} ''"
# DIMENSION id [name [algorithm [multiplier [divisor [options]]]]]
echo "DIMENSION temp1 'SAS2308 Temperature' absolute 1 1"
echo "DIMENSION temp2 '10GB NIC Temperature' absolute 1 1"
return 0
}
# Update function to collect and send data to Netdata
temperature_update() {
# Get the temperature value
temp1_output=$(ssh -i "$ssh_key" "$ssh_user@$ssh_host" "$get_sas_temp_cmd")
temp2_output=$(ssh -i "$ssh_key" "$ssh_user@$ssh_host" "$get_inc_temp_cmd")
temperature_sas_value=$(echo "$temp1_output")
temperature_inc_value=$(echo "$temp2_output")
# Check if the temperature is within the range (0, 100)
if [[ $temperature_inc_value -ge 0 && $temperature_inc_value -le 100 ]]; then
# Temperature is within the range, no action needed
:
else
# Temperature is outside the range, set temp_value to null
temperature_inc_value=0
fi
# Send the data to Netdata
echo "BEGIN ${temperature_chart}"
echo "SET temp1 = ${temperature_sas_value}"
echo "SET temp2 = ${temperature_inc_value}"
echo "END"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment