This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2016 Fredrik Lundhag - f@mekk.com | |
# Simple script to get VPS bandwidth usage into collectd with the exec plugin. | |
# Should work for all VPS providers that uses SolusVM for VPS control panel. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. | |
# | |
# Collectd sends ENV variables, but here you have some defaults when running | |
# interactive. Just use this with the exec plugin and collectd will keep | |
# this script running. | |
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}" | |
INTERVAL="${COLLECTD_INTERVAL:-10}" | |
# API documentation here: | |
# https://documentation.solusvm.com/display/DOCS/Functions | |
SOLUS_KEY="<key from vps control panel>" | |
SOLUS_HASH="<md5hash from vps control panel>" | |
SOLUS_URL="https://<vps control panel host>[:port]/api/client/command.php" | |
while true; do | |
data=$(curl -s -L --data "key=$SOLUS_KEY&hash=$SOLUS_HASH&action=info&bw=true" $SOLUS_URL | grep -oP '(?<=bw>).*(?=</bw>)' ) | |
bw=(${data//,/ }) | |
echo "PUTVAL $HOSTNAME/vps/bytes-bandwidth_total interval=$INTERVAL N:${bw[0]}" | |
echo "PUTVAL $HOSTNAME/vps/bytes-bandwidth_used interval=$INTERVAL N:${bw[1]}" | |
echo "PUTVAL $HOSTNAME/vps/bytes-bandwidth_free interval=$INTERVAL N:${bw[2]}" | |
echo "PUTVAL $HOSTNAME/vps/percent-bandwidth_percentused interval=$INTERVAL N:${bw[3]}" | |
sleep "$INTERVAL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks! its works for me.