Skip to content

Commit 842e96a

Browse files
committed
Address review comments
1 parent 33e588a commit 842e96a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,7 @@ private void addHostMetrics(final List<Item> metricsList, final long dcId, final
221221

222222
metricsList.add(new ItemHostVM(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), vmDao.listByHostId(host.getId()).size()));
223223

224-
// Add SSL certificate expiration metric
225-
if (caManager != null && caManager.getActiveCertificatesMap() != null) {
226-
X509Certificate cert = caManager.getActiveCertificatesMap().getOrDefault(host.getPrivateIpAddress(), null);
227-
if (cert != null) {
228-
long certExpiryEpoch = cert.getNotAfter().getTime() / 1000; // Convert to epoch seconds
229-
metricsList.add(new ItemHostCertExpiry(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), certExpiryEpoch));
230-
}
231-
}
224+
addSSLCertificateExpirationMetrics(metricsList, zoneName, zoneUuid, host);
232225

233226
final CapacityVO coreCapacity = capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU_CORE);
234227

@@ -267,6 +260,18 @@ private void addHostMetrics(final List<Item> metricsList, final long dcId, final
267260
addHostTagsMetrics(metricsList, dcId, zoneName, zoneUuid, totalHosts, upHosts, downHosts, total, up, down);
268261
}
269262

263+
private void addSSLCertificateExpirationMetrics(List<Item> metricsList, String zoneName, String zoneUuid, HostVO host) {
264+
if (caManager == null || caManager.getActiveCertificatesMap() == null) {
265+
return;
266+
}
267+
X509Certificate cert = caManager.getActiveCertificatesMap().getOrDefault(host.getPrivateIpAddress(), null);
268+
if (cert == null) {
269+
return;
270+
}
271+
long certExpiryEpoch = cert.getNotAfter().getTime() / 1000; // Convert to epoch seconds
272+
metricsList.add(new ItemHostCertExpiry(zoneName, zoneUuid, host.getName(), host.getUuid(), host.getPrivateIpAddress(), certExpiryEpoch));
273+
}
274+
270275
private String markTagMaps(HostVO host, Map<String, Integer> totalHosts, Map<String, Integer> upHosts, Map<String, Integer> downHosts) {
271276
List<HostTagVO> hostTagVOS = _hostTagsDao.getHostTags(host.getId());
272277
List<String> hostTags = new ArrayList<>();

0 commit comments

Comments
 (0)