8 months 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
8 months ago
okay hold on lemme look
8 months ago
it works fine for me
8 months ago

8 months ago
exact same query works for me
8 months 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 $$
8 months ago
i only queried for the CPU
8 months 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)
8 months ago
that's not a valid measurement type
8 months ago
BACKUPUSAGEGB
CPU_LIMIT
CPU_USAGE
CPUUSAGE2
DISKUSAGEGB
EPHEMERALDISKUSAGE_GB
MEASUREMENT_UNSPECIFIED
MEMORYLIMITGB
MEMORYUSAGEGB
NETWORKRXGB
NETWORKTXGB
UNRECOGNIZED
8 months ago
these are the valid measurement types
8 months ago
you can
8 months 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
8 months 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
8 months 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
8 months ago
happy to help
8 months ago
btw here's a super quick example of how you'd get the lastInvoiceId and or nextInvoiceCurrentTotal:
8 months 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
}
}
}
}8 months ago
not sure if you know but you can set usage limits in your usage tab
8 months 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?
8 months 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
8 months ago
in your usage tab:
8 months 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?
8 months 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
8 months 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)
Got it, it's clear to me now. Thank you my man <:1010:1173874936306221126>
8 months ago
im glad i could help
8 months ago
!s
Status changed to Solved dev • 8 months ago