Skip to content

Commit

Permalink
add producers
Browse files Browse the repository at this point in the history
  • Loading branch information
smartloli committed May 13, 2020
1 parent 2ee5e06 commit 35971be
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ public static String getCustomLastDay(String formatter, int day) {
return df.format(calendar.getTime());
}

/** Get custom hour. */
public static long getCustomLastHourUnix(int hour) {
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + hour);
return calendar.getTime().getTime();
}

/** Convert date to date. */
public static String convertDate2Date(String date) throws ParseException {
SimpleDateFormat newly = new SimpleDateFormat(DATA_FORMAT_SPLIT_YEAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ public void topicMsgByJmxAjax(@PathVariable("tname") String tname, HttpServletRe
}
}

/** Get cluster producer and total capacity by ajax. */
@RequestMapping(value = "/topic/list/total/jmx/ajax", method = RequestMethod.GET)
public void producersCapacityByJmxAjax(HttpServletResponse response, HttpServletRequest request, HttpSession session) {
try {
String clusterAlias = session.getAttribute(KConstants.SessionAlias.CLUSTER_ALIAS).toString();
String target = topicService.getProducersCapacity(clusterAlias);

byte[] output = target.getBytes();
BaseController.response(output, response);
} catch (Exception ex) {
ex.printStackTrace();
}
}

/** Get topic datasets by ajax. */
@RequestMapping(value = "/topic/mock/list/ajax", method = RequestMethod.GET)
public void topicMockAjax(HttpServletResponse response, HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public interface TopicService {
/** Get topic logsize, topicsize. */
public String getTopicSizeAndCapacity(String clusterAlias, String topic);

/** Get producers and total capacity. */
public String getProducersCapacity(String clusterAlias);

/** Get topic producer logsize chart datasets. */
public String queryTopicProducerChart(Map<String, Object> params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,21 @@ public List<TopicRank> getCleanTopicState(Map<String, Object> params) {
return topicDao.getCleanTopicState(params);
}

@Override
public String getProducersCapacity(String clusterAlias) {
JSONObject object = new JSONObject();
Map<String, Object> producerParams = new HashMap<>();
producerParams.put("cluster", clusterAlias);
producerParams.put("stime", CalendarUtils.getCustomLastHourUnix(-1));
producerParams.put("etime", CalendarUtils.getCustomLastHourUnix(0));
object.put("producerSize", topicDao.queryProducerAlives(producerParams).size());
Map<String, Object> capacityParams = new HashMap<>();
capacityParams.put("cluster", clusterAlias);
capacityParams.put("tkey", Topic.CAPACITY);
JSONObject capacity = StrUtils.stringifyByObject(topicDao.getTopicCapacity(capacityParams));
object.put("topicCapacity", capacity.getString("size"));
object.put("capacityType", capacity.getString("type"));
return object.toJSONString();
}

}
52 changes: 52 additions & 0 deletions kafka-eagle-web/src/main/webapp/WEB-INF/views/topic/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,58 @@
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-adn fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div id="producer_number" class="huge">0</div>
<div>APP</div>
</div>
</div>
</div>
<a>
<div class="panel-footer">
<span class="pull-left">Producers</span>
<span class="pull-right">
<i class="fa fa-arrow-circle-right"></i>
</span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<!-- row -->
<div class="col-lg-3 col-md-6 col-md-offset-6">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-database fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div id="producer_total_capacity" class="huge">0</div>
<div id="producer_total_capacity_type">B</div>
</div>
</div>
</div>
<a>
<div class="panel-footer">
<span class="pull-left">TotalCapacity</span>
<span class="pull-right">
<i class="fa fa-arrow-circle-right"></i>
</span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
Expand Down
17 changes: 17 additions & 0 deletions kafka-eagle-web/src/main/webapp/media/js/main/topic/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,22 @@ $(document).ready(function() {
}
});
}

try{
$.ajax({
type : 'get',
dataType : 'json',
url : '/ke/topic/list/total/jmx/ajax',
success : function(datas) {
if (datas != null) {
$("#producer_number").text(datas.producerSize);
$("#producer_total_capacity").text(datas.topicCapacity);
$("#producer_total_capacity_type").text(datas.capacityType);
}
}
});
}catch (e) {
console.log(e.message);
}

});
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
*/
package org.smartloli.kafka.eagle.consumer;

import org.smartloli.kafka.eagle.common.util.CalendarUtils;

/**
* TODO
*
* @author smartloli.
*
* Created by Jan 15, 2019
*/
* TODO
*
* @author smartloli.
*
* Created by Jan 15, 2019
*/
public class JTestConsumer {

public static void main(String[] args) {
System.out.println(CalendarUtils.getCustomLastHourUnix(0));
System.out.println(CalendarUtils.getCustomLastHourUnix(-1));
}
}

0 comments on commit 35971be

Please sign in to comment.