Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ReqColumns|hostid|name|Value
RAM10093Total Memory15.970000
RAM10093Total Memory [Free]12.420000
RAM10093Total Memory [used]3.550000
RAM10094Total Memory3.920000
RAM10094Total Memory [Free]1.970000
RAM10094Total Memory [used]1.950000




The above output I am getting by using this query...

SQL
SELECT ReqColumns,hostid,name , AVG(value_max) AS Value from
(
select sc.ReqColumns,
    i.name,
    TRUNCATE((tu.value_min)/(1024*1024*1024),2) AS value_min,
    TRUNCATE((tu.value_avg)/(1024*1024*1024),2) AS value_avg,
    TRUNCATE((tu.value_max)/(1024*1024*1024),2) AS value_max,
    i.hostid,
    ci.NewInterfaceName,
    lm.LocationName,
    bfm.BusinessFunctionCode,
    bm.BuildingCode,
    FROM_UNIXTIME(tu.clock,'%Y-%m-%d') Date from trends_uint tu

INNER JOIN items i ON i.itemid=tu.itemid
INNER JOIN graphs_items gi ON gi.itemid=i.itemid
  INNER JOIN graphs g ON g.graphid=gi.graphid
INNER JOIN hosts h ON h.hostid=i.hostid

  LEFT JOIN flip_linkutilisation.categorisedinterfaces ci on ci.graphid=g.graphid
  LEFT JOIN flip_linkutilisation.buildingmaster bm ON bm.BuildingID=ci.BuildingID
  LEFT JOIN flip_linkutilisation.businessfunctionmaster bfm ON bfm.BusinessFunctionID=bm.BusinessFunctionID
  LEFT JOIN flip_linkutilisation.locationmaster lm ON lm.LocationID=bm.LocationID
  LEFT JOIN flip_linkutilisation.servercolumns sc ON sc.ColumnDetails=g.name
where tu.itemid IN(SELECT itemid FROM items  WHERE  name in ('Total Memory','Total Memory [Free]', 'Total Memory [used]') )
) as x group by hostid,name





Here i need one row for one hostid and the value column calculation willl be the (Total Memory[used]/Total Memory)*100


That means my output should be like this




ReqColumns|hostid|name|Value-%
RAM10093Memory Details22.22
RAM10094Memory Details49.74



Please help me to solve this..

Thanks in advance
Posted
Updated 12-Nov-13 21:17pm
v3
Comments
Thava Rajan 13-Nov-13 2:35am    
what is the value % is it the total space user
kanamala subin 13-Nov-13 3:09am    
value % is the TotalMemory[used]/Total Memory*100

Actually this is a RAM inside a server...
Like that many servers are there..
So i want to make a report about RAM utilisation in Percentage

So we can tell in a particular hostid RAM is used this much..

1 solution

SELECT
	ReqColumns, hostid, name, (TotalUsed/TotalMemory)* 100 AS Value
FROM
	(
		SELECT
			sc.ReqColumns, i.hostid, i.name, 
			/*TRUNCATE((tu.value_min) / (1024 * 1024 * 1024), 2) AS value_min, 
			TRUNCATE((tu.value_avg) / (1024 * 1024 * 1024), 2) AS value_avg,
			TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) AS value_max,*/
			SUM(IF(i.name='Total Memory [used]',TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) ,0)) AS TotalUsed,
			SUM(IF(i.name='Total Memory',TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) ,0)) AS TotalMemory
			 
		FROM
			trends_uint tu
			INNER JOIN items i
				ON   i.itemid = tu.itemid
			INNER JOIN graphs_items gi
				ON   gi.itemid = i.itemid
			INNER JOIN graphs g
				ON   g.graphid = gi.graphid
			INNER JOIN HOSTS h
				ON   h.hostid = i.hostid
                        LEFT JOIN flip_linkutilisation.servercolumns sc 
                                ON   sc.ColumnDetails = g.name
		WHERE
			i.name IN ('Total Memory', 'Total Memory [Free]', 
			              	        'Total Memory [used]')
		GROUP BY sc.ReqColumns, i.hostid, i.name
	) AS x

well i think this will solve your problem?

watch out i remove the unnecessary joins and columns and reduce the number of reads
 
Share this answer
 
v4
Comments
kanamala subin 13-Nov-13 5:20am    
thank you for your reply..
But it s not working for me..
it gives the 0.00 value everywhere
Thava Rajan 13-Nov-13 9:27am    
what is the output of the inner query produce take a close look i miss the / 1024 section
try it with that also

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900