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
41 Replies
a year ago
okay hold on lemme look
a year ago
it works fine for me
a year ago

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
This returned only CPU usage or all the usage? I need the cost one, the real $$
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)
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
a year ago
you can
a year ago
query {
usage(measurements: MEMORY_USAGE_GB) {
measurement
value
}
}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
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
}
}
}
}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
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
a year ago
in your usage tab:
a year ago
you'll see an option to set a limit under your current usage
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)
a year ago
im glad i could help
a year ago
!s
Status changed to Solved dev • 12 months ago