Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notifications after db1000n output update (again) #6

Merged
merged 1 commit into from
Apr 24, 2022
Merged

Conversation

sadviq99
Copy link
Owner

@sadviq99 sadviq99 commented Apr 24, 2022

After the db1000n update, the output format has been changed again. It is still possible to get the "total" statistic as a JSON line, but that worked 1/3 times for me, so I gave up on that, we can't rely on that.

docker-programm-1  | {"level":"info","ts":1650813556.245873,"caller":"metrics/metrics.go:183","msg":"stats","target":"total","requests_attempted":13536,"requests_sent":1843,"responses_received":1843,"bytes_sent":314844}

An alternative solution was to show the stats for each target, I selected this way. To upgrade, do next:

  1. Login to the console
  2. Open /root/tg.sh file and some your TG token and chat id somewhere
  3. Return back to the console
  4. Copy and paste this content to the console, press Enter
    echo "
    #!/bin/bash
    set -x
    TG_TOKEN=\"YOUR TELEGRAM TOKEN\"
    TG_CHAT_ID=\"YOUR TELEGRAM CHAT ID\"
    TARGETS=\$(docker compose -f /root/db1000n/examples/docker/static-docker-compose.yml logs --tail=1000 | grep 'stats' | grep 'target.*://.*' | cut -d '|' -f 2 | jq -r '. | \"\(.target) \`(\(.requests_sent)/\(.responses_received), \(.bytes_sent/1000000)MB)\`\"' | sed 's/.*\/\///' | awk -F' ' '!_[\$1]++' | sed -E 's/([0-9]+\.[0-9]{1,2})[^ ]*MB/\1MB/g' | sort -n -r -k3)
    COUNTRY=\$(docker compose -f /root/db1000n/examples/docker/static-docker-compose.yml logs --no-log-prefix | grep 'country*' | tail -n 1 | jq -r '.country')
    message=\"*Host*: \\\`\$(hostname)\\\`\"
    message+=\"%0A\"
    message+=\"*VPN location*: \\\`\$COUNTRY\\\`\"
    message+=\"%0A\"
    message+=\"*Targets*:\"
    message+=\"%0A\"
    message+=\$TARGETS
    curl -s --data \"text=\${message}\" \
    --data \"chat_id=\$TG_CHAT_ID\" \
    --data \"parse_mode=markdown\" \
    \"https://api.telegram.org/bot\${TG_TOKEN}/sendMessage\"
    " > /root/tg.sh
  5. Open /root/tg.sh and return back you TG token and chat id values

The next notification will look like below:
img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant