News for hackers. Stuff that matters.
Re:Fly.io: The reclaimer of Heroku's magic by TJSomething on Monday May 16, 2022 @02:04AM (#31394032)
Yup. Not too hard. This outputs the current bandwidth in gigabytes when you pass your app name.

  #!/usr/bin/env bash

  set -euo pipefail

  QUERY=$(cat <<EOF
  {
      "variables":{
          "app":"$1",
          "start":"$(date +%Y-%m)",
          "end":"$(date -d "$(date +%Y%m01) +1 month -1 day" +%Y-%m-%d)"
      },
      "query":"query (\$app: String!, \$start: ISO8601DateTime!, \$end: ISO8601DateTime!) { app(name: \$app) { organization { billables(startDate: \$start, endDate: \$end) { edges { node { app { id } category quantity } } } } } } "
  }
  EOF
  )

  curl https://api.fly.io/graphql \
      -H "Authorization: Bearer $(fly auth token)" \
      -H 'content-type: application/json' \
      --compressed \
      -X POST \
      --data-raw "$QUERY" \
      --silent |
      jq '[.data.app.organization.billables.edges[].node | select(.app.id == "'"$1"'" and .category == "data_out") | .quantity] | add'

There are no comments on this comment yet.