Skip to content

Commit

Permalink
update response time
Browse files Browse the repository at this point in the history
update response time
  • Loading branch information
Eduardo Mioto committed Oct 10, 2019
1 parent 9c8d4eb commit f66d771
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.mioto.cloud</groupId>
<groupId>br.com.mioto.cloud.m2csea</groupId>
<artifactId>architecture-probe</artifactId>
<version>1.0.0</version>

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/br/com/mioto/cloud/bo/impl/ResponseTimeBOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ public class ResponseTimeBOImpl implements ResponseTimeBO {
@Override
public List<ResponseTime> getAllResponseTimes() throws SQLException {

final List<ResponseTime> responseTimeList = ResponseTimeDAO.getResponseTime();
final List<ResponseTime> responseTimeList = ResponseTimeDAO.getAverageTime();

// final List<ResponseTime> meanTimeList = ResponseTimeDAO.getMeanTime();
//
// for (final ResponseTime responseTime : responseTimeList) {
//
// for (final ResponseTime responseTime2 : meanTimeList) {
// if(responseTime.getProject().equals(responseTime2.getProject())) {
// responseTime.setMean(responseTime2.getMean());
// }
// }
// }

Collections.sort(responseTimeList, Collections.reverseOrder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ResponseTimeController {
@Autowired
private ResponseTimeBO responseTimeBO;

@RequestMapping(value = "/microservices/responseTime/", method = RequestMethod.GET)
@RequestMapping(value = "/microservices/responseTime", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<List<ResponseTime>> getResponseTime() {
log.info("ResponseTimeController >> getResponseTime");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/br/com/mioto/cloud/dao/ResponseTimeDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@

public interface ResponseTimeDAO {

public List<ResponseTime> getResponseTime() throws SQLException;
public List<ResponseTime> getAverageTime() throws SQLException;

public List<ResponseTime> getMeanTime() throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class ResponseTimeDAOImpl extends BaseDAOImpl implements ResponseTimeDAO {

@Override
public List<ResponseTime> getResponseTime() throws SQLException {
public List<ResponseTime> getAverageTime() throws SQLException {
final Connection conn = getConnection();
final String query = "SELECT avg(response_time) as avg, microservice FROM response_time GROUP BY microservice";

Expand All @@ -35,4 +35,35 @@ public List<ResponseTime> getResponseTime() throws SQLException {
return list;
}

@Override
public List<ResponseTime> getMeanTime() throws SQLException {

final String query = "SET @rowindex := -1; " +
"SELECT " +
" AVG(g.response_time) as mean, g.microservice " +
"FROM " +
" (SELECT @rowindex:=@rowindex + 1 AS rowindex, " +
" response_time.response_time AS response_time " +
" FROM response_time " +
" ORDER BY response_time) AS g " +
"WHERE " +
"g.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2))";

final Connection conn = getConnection();

final java.sql.Statement stmt = conn.createStatement();
final ResultSet rs = stmt.executeQuery(query);

final List<ResponseTime> list = new ArrayList<ResponseTime>();
while (rs.next()) {
final ResponseTime responseTime = new ResponseTime();
responseTime.setAverage( rs.getDouble("mean"));
responseTime.setProject(rs.getString("microservice"));
list.add(responseTime);
}

conn.close();
return list;
}

}

0 comments on commit f66d771

Please sign in to comment.