Display Only Skewed Sessions

Extensibility
Extensibility covers the mechanisms by which you, as the user or developer, can extend the functionality of the Teradata Database, for example with the use of User Defined Functions, or UDFs.
Teradata Employee

Display Only Skewed Sessions

At this point, we have a working portlet that displays all non-idle sessions. We now want to modify it so that it only displays skewed sessions and it only displays those sessions if the entire system is skewed.

To accomplish this task, we need to enable the user to specify thresholds for the system skew level and the session skew level. The system skew threshold will determine the amount of system skew that will trigger the display of skewed sessions. The session skew threshold will determine which active sessions will be displayed in the portlet. We need to add these two thresholds to our preferences model:

SkewedSessions\src\java\com\teradata\portlets\skewedsessions\model\SkewedSessionsPreferences.java


    /**
* The system Skew threshold at which we begin showing skewed sessions
*/
@Preference private Double ampCpuSkewThreshold;

/**
* The session Skew threshold at which we begin showing skewed sessions
*/
@Preference private Double sessionCpuSkewThreshold;

public SkewedSessionsPreferences()
{
// set default values
ampCpuSkewThreshold = 70.0;
sessionCpuSkewThreshold = 70.0;
}

/**
* Gets the system AMP CPU skew threshold.
*
* @return the system AMP CPU skew threshold
*/
public Double getAmpCpuSkewThreshold()
{
return ampCpuSkewThreshold;
}

/**
* Sets the system AMP CPU skew threshold.
*
* @param ampCpuSkewThreshold The system AMP CPU skew threshold.
*/
public void setAmpCpuSkewThreshold(Double ampCpuSkewThreshold)
{
this.ampCpuSkewThreshold = ampCpuSkewThreshold;
}

/**
* Gets the session CPU skew threshold.
*
* @return the session CPU skew threshold
*/
public Double getSessionCpuSkewThreshold()
{
return sessionCpuSkewThreshold;
}

/**
* Sets the session CPU skew threshold.
*
* @param sessionCpuSkewThreshold The session CPU skew threshold.
*/
public void setSessionCpuSkewThreshold(Double sessionCpuSkewThreshold)
{
this.sessionCpuSkewThreshold = sessionCpuSkewThreshold;
}
 


We now need to update the preferences view to allow the user to enter this data.

SkewedSessions\web\WEB-INF\portlet-jsp\preferences.jsp

    <!-- form content goes here -->
<br/>
Please choose a system to monitor.
<br/>
<br/>
System:
<form:select path="system" size="1">
<c:forEach items="${systemNames}" var="system">
<form:option label="${system}" value="${system}"/>
</c:forEach>
</form:select>
<br/>

<!-- Add the following section below -->
<br/>
<br/>
Please enter system and session thresholds.
<br/>
<br/>
System AMP CPU Skew: <form:input path="ampCpuSkewThreshold"/> (0-100 percent)
<br/>
<br/>
Session CPU Skew: <form:input path="sessionCpuSkewThreshold"/> (0-100 percent)
<br/>
<br/>
<!-- End add section -->

<form:errors path="*" cssStyle="color:red"/>

This completes the preferences changes.

To determine if the entire system is skewed we need another source of information. Viewpoint provides a system statistics table that will meet this need. We access the system statistics table using the SystemStatisticsDAO. So our first step is to use spring to inject a reference to this DAO into our service.

First we add the DAO to our dataSourceIBatis.xml configuration file:

SkewedSessions\web\WEB-INF\dataSourceiBatis.xml


    <bean id="statisticsDAO"
class="com.teradata.dcs.data.dao.ibatis.SystemStatisticsDAOiBatis">
<description>DAO for accessing System Statistics table</description>
<property name="sqlMapClient" ref="dcsSqlMapClient" />
</bean>


Then we can inject the DAO into the service in the applicationContext.xml configuration file:

SkewedSessions\web\WEB-INF\applicationContext.xml

    <bean id="skewedSessionsManager" 
class="com.teradata.portlets.skewedsessions.service.impl.SkewedSessionsManagerImpl">
<description>The business delegate for this application</description>
<property name="preferencesDAO" ref="preferencesDAO"/>
<property name="sessionDAO" ref="sessionDAO"/>
<!-- Add the following property below -->

<property name="statisticsDAO" ref="statisticsDAO"/>

<!-- End add property -->

</bean>

In our SkewedSessionManagerImpl class, we need to add a statisticsDAO field and a setter.

SkewedSessions\src\java\com\teradata\portlets\skewedsessions\service\impl\SkewedSessionsManagerImpl.java


import com.teradata.dcs.data.model.SystemStatistics;
import com.teradata.dcs.data.dao.SystemStatisticsDAO;

private SystemStatisticsDAO statisticsDAO;

/**
* Set the statistics DAO.
*
* @param value The Statistics DAO.
*/
public void setStatisticsDAO(SystemStatisticsDAO value)
{
statisticsDAO = value;
}


Now, we can add code to our getCurrentSkewedSessions method to get the current system skew and use it as a part of our filter. We're also going to use the thresholds that we set in our preferences as the filter criteria.

SkewedSession\src\java\com\teradata\portlets\skewedsessions\service\impl\SkewedSessionsManagerImpl.java

    /**
* Gets a list of active skewed sessions running on the specified system. Each list
* item is a session model.
*
* @param system The name of a system to monitor.
* @param preferences The user's portlet preferences for this portlet instance.
*/
public List<Session> getCurrentSkewedSessions(SkewedSessionsPreferences preferences)
{
List<Session> result = new ArrayList<Session>();
Integer id = getSystemId(preferences.getSystem());
if (id != null)
{
//** Add the following section below **/

SystemStatistics statistics = statisticsDAO.getCurrentSystemStatistics(id);
// save the system skew value
if (statistics != null && statistics.getAmpCpuSkew() > preferences.getAmpCpuSkewThreshold())
{
List<Integer> systemIds = new ArrayList<Integer>();
systemIds.add(id);

// fetch the data
List<Session> sessions = sessionDAO.getCurrentActiveSessions(systemIds);

for (Session session : sessions)
{
if ((session.getComputedState().equals("ACTIVE"))
&& (session.getCpuSkew() > preferences.getSessionCpuSkewThreshold()))
{
result.add(session);
}
}
}
//** End add section **/
}
return result;
}

This complete the changes needed to display skewed sessions. Go ahead and deploy your portlet and try it out. If no data is displayed, you may need to lower the thresholds we've just added in the preferences.

Tags (2)