Friday, June 27, 2014

GSoC Week 06 - Mid-term Evaluations :)

The good news from GSoC office came today and it said i had passed the mid-term evaluation. :) Few more step to go now ...

This week at the start i had a mail discussion with pascal and we discussed on getting the first release for the System Monitoring module out by the 2nd week of July.

Then it was back to drawing the graph based on memory data. After struggling several times with NVD3 js i finally decided to look for alternatives as it was not easy for me to get the NVD3 based graph working. There were not enough examples, documents on getting this etc. When looking at other available options i found the Google Chart API [1] which was amazing and did my job !!

Google chart API has a rich documentation support and  a good API reference guide which helped me in creating a line chart by retrieving data from the metric value table and populate them as a graph. The syntax was easy to understand. So finally i was able to draw my first graph with real time memory data as shown in the image below. 

This is how the week went so far. Now i am going to work on furnishing the graphs and finalize the current implementation by next week so we can meet up the release deadline right at the time.

Sunday, June 22, 2014

GSoC Week 5 : Generated my first graph with Memory Usage

Since i have got lot of progress in listening to memory usage previous week this week my main target was getting started with NVD3 js and try to generate the graphs.

NVD3 js is a tool for build re-usable charts and chart components for using d3.js which is a JavaScript library for manipulating documents based on data using HTML, SVG and CSS. 

This is the first time i was working with NVD3 js and therefore it took me a few days to get it learnt and try out few basic examples. After that i started with creating the first graph in the module for the used memory data values. I first tried with using sample data and populating X and Y axises of the graph with reading and iterating  data using a json file where i stored {"timestamp": "memory value"} pairs. However it didn't work as each time i got D3.js error as it is not able to find my data.json file when called using,

d3.json('file path', callbacks); method.

Therefore to get the graph using i used some mock memory values inside my chart.jsp file and by populating those data i was able to draw the graph as below.




Therefore for the next week my biggest challenge is getting more used to NVD3 js API and to javascript and get this graph populated with real time memory data.

In addition since the coming week is the mid term evaluation, i worked on creating my project update presentation and added in the below locations.


[1] https://talk.openmrs.org/t/gsoc-2014-system-performance-and-utilization-module-midterm-presentation/313

[2] https://wiki.openmrs.org/display/projects/System+Performance+and+Utilization+Module

Saturday, June 14, 2014

GSoC Week 4: Extracting memory data values

In this week i started on reading memory values from the system and storing it in memory values table in System Performance and Utilization  module.

Querying the used memory for this is done using the Java Management beans where it expose both use memory and free memory values with MemoryMXBean. The following link is explaining about the structure of the beans API.

http://docs.oracle.com/javase/7/docs/api/java/lang/management/ManagementFactory.html

Once we read memory values from the beans, we store them in the metric_values table. This operation is called in each 10 seconds where it reads used memory value and them sleeps for 10 seconds.

After every one minute the used memory values which was recorded for the previous minute is taken and we get the average used memory value for that minute using these. Then there is another table named per_minute_value_table. The new average used memory value will be recorded in this table in every minute.

Below is the structure of the metric_value table of the new module and how the data entered there looks like for now.



The next step would be read these entries from DB and display them in graphs in the UI.

Saturday, June 7, 2014

GSOC Week 3 : Adding new tables for system indicators

In this week i worked on creating Hibernate mappings and adding the newly designed tables system_metric_types and system_metric_values into OpenMRS database. I first created HibernateDAO objects for MetricType object then called that in PerformanceMonitoringServiceImpl service to add/remove/modify MetricType values. 

However when i then added MetricType.hbm.xml file and name in config.xml it gave me this error.

org.hibernate.MappingException: Unknown entity: org.openmrs.module.systemmetrics.MetricType at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693) at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1485) 

 It seemed that hibernate didn't pick up my mapping file entry. With the help of my mentor i finally figured out a way to get rid of it as below. Instead of mapping, i used JPA annoatations. 

 First create MetricType object and annotate it with Table and column annotations as below. As we define table name, primary key, column names here there is no need to refer a .hbm.xml file Also the class needed to implement Serializable in order to define Id, which is primary key. 

  @Entity @Table(name = "systemmetrics_metric_type") 
public class MetricType implements Serializable { 

 @Id @Column(name = "metric_id") 
 private int metricId; 

 @Id @Column(name = "metric_name", length = 255) 
 private String metricName; 

 @Id @Column(name = "metric_type", length = 255) 
 private String metricType; 


 After that modify config.xml file to use annotated classes. You can comment out mapping-files entry there. 

 <!-- Maps hibernate file's, if present -->
    <!--<mappingFiles></mappingFiles>-->

 <!-- Packages that will be scanned for JPA annotations -->
<packagesWithMappedClasses>
        org.openmrs.module.systemmetrics
</packagesWithMappedClasses>


Then it is needed to change liquibase.xml file and add the changeset entry there with entries for each our tables as below. A list of supported elements and attributed as given in http://www.liquibase.org/manual/home#available_database_refactorings 

<changeSet id="system-metrics-1" author="milinda-ruk">
        <createTable tableName="systemmetrics_metric_type">
            <column name="metric_id" type="int" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="metric_name" type="varchar(255)">
                <constraints nullable="false"/>
            </column>
            <column name="metric_type" type="varchar(255)">
                <constraints nullable="false"/>
            </column>
        </createTable>
  </changeSet>

When the module is loaded the new table is created now and you can add data there using DAO objects. 

For the next week i hope to complete adding used memory data periodically into metric_value table and moving them into used_memory_minute table.