-
Notifications
You must be signed in to change notification settings - Fork 129
/
linux_odfs_API.sh
33 lines (28 loc) · 1.13 KB
/
linux_odfs_API.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
#!/bin/sh
# Make sure you replace the API key below with the one for your account
# NOTE: In CentOS and variants, the crontab path is /usr/bin:/bin and lsof is /usr/sbin/lsof
# So you will need to add this to the script, otherwise it will report 0:
#
# PATH=$PATH:/usr/sbin
USER="user_name_here"
process_name="process_name"
for pid in $(ps -fu ${USER} | grep "${process_name}" | grep -v "grep" | awk '{print $2}'); do
# echo "pid is ${pid}"
val=`lsof -p ${pid} | wc -l`
# echo "val is ${val}"
# If you want to include your hostname as a tag (in the form of host:xyz), then include it here
host_name="your_host_name"
if [ -n $pid ]; then
currenttime=$(date +%s)
curl -X POST -H "Content-type: application/json" \
-d "{ \"series\" :
[{\"metric\":\"linux.open_file_descriptors\",
\"points\":[[$currenttime, $val]],
\"type\":\"gauge\",
\"host\":\"$host_name\",
\"tags\":[\"process_name:$process_name\",\"pid:$pid\"]}
]
}" \
'https://app.datadoghq.com/api/v1/series?api_key=YOUR_API_KEY_HERE'
fi
done