├── LICENSE ├── README.md └── vzdump2influx.sh /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vzdump2influx 2 | ## Proxmox backup stats to InfluxDB ## 3 | 4 | Just a simple script to wtite some stats to InfluxDB about your backup. Based on vzdump hook method. 5 | 6 | Please don't hesitate, and contact me if you found a bug, or you have any idea for this script. 7 | 8 | ### Updates: ### 9 | 02/24/22: Tabnul's fixes (Thanks!) merged. Now it works with PVE 7.x, and requires InfluxDB 2.x (https://docs.influxdata.com/influxdb/v2.1/write-data/developer-tools/api/) 10 | 11 | 11/10/18: Quick fix for LXC transfer speeds 12 | 13 | ### Requirements: ### 14 | - Proxmox :) 15 | - curl 16 | 17 | ### Install: ### 18 | 1. On Proxmox host install curl. 19 | 20 | `sudo apt-get install curl` 21 | 22 | 2. Put the script somewhere. 23 | 24 | E.g. /usr/local/bin/vzdump2influx.sh 25 | 26 | Be sure your script is executable. (Check the permissions on file.) 27 | 28 | 3. Customize! 29 | 30 | Fill the neccessary datas in the script. 31 | - `` : username for DB 32 | - `` : password for DB 33 | - `` : protocol for communication with DB server. HTTP or HTTPS 34 | - `` : hostname or ip for your DB 35 | - `` : HTTP API port (default: 8086) 36 | - `` : name of your DB 37 | - `` : put your location here. I have multiple DCs, so I have different location for each. 38 | - `DEBUG` : true or false. If the value is true, the script copies all logs to /tmp/timestamp (and does not delete it) 39 | 40 | 4. Add the hook to the backup job. 41 | Edit the /etc/vzdump.conf file, and add this line: "script: /location/of/the/script.sh" 42 | 43 | 5. Done! 44 | 45 | Thats all. :) 46 | -------------------------------------------------------------------------------- /vzdump2influx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Just a simple script to wtite some stats to InfluxDB about your backup. Based on vzdump hook method. 3 | TOKEN= 4 | ORGANIZATION= 5 | LOCATIONCODE= 6 | PROTOCOL= #HTTP or HTTPS 7 | DBHOSTNAME= 8 | PORT= 9 | BUCKETNAME= 10 | DEBUG=false #Debug mode, copy all logs to /tmp/timestamp 11 | SPEED="" 12 | 13 | if [ "$1" == "backup-start" ]; then 14 | echo `date +%s` > /tmp/backup-info 15 | echo $HOSTNAME >> /tmp/backup-info 16 | fi 17 | 18 | if [ "$1" == "log-end" ]; then 19 | if [ "$DEBUG" = true ]; then 20 | cp ${LOGFILE} /tmp/`date +%s` 21 | fi 22 | if [ `cat ${LOGFILE} | grep ERROR | wc -l` -gt 0 ]; then 23 | DURATION=$((`date +%s`-`sed '1q;d' /tmp/backup-info`)) 24 | /usr/bin/curl --request POST "$PROTOCOL://$DBHOSTNAME:$PORT/api/v2/write?org=$ORGANIZATION&bucket=$BUCKETNAME&precision=ns" --data-binary "proxmox,host=$HOSTNAME,location=$LOCATIONCODE success=0,duration=$DURATION,speed=0,size=0" --header "Authorization: Token $TOKEN" --header "Content-Type: text/plain; charset=utf-8" --header "Accept: application/json" 25 | rm /tmp/backup-info 26 | else 27 | if [ -f "${TARGET}" ]; then 28 | SPEED=`cat ${LOGFILE} | grep -o -P "(?<=seconds \().*(?= MB\/s| MiB\/s)"` 29 | if [ -z $SPEED ]; then 30 | SPEED=`cat ${LOGFILE} | grep -o -P "(?<=.iB, ).*(?=.iB\/s)"` 31 | fi 32 | DURATION=$((`cat ${LOGFILE} |grep -o -P "(?<=\()[0-9][0-9]:[0-9][0-9]:[0-9][0-9](?=\))"|awk -F':' '{print($1*3600)+($2*60)+$3}'`)) 33 | /usr/bin/curl --request POST "$PROTOCOL://$DBHOSTNAME:$PORT/api/v2/write?org=$ORGANIZATION&bucket=$BUCKETNAME&precision=ns" --data-binary "proxmox,host=$HOSTNAME,location=$LOCATIONCODE success=1,duration=$DURATION,speed=$SPEED,size=`stat -c%s $TARGET`" --header "Authorization: Token $TOKEN" --header "Content-Type: text/plain; charset=utf-8" --header "Accept: application/json" 34 | else 35 | SPEEDR=$((`cat ${LOGFILE} |grep -o -P "(?<=\().*(?=....\/s\))"`)) 36 | SPEEDS=$((`cat ${LOGFILE} |grep -o -P "(?<=[0-9] ).(?=iB\/s\))"`)) 37 | case $SPEEDS in 38 | K) 39 | SPEED=`echo "$SPEEDR 1024" | awk '{printf "%f", $1 / $2}'` 40 | ;; 41 | M) 42 | SPEED=$SPEEDR 43 | ;; 44 | G) 45 | SPEED=`echo "$SPEEDR 1024" | awk '{printf "%f", $1 * $2}'` 46 | ;; 47 | esac 48 | DURATION=$((`cat ${LOGFILE} |grep -o -P "(?<=\()[0-9][0-9]:[0-9][0-9]:[0-9][0-9](?=\))"|awk -F':' '{print($1*3600)+($2*60)+$3}'`)) 49 | SIZER=$((`cat ${LOGFILE} |grep -o -P "(?<=transferred ).*(?= [K|M|G]iB in )"`)) 50 | SIZES=$((`cat ${LOGFILE} |grep -o -P "(?<=[0-9 ]).(?=iB in [0-9])"`)) 51 | case $SIZES in 52 | K) 53 | SIZE=`echo "$SIZER 1024" | awk '{printf "%f", $1 * $2}'` 54 | ;; 55 | M) 56 | SIZE=`echo "$SIZER 1024" | awk '{printf "%f", $1 * $2 * $2}'` 57 | ;; 58 | G) 59 | SIZE=`echo "$SIZER 1024" | awk '{printf "%f", $1 * $2 * $2 * $2}'` 60 | ;; 61 | esac 62 | /usr/bin/curl --request POST "$PROTOCOL://$DBHOSTNAME:$PORT/api/v2/write?org=$ORGANIZATION&bucket=$BUCKETNAME&precision=ns" --data-binary "proxmox,host=$HOSTNAME,location=$LOCATIONCODE success=1,duration=$DURATION,speed=$SPEED,size=$SIZE" --header "Authorization: Token $TOKEN" --header "Content-Type: text/plain; charset=utf-8" --header "Accept: application/json" 63 | fi 64 | fi 65 | fi 66 | --------------------------------------------------------------------------------