graphiql project usage
tacg78952
PROOP

a year ago

Good morning everyone, I need to retrieve the project usage spends of my railway enviroment but I can't figure out how to do it using the grafiql. Anyone already done that and have the query to it?

Regards

Solved$10 Bounty

41 Replies

tacg78952
PROOP

a year ago

51e89ca6-b73e-4527-8faf-ace855422563


a year ago

okay hold on lemme look


a year ago

it works fine for me


a year ago

1396825015617589410


a year ago

exact same query works for me


a year ago

you might not be authorised, or might not be providing the variables correctly


tacg78952
PROOP

a year ago

This returned only CPU usage or all the usage? I need the cost one, the real $$


tacg78952
PROOP

a year ago

Let me check


a year ago

i only queried for the CPU


a year ago

you can calculate the cost by just mapping the cost next to each measurement using the data from railway.com/pricing (meaning you multiply CPU metrics by 20 for example)


tacg78952
PROOP

a year ago

Yes cpu usage works


tacg78952
PROOP

a year ago

"usageMeasurements": ["ESTIMATED_USAGE"],


tacg78952
PROOP

a year ago

This do not work


a year ago

that's not a valid measurement type


a year ago

  • BACKUP_USAGE_GB
  • CPU_LIMIT
  • CPU_USAGE
  • CPU_USAGE_2
  • DISK_USAGE_GB
  • EPHEMERAL_DISK_USAGE_GB
  • MEASUREMENT_UNSPECIFIED
  • MEMORY_LIMIT_GB
  • MEMORY_USAGE_GB
  • NETWORK_RX_GB
  • NETWORK_TX_GB
  • UNRECOGNIZED

a year ago

these are the valid measurement types


tacg78952
PROOP

a year ago

I can not retrieve Current Usage from anywhere? Dashboards maybe?


a year ago

you can


a year ago

query {
  usage(measurements: MEMORY_USAGE_GB) {
    measurement
    value
  }
}

tacg78952
PROOP

a year ago

This works fine to the hardware usage, but what works to me is the prices. I could do what you told me but any variation at the railway prices would screw up the calculation


a year ago

that's true but railway doesnt change their prices often, ive been using railway for over 3 years and theyve only changed their prices once but its cause they migrated to their own datacenters so I'm doubtful it'll change again any time soon

if your ultimate goal is just to export your costs then you could also just use Customer.invoices to fetch your total spendatures over past invoices


a year ago

or if your goal is to get the current cost of your current billing period then Customer.subscriptions has a nextInvoiceCurrentTotal field as well


tacg78952
PROOP

a year ago

Ok Fragly, I'll go in this direction, thank you for the help


a year ago

happy to help


a year ago

btw here's a super quick example of how you'd get the lastInvoiceId and or nextInvoiceCurrentTotal:


a year ago

query GetSubscriptions($teamId: String!) {
  workspace(workspaceId: $teamId) {
    customer {
      subscriptions {
        latestInvoiceId
        nextInvoiceCurrentTotal
      }
    }
  }
}

and here's how you'd get past invoice totals

query GetPastInvoiceTotal($teamId: String!) {
  workspace(workspaceId: $teamId) {
    customer { 
      invoices {
        total
      } 
    }
  }
}

tacg78952
PROOP

a year ago

I think this will work, the goal is only to have the spend control


tacg78952
PROOP

a year ago

Thanks a lot


a year ago

not sure if you know but you can set usage limits in your usage tab


a year ago

no problem at all


tacg78952
PROOP

a year ago

Yes, I'm aware, I just don't know how it works to be honest. If I set a usage limit when it reach the limit what happens? Stop the service?


a year ago

yea, so there's two types of usage limits:

  • a soft limit
  • and a hard limit

a hard limit will stop your services immediately once reached, you'd want to avoid this which is why the soft limit is useful. a soft limit will only send you an email warning you that you passed the soft limit threshold, this should give you time to mitigate whatever's costing you a lot of money before you reach your hard limit


tacg78952
PROOP

a year ago

Got it, that's really helpfull. Where can I set it?


a year ago

in your usage tab:


a year ago

you'll see an option to set a limit under your current usage


tacg78952
PROOP

a year ago

So I only can set to the entire workspace? There's no option to set by container?


a year ago

no unfortunately not, instead you can individually set a resource limit on each service which will effectively behave the same way just with usage instead of cost


a year ago

(i dont think it shuts the deployment down but the deployment may crash anyway if it expects more memory than provided but this isnt necasserily true for all apps)


tacg78952
PROOP

a year ago

Got it, it's clear to me now. Thank you my man <:1010:1173874936306221126>


a year ago

im glad i could help


a year ago

!s


Status changed to Solved dev 12 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...