 In the previous three videos, we used Pixie to estimate the CPU, memory, and network cost of our Kubernetes services. In this video, we'll compute the amortized cost per request for each service. Okay, so what is Pixie? Pixie is an open-source observability tool for Kubernetes applications. Pixie uses EBPF to automatically collect a lot of data out of the box, such as infrastructure and network metrics, application profiles, and full-body requests. Pixie is a scriptable interface, so you can modify existing scripts or write custom scripts to do the analysis that you're interested in. In this video, we'll be writing a custom script to get visibility into the cost of our services. So here we have Pixie's live UI, and from this HTTP service map, you can see all the microservices that are talking to each other in my cluster. I'm going to open the scratchpad script. I have a custom script pasted into the editor, which calculates amortized costs per request per service. Let's run this script. This script outputs two tables. The first table shows the individual resource costs we calculated in the last three videos, specifically the CPU, memory, and network yearly costs, and then we've summed them over here in the total yearly cost column. The second table shows the cost broken down by service, along with two new columns. So here we have our yearly network cost, yearly memory cost, yearly CPU cost, and then total yearly cost. And then we have two new columns, the yearly number of requests per service, and the cost per million requests of that service. So we can sort this column and see which services are the most expensive. Let's take a closer look at the script. So at the top of the script, I've copied the code from our previous three videos, the functions for computing CPU, memory, and network usage. The yearly total cost per service function sums the total costs by joining the CPU, memory, and network cost tables by the service column. Next we calculate the number of HTTP requests per service using Pixi's HTTP events table. This table contains HTTP request response pair events. And basically all we're doing is grouping those requests by service and counting the number of requests. So now that we have the number of requests per service per hour, we can simply multiply that by the number of hours in a year in order to get the number of yearly requests. Finally, to get the cost per service, all we're going to do is join the yearly requests table with the cost table, and then we're going to divide the total yearly cost by the yearly number of requests in order to get the cost per request. Now these scripts are all public, so you can try them out by following the link in the video description below.