5959import com .cloud .host .Status ;
6060import com .cloud .host .dao .HostDao ;
6161import com .cloud .host .dao .HostTagsDao ;
62+ import com .cloud .network .VirtualNetworkApplianceService ;
6263import com .cloud .network .dao .IPAddressDao ;
64+ import com .cloud .network .dao .RouterHealthCheckResultDao ;
65+ import com .cloud .network .dao .RouterHealthCheckResultVO ;
66+ import com .cloud .network .router .VirtualRouter ;
6367import com .cloud .storage .ImageStore ;
6468import com .cloud .storage .StorageStats ;
6569import com .cloud .storage .Volume ;
7074import com .cloud .utils .Ternary ;
7175import com .cloud .utils .component .Manager ;
7276import com .cloud .utils .component .ManagerBase ;
77+ import com .cloud .vm .DomainRouterVO ;
7378import com .cloud .vm .VirtualMachine .State ;
79+ import com .cloud .vm .dao .DomainRouterDao ;
7480import com .cloud .vm .dao .UserVmDao ;
7581import com .cloud .vm .dao .VMInstanceDao ;
7682
@@ -137,6 +143,10 @@ public String toString() {
137143 private HostTagsDao _hostTagsDao ;
138144 @ Inject
139145 private CAManager caManager ;
146+ @ Inject
147+ private DomainRouterDao domainRouterDao ;
148+ @ Inject
149+ private RouterHealthCheckResultDao routerHealthCheckResultDao ;
140150
141151 public PrometheusExporterImpl () {
142152 super ();
@@ -501,6 +511,35 @@ private void addVMsBySizeMetrics(final List<Item> metricsList, final long dcId,
501511 }
502512 }
503513
514+ private void addVirtualRouterHealthCheckMetrics (final List <Item > metricsList , final long dcId , final String zoneName , final String zoneUuid ) {
515+ List <DomainRouterVO > routers = domainRouterDao .listByDataCenter (dcId );
516+ if (routers == null ) {
517+ return ;
518+ }
519+ for (DomainRouterVO router : routers ) {
520+ if (router .getRole () != VirtualRouter .Role .VIRTUAL_ROUTER ) {
521+ continue ;
522+ }
523+ List <RouterHealthCheckResultVO > checks = routerHealthCheckResultDao .getHealthCheckResults (router .getId ());
524+ if (checks == null || checks .isEmpty ()) {
525+ continue ;
526+ }
527+ for (RouterHealthCheckResultVO check : checks ) {
528+ int resultValue = (check .getCheckResult () ==
529+ VirtualNetworkApplianceService .RouterHealthStatus .SUCCESS ) ? 1 : 0 ;
530+ metricsList .add (new ItemVRHealthCheckResult (
531+ zoneName , router .getInstanceName (),
532+ check .getCheckName (), check .getCheckType (), resultValue ));
533+ if (check .getLastUpdateTime () != null ) {
534+ long epochSeconds = check .getLastUpdateTime ().getTime () / 1000L ;
535+ metricsList .add (new ItemVRHealthCheckLastCheck (
536+ zoneName , router .getInstanceName (),
537+ check .getCheckName (), check .getCheckType (), epochSeconds ));
538+ }
539+ }
540+ }
541+ }
542+
504543 @ Override
505544 public void updateMetrics () {
506545 final List <Item > latestMetricsItems = new ArrayList <Item >();
@@ -518,6 +557,7 @@ public void updateMetrics() {
518557 addDomainMetrics (latestMetricsItems , zoneName , zoneUuid );
519558 addAccountMetrics (latestMetricsItems , dc .getId (), zoneName , zoneUuid );
520559 addVMsBySizeMetrics (latestMetricsItems , dc .getId (), zoneName , zoneUuid );
560+ addVirtualRouterHealthCheckMetrics (latestMetricsItems , dc .getId (), zoneName , zoneUuid );
521561 }
522562 addDomainLimits (latestMetricsItems );
523563 addDomainResourceCount (latestMetricsItems );
@@ -1180,4 +1220,56 @@ public String toMetricsString() {
11801220 return String .format ("%s{zone=\" %s\" ,hostname=\" %s\" ,ip=\" %s\" } %d" , name , zoneName , hostName , hostIp , expiryTimestamp );
11811221 }
11821222 }
1223+
1224+ class ItemVRHealthCheckResult extends Item {
1225+ String zoneName ;
1226+ String routerName ;
1227+ String checkName ;
1228+ String checkType ;
1229+ int result ;
1230+
1231+ public ItemVRHealthCheckResult (String zn , String rn , String cn , String ct , int res ) {
1232+ super ("cloudstack_virtualrouter_healthcheck_result" ,
1233+ "Virtual Router Health Check result (1=success, 0=failure/unknown)" ,
1234+ "gauge" );
1235+ zoneName = zn ;
1236+ routerName = rn ;
1237+ checkName = cn ;
1238+ checkType = ct ;
1239+ result = res ;
1240+ }
1241+
1242+ @ Override
1243+ public String toMetricsString () {
1244+ return String .format (
1245+ "%s{checkname=\" %s\" ,checktype=\" %s\" ,zone=\" %s\" ,virtualrouter=\" %s\" } %d" ,
1246+ name , checkName , checkType , zoneName , routerName , result );
1247+ }
1248+ }
1249+
1250+ class ItemVRHealthCheckLastCheck extends Item {
1251+ String zoneName ;
1252+ String routerName ;
1253+ String checkName ;
1254+ String checkType ;
1255+ long lastCheckEpochSeconds ;
1256+
1257+ public ItemVRHealthCheckLastCheck (String zn , String rn , String cn , String ct , long ts ) {
1258+ super ("cloudstack_virtualrouter_healthcheck_lastcheck" ,
1259+ "Virtual Router Health Check last check timestamp (Unix seconds)" ,
1260+ "gauge" );
1261+ zoneName = zn ;
1262+ routerName = rn ;
1263+ checkName = cn ;
1264+ checkType = ct ;
1265+ lastCheckEpochSeconds = ts ;
1266+ }
1267+
1268+ @ Override
1269+ public String toMetricsString () {
1270+ return String .format (
1271+ "%s{checkname=\" %s\" ,checktype=\" %s\" ,zone=\" %s\" ,virtualrouter=\" %s\" } %d" ,
1272+ name , checkName , checkType , zoneName , routerName , lastCheckEpochSeconds );
1273+ }
1274+ }
11831275}
0 commit comments