mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	kvm: get vm disk stats for ceph disks (#7045)
This commit is contained in:
		
							parent
							
								
									55d2d26449
								
							
						
					
					
						commit
						743ebe7278
					
				| @ -4016,15 +4016,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|                 final DomainBlockStats blockStats = dm.blockStats(disk.getDiskLabel()); |                 final DomainBlockStats blockStats = dm.blockStats(disk.getDiskLabel()); | ||||||
|                 final String path = disk.getDiskPath(); // for example, path = /mnt/pool_uuid/disk_path/ |                 String diskPath = getDiskPathFromDiskDef(disk); | ||||||
|                 String diskPath = null; |                 if (diskPath != null) { | ||||||
|                 if (path != null) { |                     final VmDiskStatsEntry stat = new VmDiskStatsEntry(vmName, diskPath, blockStats.wr_req, blockStats.rd_req, blockStats.wr_bytes, blockStats.rd_bytes); | ||||||
|                     final String[] token = path.split("/"); |                     stats.add(stat); | ||||||
|                     if (token.length > 3) { |  | ||||||
|                         diskPath = token[3]; |  | ||||||
|                         final VmDiskStatsEntry stat = new VmDiskStatsEntry(vmName, diskPath, blockStats.wr_req, blockStats.rd_req, blockStats.wr_bytes, blockStats.rd_bytes); |  | ||||||
|                         stats.add(stat); |  | ||||||
|                     } |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -4036,6 +4031,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     protected String getDiskPathFromDiskDef(DiskDef disk) { | ||||||
|  |         final String path = disk.getDiskPath(); | ||||||
|  |         if (path != null) { | ||||||
|  |             final String[] token = path.split("/"); | ||||||
|  |             if (DiskProtocol.RBD.equals(disk.getDiskProtocol())) { | ||||||
|  |                 // for example, path = <RBD pool>/<disk path> | ||||||
|  |                 if (token.length > 1) { | ||||||
|  |                     return token[1]; | ||||||
|  |                 } | ||||||
|  |             } else if (token.length > 3) { | ||||||
|  |                 // for example, path = /mnt/pool_uuid/disk_path/ | ||||||
|  |                 return token[3]; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private class VmStats { |     private class VmStats { | ||||||
|         long _usedTime; |         long _usedTime; | ||||||
|         long _tx; |         long _tx; | ||||||
|  | |||||||
| @ -990,6 +990,10 @@ public class LibvirtVMDef { | |||||||
|             _sourcePath = volPath; |             _sourcePath = volPath; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public DiskProtocol getDiskProtocol() { | ||||||
|  |             return _diskProtocol; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         public DiskBus getBusType() { |         public DiskBus getBusType() { | ||||||
|             return _bus; |             return _bus; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -6053,6 +6053,39 @@ public class LibvirtComputingResourceTest { | |||||||
|         verify(scriptMock).add(String.valueOf(port)); |         verify(scriptMock).add(String.valueOf(port)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |    @Test | ||||||
|  |     public void testGetDiskPathFromDiskDefForRBD() { | ||||||
|  |         DiskDef diskDef = new DiskDef(); | ||||||
|  |         diskDef.defNetworkBasedDisk("cloudstack/diskpath", "1.1.1.1", 3300, "username", "uuid", 0, | ||||||
|  |                 DiskDef.DiskBus.VIRTIO, DiskDef.DiskProtocol.RBD, DiskDef.DiskFmtType.RAW); | ||||||
|  |         String diskPath = libvirtComputingResourceSpy.getDiskPathFromDiskDef(diskDef); | ||||||
|  |         Assert.assertEquals("diskpath", diskPath); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testGetDiskPathFromDiskDefForNFS() { | ||||||
|  |         DiskDef diskDef = new DiskDef(); | ||||||
|  |         diskDef.defFileBasedDisk("/mnt/pool/filepath", 0, DiskDef.DiskBus.VIRTIO, DiskDef.DiskFmtType.QCOW2); | ||||||
|  |         String diskPath = libvirtComputingResourceSpy.getDiskPathFromDiskDef(diskDef); | ||||||
|  |         Assert.assertEquals("filepath", diskPath); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testGetDiskPathFromDiskDefForNFSWithNullPath() { | ||||||
|  |         DiskDef diskDef = new DiskDef(); | ||||||
|  |         diskDef.defFileBasedDisk(null, 0, DiskDef.DiskBus.VIRTIO, DiskDef.DiskFmtType.QCOW2); | ||||||
|  |         String diskPath = libvirtComputingResourceSpy.getDiskPathFromDiskDef(diskDef); | ||||||
|  |         Assert.assertNull(diskPath); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testGetDiskPathFromDiskDefForNFSWithUnsupportedPath() { | ||||||
|  |         DiskDef diskDef = new DiskDef(); | ||||||
|  |         diskDef.defFileBasedDisk("/mnt/unsupported-path", 0, DiskDef.DiskBus.VIRTIO, DiskDef.DiskFmtType.QCOW2); | ||||||
|  |         String diskPath = libvirtComputingResourceSpy.getDiskPathFromDiskDef(diskDef); | ||||||
|  |         Assert.assertNull(diskPath); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Test |     @Test | ||||||
|     @PrepareForTest(value = {LibvirtComputingResource.class}) |     @PrepareForTest(value = {LibvirtComputingResource.class}) | ||||||
|     public void testNetworkUsageMethod1() throws Exception { |     public void testNetworkUsageMethod1() throws Exception { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user