Hopefully the title isn’t too confusing. Here is my code
SELECT SRV_NAME, TOT_CPU, TOT_MEM, SNAP_DATE
FROM capacity2.SRV_CAPACITY_UNIX
WHERE TOT_CPU >= 90 OR TOT_MEM >= 90 AND SNAP_DATE BETWEEN to_date('14-jun-2012 00:00:00', 'dd-mon-yyyy hh24:mi:ss') AND to_date('14-jul-2012 00:00:00', 'dd-mon-yyyy hh24:mi:ss')
ORDER BY SRV_NAME desc, SNAP_DATE desc;
A sample of the data the code returns is as follows:
SNAP_DATE TOT_CPU TOT_MEM SRV_NAME
6/22/2012 0:00 99.98 70.86 server555
6/22/2012 0:05 99.98 70.9 server555
6/22/2012 0:10 99.98 70.93 server555
6/22/2012 0:15 99.98 71.06 server555
6/22/2012 0:20 99.98 70.87 server555
...
6/22/2012 23:35 99.97 71.12 server555
6/22/2012 23:40 99.99 71.12 server555
6/22/2012 23:45 99.97 71.12 server555
6/22/2012 23:50 99.98 71.12 server555
6/22/2012 23:55 99.98 71.12 server555
The objective:
Extract data for servers (the servers are within the capacity2.SRV_CAPACITY_UNIX database) that are 90% and above (in TOT_CPU and TOT_MEM) over a given duration (in this case a month/30 days). I need to graph this data and by default the data is recorded every 5 minutes so I’m left with 288 rows in one day over the span of approximately 30 days. This is approximately 8,600 rows that I am left with to plot on a graph which is obviously impractical.
Therefore what I need to do is to write a SQL query that will only extract the average TOT_CPU and TOT_MEM of each day so I will only be left with 30 rows of data I need to plot for 30 days (one row for each day).
This is my first time using Stack Overflow so I have attempted to be as clear as possible. If you need any information I will surely provide it.
Based on the
TO_DATEfunction, I’ll assume this is Oracle. Therefore, it should look somewhat like this:Please notice that this is broken down by server as well, you probably will plot one series per server.
Also notice that, if by any chance, there’s no logged data for a specific day, that day will not be present in the results and your plotting logic should deal with that.