Skip to content

Instantly share code, notes, and snippets.

@joltcan
Last active August 17, 2023 06:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joltcan/718653fe18cf431612895b7c5a86f74b to your computer and use it in GitHub Desktop.
Save joltcan/718653fe18cf431612895b7c5a86f74b to your computer and use it in GitHub Desktop.
#!/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
@directionsystems
Copy link

thanks! its works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment