-
Notifications
You must be signed in to change notification settings - Fork 14
/
temps-rrd-format.sh
executable file
·100 lines (81 loc) · 2.79 KB
/
temps-rrd-format.sh
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
#!/usr/bin/env bash
#####
# This script gathers and outputs the CPU and drive
# temperatures in a format rrdtool can consume.
#
# Author: Seren Thompson
# Date: 2017-09-19
# Website: https://github.com/seren/freenas-temperature-graphing
#####
# # display expanded values
# set -o xtrace
# quit on errors
set -o errexit
# error on unset variables
set -o nounset
# Helpful usage message
func_usage () {
echo ' This script gathers and outputs the CPU and drive
temperatures in a format rrdtool can consume.
Usage $0 [-v] [-d] [-h]
-v | --verbose Enables verbose output
-d | --debug Outputs each line of the script as it executes (turns on xtrace)
-h | --help Displays this message
-o | --output <file> Output rrd data to the named file
Options for ESXi:
--platform "esxi" Indicates that we will use ESXi tools to retrieve CPU temps
--ipmitool_username <USERNAME> Required: Username to use when connecting to BMC
--ipmitool_address <BMC_ADDRESS> Required: BMC ip address to connect to
'
}
# Process command line args
help=
verbose=
debug=
USERNAME=
BMC_ADDRESS=
PLATFORM=
output=/dev/stdout
while [ $# -gt 0 ]; do
case $1 in
-h|--help) help=1; shift 1 ;;
-v|--verbose) verbose=1; shift 1 ;;
-d|--debug) debug=1; shift 1 ;;
-o|--output) output=$2; shift 2 ;;
--platform) PLATFORM=$2; shift 2 ;;
--ipmitool_username) USERNAME=$2; shift 2 ;;
--ipmitool_address) BMC_ADDRESS=$2; shift 2 ;;
-*) echo "$0: Unrecognized option: $1 (try --help)" >&2; exit 1 ;;
*) shift 1; break ;;
esac
done
if [ -n "$debug" ]; then
set -o xtrace
verbose=1
fi
# [ -n "$verbose" ] && set -o xtrace
[ -n "$help" ] && func_usage && exit 0
case "${PLATFORM}" in
esxi)
[ -n "$verbose" ] && echo "Platform is set to '${PLATFORM}'. Username is '${USERNAME} and ip is '${BMC_ADDRESS}'"
[ -z "$USERNAME" ] && echo "You need to to provide --ipmitool_username with an argument" && exit 1
[ -z "$BMC_ADDRESS" ] && echo "You need to to provide --ipmitool_address with an argument" && exit 1
;;
esac
# Check we're root
if [ "$(id -u)" != "0" ]; then
echo "Error: this script needs to be run as root (for smartctl). Try 'sudo $0 $1'"
exit 1
fi
# Get current working directory
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[ -n "$verbose" ] && echo "Current working directory is: ${CWD}"
# Load common functions (temperature retrieval, device enumeration, etc)
# shellcheck source=./rrd-lib.sh
. "${CWD}/rrd-lib.sh"
get_devices
get_temperatures
# Strip any leading, trailing, or duplicate colons
[ -n "$verbose" ] && echo "Cleaned up data:"
echo "${data}" | sed 's/:::*/:/;s/^://;s/:$//' > $output
[ -n "$verbose" ] && echo "Done gathering temp data returning"