private void AddDriveMetrics(System.IO.DriveInfo drive, List<Amazon.CloudWatch.Model.MetricDatum> metrics)
{
string driveName = String.Format("{0}", drive.Name[0]);
// If we need to filter drives, then only include those
// explicitly specified.
if (_includeDrives != null)
{
if (!_includeDrives.Contains(driveName))
{
Info("Not including drive: {0}", driveName);
return;
}
}
// For the drive,
// collect the free space values we care about,
// formulate the request objects,
// submit to AWS
Info("Adding metrics for drive: {0}", driveName);
// Skip drives not ready
if (!drive.IsReady)
{
Info("\tNot ready");
return;
}
var dimensions = new List<Amazon.CloudWatch.Model.Dimension>();
dimensions.Add(new Amazon.CloudWatch.Model.Dimension()
{
Name = "InstanceId",
Value = _instanceId
});
dimensions.Add(new Amazon.CloudWatch.Model.Dimension()
{
Name = "Drive",
Value = driveName
});
long spaceAvailable = drive.AvailableFreeSpace;
long totalSize = drive.TotalSize;
long spaceUsed = drive.TotalSize - drive.AvailableFreeSpace;
double diskUtilized;
// If the drive has no size, then assume 100% used
if (totalSize == 0)
diskUtilized = 1.0;
else
diskUtilized = Convert.ToDouble(spaceUsed) / Convert.ToDouble(totalSize);
diskUtilized *= 100.0;
Info("\tTotal Disk Space: {0:N0} bytes", totalSize);
if (_isSubmitDiskSpaceUsed)
{
Info("\tDisk Space Used: {0:N0} bytes", spaceUsed);
metrics.Add(new Amazon.CloudWatch.Model.MetricDatum()
{
MetricName = "DiskSpaceUsed",
Unit = "Bytes",
Value = spaceUsed,
Dimensions = dimensions
});
}
if (_isSubmitDiskSpaceAvailable)
{
Info("\tDisk Space Available: {0:N0} bytes", spaceAvailable);
metrics.Add(new Amazon.CloudWatch.Model.MetricDatum()
{
MetricName = "DiskSpaceAvailable",
Unit = "Bytes",
Value = spaceAvailable,
Dimensions = dimensions
});
}
if (_isSubmitDiskSpaceUtilization)
{
Info("\tDisk Space Utilization: {0:F1}%", diskUtilized);
metrics.Add(new Amazon.CloudWatch.Model.MetricDatum()
{
MetricName = "DiskSpaceUtilization",
Unit = "Percent",
Value = diskUtilized,
Dimensions = dimensions
});
}
}