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.

Friday, May 30, 2014

GSoC Week 2: Designing database schema for store module data

In this week i had the weekly call with Pascal as usual. As discussed in that, i was mainly working on designing the database schemas for the new module data to be stored. As the first steps i have come up with the following schema for the new tables that will be used in storing system indicators as used memory, heap memory, free memory etc. Since it is bad practice to define a separate table to each indicator and as it is hard to scale that with time the following design is agreed. We first store metic_name with an id called  metric_id in seperate table for all metics. Then another table is used to store real data values against metirc name and id as below.

Metircs Types Table
[ metric_id, time_stamp, metric_value ]

Metic Values Table

[ metric_id, metric_name, metric_type ]

I am now going to follow this way and create the first set of tables and try to store memory data here.

In addition we discussed on handling historical data. As we can't store previous data forever since database is growing, we are going to have a periodical call to calculate the aggregate value of each metric and it will be moved to a seperate table.

I also sent a request to add my new module into OpenMRS reporsitory this week.


Friday, May 23, 2014

Beginning coding with GSoC - Adding a new module

This week started the coding for Google Summer of Code project. As the first task i started writing the new module structure using maven archetype document reference in [1]. Also i discussed with my mentors Pascal and Jan through mail about the first set of indicators to implement and how to do that. Since this is the first week i still didn't start coding for the indicators but focused on creating the now module and adding it to github. As agreed by three of us the new module will be named as openmrs-module-metrics. 

Below are few snapshots from the module home page. I will be adding this to github soon and will be starting the coding from next week as planned.


 [Module Link from OpenMRS Home]




                                                [Module Home Page]

[1] https://wiki.openmrs.org/display/docs/Creating+Your+First+Module

Sunday, May 18, 2014

Community Bonding Period of GSoC

During the community bonding period, i had two calls with my mentors Pascal and Jan. In first one we introduced ourselves and discussed about project requirements. As per my mentors guidance, i created a google doc where we will be discussing and adding project requirements and added it into OpenMRS wiki here.

GSoC Project Requirements:

https://wiki.openmrs.org/display/projects/System+Performance+and+Utilization+Module+Requirements

In the second week we identified few main indicators that needed to be searched and tried to implement as first phase and my mentor, pascal requested me to find out how that data can be captured and presented therefore i spent the week on them. Also learnt on how to write a new OpenMRS module as below since it will be my first task to get started with project.

How t write a new module:

https://wiki.openmrs.org/display/docs/Creating+Your+First+Module

Wednesday, May 7, 2014

Beginning GSoC 2014 with OpenMRS


It was a wonderful news that after months of hard work i have been selected to Google Summer of Code with OpenMRS. This is my first time in the GSoC. Here is a short description about my project as it will be a help for you to understand that how it works in OpenMRS.

My project is to develop a system performance and utilization module [1]. It's a new OpenMRS module which can supply information on system performance and utilization in order to monitor reliability and impact of the electronic medical record system installation.This module can be used to monitor OpenMRS and transfer specific system indications.

So far, I have already started creating mock GUI's and now I'm going to start the cording part from mid of this month.I have already fixed some bugs in the code earlier. Last week I addressed the GSoC 2014 developer forum to introduce myself to others.

In this week I started the project discussion with my primary mentor Pascal Brandt and backup mentor Jan Flower. We agreed to have this conversation on every week. I hope it will be a good help for make my way to success.
                                  
Finally i would like to make a note here that  I consider working with OpenMRS community is a big merit for me.