Repository navigation
Conversation
DaanHoogland
left a comment
There was a problem hiding this comment.
seems to look good generally (no prometheus expert, but seems like useful functionality)
| List<String> hostTags = _hostTagsDao.gethostTags(host.getId()); | ||
| String hosttags = StringUtils.join(hostTags, ","); | ||
| for (String tag : hostTags) { | ||
| Integer current = totalHosts.get(tag) != null ? totalHosts.get(tag) : 0; | ||
| totalHosts.put(tag, current + 1); | ||
| } | ||
| if (host.getStatus() == Status.Up) { | ||
| for (String tag : hostTags) { | ||
| Integer current = upHosts.get(tag) != null ? upHosts.get(tag) : 0; | ||
| upHosts.put(tag, current + 1); | ||
| } | ||
| } else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down) { | ||
| for (String tag : hostTags) { | ||
| Integer current = downHosts.get(tag) != null ? downHosts.get(tag) : 0; | ||
| downHosts.put(tag, current + 1); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
addHostMetrics() is already way to long, and the new functionality shouldn't be added to it, so as an example
this functionality seems like it could be extracted and there is some repetition in it that can be generalised as well.
| List<String> hostTags = _hostTagsDao.gethostTags(host.getId()); | |
| String hosttags = StringUtils.join(hostTags, ","); | |
| for (String tag : hostTags) { | |
| Integer current = totalHosts.get(tag) != null ? totalHosts.get(tag) : 0; | |
| totalHosts.put(tag, current + 1); | |
| } | |
| if (host.getStatus() == Status.Up) { | |
| for (String tag : hostTags) { | |
| Integer current = upHosts.get(tag) != null ? upHosts.get(tag) : 0; | |
| upHosts.put(tag, current + 1); | |
| } | |
| } else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down) { | |
| for (String tag : hostTags) { | |
| Integer current = downHosts.get(tag) != null ? downHosts.get(tag) : 0; | |
| downHosts.put(tag, current + 1); | |
| } | |
| } | |
| String hosttags = markTagMaps(totalHosts, upHosts, downHosts); |
and then add
private String markTagMaps(Map<String, Integer> totalHosts, Map<String, Integer> upHosts, Map<String, Integer> downHosts) {
List<String> hostTags = _hostTagsDao.gethostTags(host.getId());
markTags(hostTags,totalHosts);
if (host.getStatus() == Status.Up) {
markTags(hostTags, upHosts);
} else if (host.getStatus() == Status.Disconnected || host.getStatus() == Status.Down) {
markTags(hostTags, downHosts);
}
return StringUtils.join(hostTags, ",");
}
and
private void markTags(List<String tags, Map<String, Integer> tagMap) {
for (String tag : tags) {
Integer current = tagMap.get(tag) != null ? tagMap.get(tag) : 0;
tagMap.put(tag, current + 1);
}
}
| } | ||
|
|
||
| metricsList.add(new ItemHost(zoneName, zoneUuid, ONLINE, up, null)); | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, OFFLINE, down, null)); | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, TOTAL, total, null)); | ||
| for (Map.Entry<String, Integer> entry : totalHosts.entrySet()) { | ||
| String tag = entry.getKey(); | ||
| Integer count = entry.getValue(); | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, TOTAL, count, tag)); | ||
| if (upHosts.get(tag) != null) { | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, ONLINE, upHosts.get(tag), tag)); | ||
| } else { | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, ONLINE, 0, tag)); | ||
| } | ||
| if (downHosts.get(tag) != null) { | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, OFFLINE, downHosts.get(tag), tag)); | ||
| } else { | ||
| metricsList.add(new ItemHost(zoneName, zoneUuid, OFFLINE, 0, tag)); | ||
| } | ||
| } | ||
| for (Map.Entry<String, Integer> entry : totalHosts.entrySet()) { | ||
| String tag = entry.getKey(); | ||
| Ternary<Long, Long, Long> allocatedCapacityByTag = capacityDao.findCapacityByZoneAndHostTag(dcId, tag); | ||
| metricsList.add(new ItemVMCore(zoneName, zoneUuid, null, null, null, ALLOCATED, allocatedCapacityByTag.first(), 0, tag)); | ||
| metricsList.add(new ItemHostCpu(zoneName, zoneUuid, null, null, null, null, ALLOCATED, allocatedCapacityByTag.second(),0, tag)); | ||
| metricsList.add(new ItemHostMemory(zoneName, zoneUuid, null, null, null, null, ALLOCATED, allocatedCapacityByTag.third(), 0, tag)); |
|
|
||
| List<String> allHostTags = hostDao.listAll().stream() | ||
| .flatMap( h -> _hostTagsDao.gethostTags(h.getId()).stream()) | ||
| .distinct() | ||
| .collect(Collectors.toList()); | ||
|
|
||
| for (final State state : State.values()) { | ||
| for (final String hosttag : allHostTags) { | ||
| final Long count = vmDao.countByZoneAndStateAndHostTag(dcId, state, hosttag); | ||
| metricsList.add(new ItemVMByTag(zoneName, zoneUuid, state.name().toLowerCase(), count, hosttag)); | ||
| } | ||
| } |
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
|
@soreana another conflict... |
|
@soreana will you still work on this? |
|
@DaanHoogland Yes, I'm still work on this but not actively. My plan is to remove object creation and use functions to export entries. I didn't find a time to do so yet. |
34c1525 to
51d4e54
Compare
Description
For a long time, I've worked with Prometheus. I've always wanted to clean its code. Now I have enough time to work on it.
My idea is to use a lambda expression rather than an object creation for Prometheus output.
Add documentation and UI support to it.
Let me know if you have any ideas.
P.S: This pr is based on the #4438. I will rebase it when it gets merged.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?