mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 15:29:26 +01:00
Use the Helpers regular expressions for assigning the datasource category.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
5619b65fe2
commit
a0bd8a7d46
@ -54,7 +54,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
public List<DataPoint> CurrentlyDisplayed = new List<DataPoint>();
|
||||
public IXenObject XenObject;
|
||||
public readonly string Id;
|
||||
public DataType Category;
|
||||
public string DataSourceName;
|
||||
public string FriendlyName { get; }
|
||||
private int MultiplyingFactor = 1;
|
||||
@ -107,7 +106,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
}
|
||||
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Latency;
|
||||
}
|
||||
else if (settype.StartsWith("vif") || settype.StartsWith("pif"))
|
||||
{
|
||||
@ -115,7 +113,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
Unit unit = settype.EndsWith("errors") ? Unit.CountsPerSecond : Unit.BytesPerSecond;
|
||||
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, unit, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Network;
|
||||
}
|
||||
else if (settype.StartsWith("vbd"))
|
||||
{
|
||||
@ -135,13 +132,9 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
|
||||
else
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto);
|
||||
|
||||
dataSet.Category = DataType.Disk;
|
||||
}
|
||||
else if ((settype.Contains("memory") || settype.Contains("allocation")) && !settype.Contains("utilisation"))
|
||||
{
|
||||
dataSet.Category = settype.Contains("gpu") ? DataType.Gpu : DataType.Memory;
|
||||
|
||||
dataSet.MultiplyingFactor = settype.Contains("kib") || settype == "memory_internal_free"
|
||||
? (int)Util.BINARY_KILO
|
||||
: 1;
|
||||
@ -166,29 +159,23 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto);
|
||||
dataSet.MultiplyingFactor = 100;
|
||||
dataSet.Category = DataType.LoadAverage;
|
||||
}
|
||||
else if (settype.EndsWith("-avg-freq"))
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.MegaHertz, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Cpu;
|
||||
}
|
||||
else if (settype.StartsWith("cpu") || settype == "avg_cpu" || settype.StartsWith("runstate"))
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Fixed);
|
||||
dataSet.MultiplyingFactor = 100;
|
||||
dataSet.Category = DataType.Cpu;
|
||||
}
|
||||
else if (settype.StartsWith("io_throughput"))
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto);
|
||||
dataSet.MultiplyingFactor = (int)Util.BINARY_MEGA; //xapi units are in mebibytes/sec
|
||||
dataSet.Category = DataType.Storage;
|
||||
}
|
||||
else if (settype.StartsWith("sr"))
|
||||
{
|
||||
dataSet.Category = DataType.Storage;
|
||||
|
||||
if (settype.EndsWith("cache_size"))
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.Bytes, RangeScaleMode.Auto);
|
||||
else if (settype.EndsWith("cache_hits") || settype.EndsWith("cache_misses"))
|
||||
@ -198,19 +185,16 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
{
|
||||
//xapi units are in requests/sec
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.CountsPerSecond, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Storage;
|
||||
}
|
||||
else if (settype.StartsWith("iowait"))
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto);
|
||||
dataSet.MultiplyingFactor = 100;
|
||||
dataSet.Category = DataType.Storage;
|
||||
}
|
||||
else if (settype.StartsWith("inflight") || settype.StartsWith("avgqu_sz"))
|
||||
{
|
||||
//xapi units are in requests
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Storage;
|
||||
}
|
||||
else if (settype.StartsWith("gpu"))
|
||||
{
|
||||
@ -229,7 +213,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Fixed);
|
||||
dataSet.MultiplyingFactor = 100;
|
||||
}
|
||||
dataSet.Category = DataType.Gpu;
|
||||
}
|
||||
else if (settype.StartsWith("pvsaccelerator"))
|
||||
{
|
||||
@ -241,25 +224,21 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Fixed); // values range from 0 to 100
|
||||
else
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Pvs;
|
||||
}
|
||||
else if (settype.StartsWith("read_latency") || settype.StartsWith("write_latency"))
|
||||
{
|
||||
// Units are microseconds
|
||||
dataSet.MultiplyingFactor = 1000;
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Latency;
|
||||
}
|
||||
else if (settype.StartsWith("read") || settype.StartsWith("write"))
|
||||
{
|
||||
// Units are Bytes/second
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Storage;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto);
|
||||
dataSet.Category = DataType.Custom;
|
||||
}
|
||||
|
||||
return dataSet;
|
||||
@ -267,50 +246,49 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
|
||||
public static DataSet Create(string id, IXenObject xenObject)
|
||||
{
|
||||
string[] bits = id.Split(':');
|
||||
if (bits.Length < 3)
|
||||
return Create(id, null, true, id);
|
||||
|
||||
string theId;
|
||||
string theObjType;
|
||||
string theUuid;
|
||||
string theDataName;
|
||||
|
||||
if (bits.Length == 4)
|
||||
if (ParseId(id, out string objType, out string objUuid, out string dataSourceName))
|
||||
{
|
||||
string[] important_bits = new string[3];
|
||||
Array.Copy(bits, 1, important_bits, 0, 3);
|
||||
string theId = $"{objType}:{objUuid}:{dataSourceName}";
|
||||
|
||||
theId = string.Join(":", important_bits);
|
||||
theObjType = bits[1];
|
||||
theUuid = bits[2];
|
||||
theDataName = bits[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
theId = id;
|
||||
theObjType = bits[0];
|
||||
theUuid = bits[1];
|
||||
theDataName = bits[2];
|
||||
}
|
||||
if (objType == "host")
|
||||
{
|
||||
Host host = xenObject.Connection.Cache.Find_By_Uuid<Host>(objUuid);
|
||||
if (host != null)
|
||||
return Create(theId, host, (xenObject as Host)?.uuid != objUuid, dataSourceName);
|
||||
}
|
||||
|
||||
if (theObjType == "host")
|
||||
{
|
||||
Host host = xenObject.Connection.Cache.Find_By_Uuid<Host>(theUuid);
|
||||
if (host != null)
|
||||
return Create(theId, host, (xenObject as Host)?.uuid != theUuid, theDataName);
|
||||
}
|
||||
|
||||
if (theObjType == "vm")
|
||||
{
|
||||
VM vm = xenObject.Connection.Cache.Find_By_Uuid<VM>(theUuid);
|
||||
if (vm != null)
|
||||
return Create(theId, vm, (xenObject as VM)?.uuid != theUuid, theDataName);
|
||||
if (objType == "vm")
|
||||
{
|
||||
VM vm = xenObject.Connection.Cache.Find_By_Uuid<VM>(objUuid);
|
||||
if (vm != null)
|
||||
return Create(theId, vm, (xenObject as VM)?.uuid != objUuid, dataSourceName);
|
||||
}
|
||||
}
|
||||
|
||||
return Create(id, null, true, id);
|
||||
}
|
||||
|
||||
public static bool ParseId(string id, out string objType, out string objUuid, out string dataSourceName)
|
||||
{
|
||||
var bits = id.Split(':').ToList();
|
||||
|
||||
if (bits.Count > 3)
|
||||
bits.RemoveAt(0);
|
||||
|
||||
if (bits.Count >= 3)
|
||||
{
|
||||
objType = bits[0];
|
||||
objUuid = bits[1];
|
||||
dataSourceName = bits[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
objType = null;
|
||||
objUuid = null;
|
||||
dataSourceName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public List<DataPoint> GetRange(DataTimeRange xrange, long intervalneed, long intervalat)
|
||||
@ -742,36 +720,4 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DataType { Cpu, Memory, Disk, Storage, Network, Latency, LoadAverage, Gpu, Pvs, Custom };
|
||||
|
||||
public static class DatatypeExtensions
|
||||
{
|
||||
public static string ToStringI18N(this DataType datatype)
|
||||
{
|
||||
switch (datatype)
|
||||
{
|
||||
case DataType.Cpu:
|
||||
return Messages.DATATYPE_CPU;
|
||||
case DataType.Memory:
|
||||
return Messages.DATATYPE_MEMORY;
|
||||
case DataType.Disk:
|
||||
return Messages.DATATYPE_DISK;
|
||||
case DataType.Storage:
|
||||
return Messages.DATATYPE_STORAGE;
|
||||
case DataType.Network:
|
||||
return Messages.DATATYPE_NETWORK;
|
||||
case DataType.Latency:
|
||||
return Messages.DATATYPE_LATENCY;
|
||||
case DataType.LoadAverage:
|
||||
return Messages.DATATYPE_LOADAVERAGE;
|
||||
case DataType.Gpu:
|
||||
return Messages.DATATYPE_GPU;
|
||||
case DataType.Pvs:
|
||||
return Messages.DATATYPE_PVS;
|
||||
default:
|
||||
return Messages.DATATYPE_CUSTOM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
public Color Color;
|
||||
public bool ColorChanged;
|
||||
public string Id;
|
||||
public DataType Category;
|
||||
public Helpers.DataSourceCategory Category;
|
||||
|
||||
public DataSourceItem(Data_source ds, string friendlyname, Color color, string id, IXenObject xo = null)
|
||||
{
|
||||
@ -140,8 +140,8 @@ namespace XenAdmin.Controls.CustomDataGraph
|
||||
Color = color;
|
||||
Id = id;
|
||||
|
||||
if (xo != null)
|
||||
Category = DataSet.Create(id, xo).Category;
|
||||
if (DataSet.ParseId(id, out _, out _, out string dataSourceName))
|
||||
Category = Helpers.GetDataSourceCategory(dataSourceName);
|
||||
}
|
||||
|
||||
public string GetDataSource()
|
||||
|
@ -959,31 +959,114 @@ namespace XenAdmin.Core
|
||||
|
||||
#endregion
|
||||
|
||||
public enum DataSourceCategory
|
||||
{
|
||||
Cpu,
|
||||
Memory,
|
||||
Disk,
|
||||
Storage,
|
||||
Network,
|
||||
Latency,
|
||||
LoadAverage,
|
||||
Gpu,
|
||||
Pvs,
|
||||
Custom
|
||||
}
|
||||
|
||||
public static string ToStringI18N(this DataSourceCategory category)
|
||||
{
|
||||
switch (category)
|
||||
{
|
||||
case DataSourceCategory.Cpu:
|
||||
return Messages.DATATYPE_CPU;
|
||||
case DataSourceCategory.Memory:
|
||||
return Messages.DATATYPE_MEMORY;
|
||||
case DataSourceCategory.Disk:
|
||||
return Messages.DATATYPE_DISK;
|
||||
case DataSourceCategory.Storage:
|
||||
return Messages.DATATYPE_STORAGE;
|
||||
case DataSourceCategory.Network:
|
||||
return Messages.DATATYPE_NETWORK;
|
||||
case DataSourceCategory.Latency:
|
||||
return Messages.DATATYPE_LATENCY;
|
||||
case DataSourceCategory.LoadAverage:
|
||||
return Messages.DATATYPE_LOADAVERAGE;
|
||||
case DataSourceCategory.Gpu:
|
||||
return Messages.DATATYPE_GPU;
|
||||
case DataSourceCategory.Pvs:
|
||||
return Messages.DATATYPE_PVS;
|
||||
default:
|
||||
return Messages.DATATYPE_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
public static Regex CpuRegex = new Regex("^cpu([0-9]+)$");
|
||||
public static Regex CpuAvgFreqRegex = new Regex("^CPU([0-9]+)-avg-freq$");
|
||||
static Regex CpuAvgFreqRegex = new Regex("^CPU([0-9]+)-avg-freq$");
|
||||
public static Regex CpuStateRegex = new Regex("^cpu([0-9]+)-(C|P)([0-9]+)$");
|
||||
static Regex CpuOtherRegex = new Regex("^cpu_avg|avg_cpu$");
|
||||
private static Regex VcpuRegex = new Regex("^runstate_(blocked|concurrency_hazard|full_contention|fullrun|partial_contention|partial_run)$");
|
||||
static Regex VifRegex = new Regex("^vif_([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifEthRegex = new Regex("^pif_eth([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifVlanRegex = new Regex("^pif_eth([0-9]+).([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifVlanRegex = new Regex("^pif_eth([0-9]+).([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifBrRegex = new Regex("^pif_xenbr([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifXapiRegex = new Regex("^pif_xapi([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifXapiRegex = new Regex("^pif_xapi([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifTapRegex = new Regex("^pif_tap([0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifLoRegex = new Regex("^pif_lo_(tx|rx)((_errors)?)$");
|
||||
static Regex PifBondRegex = new Regex("^pif_(bond[0-9]+)_(tx|rx)((_errors)?)$");
|
||||
static Regex PifOtherRegex = new Regex("^pif_aggr_(tx|rx)$");
|
||||
static Regex DiskRegex = new Regex("^vbd_((xvd|hd)[a-z]+)(_(read|write))?(_latency)?$");
|
||||
static Regex DiskIopsRegex = new Regex("^vbd_((xvd|hd)[a-z]+)_iops_(read|write|total)$");
|
||||
static Regex DiskThroughputRegex = new Regex("^vbd_((xvd|hd)[a-z]+)_io_throughput_(read|write|total)$");
|
||||
static Regex DiskOtherRegex = new Regex("^vbd_((xvd|hd)[a-z]+)_(avgqu_sz|inflight|iowait)$");
|
||||
static Regex NetworkLatencyRegex = new Regex("^network/latency$");
|
||||
static Regex XapiLatencyRegex = new Regex("^xapi_healthcheck/latency$");
|
||||
static Regex XapiMemoryRegex = new Regex("^xapi_(allocation|free_memory|live_memory|memory_usage)_kib$");
|
||||
static Regex StatefileLatencyRegex = new Regex("^statefile/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/latency$");
|
||||
static Regex LoadAvgRegex = new Regex("loadavg");
|
||||
static Regex SrRegex = new Regex("^sr_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}_cache_(size|hits|misses)");
|
||||
static Regex SrRegex = new Regex("^sr_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}_cache_(size|hits|misses)");
|
||||
static Regex SrIORegex = new Regex("^(io_throughput|iops)_(read|write|total)_([a-f0-9]{8})$");
|
||||
static Regex SrOtherRegex = new Regex("^(latency|avgqu_sz|inflight|iowait)_([a-f0-9]{8})$");
|
||||
static Regex SrReadWriteRegex = new Regex("^((read|write)(_latency)?)_([a-f0-9]{8})$");
|
||||
static Regex GpuRegex = new Regex(@"^gpu_((memory_(free|used))|power_usage|temperature|(utilisation_(compute|memory_io)))_((([a-fA-F0-9]{4}\/)|([a-fA-F0-9]{8}\/))?[a-fA-F0-9]{2}\/[0-1][a-fA-F0-9].[0-7])$");
|
||||
|
||||
public static DataSourceCategory GetDataSourceCategory(string name)
|
||||
{
|
||||
if (CpuRegex.IsMatch(name) || CpuAvgFreqRegex.IsMatch(name) ||
|
||||
CpuStateRegex.IsMatch(name) || CpuOtherRegex.IsMatch(name) || VcpuRegex.IsMatch(name))
|
||||
return DataSourceCategory.Cpu;
|
||||
|
||||
if (VifRegex.IsMatch(name) || PifEthRegex.IsMatch(name) || PifVlanRegex.IsMatch(name) ||
|
||||
PifBrRegex.IsMatch(name) || PifXapiRegex.IsMatch(name) || PifBondRegex.IsMatch(name) ||
|
||||
PifLoRegex.IsMatch(name) || PifTapRegex.IsMatch(name) || PifOtherRegex.IsMatch(name))
|
||||
return DataSourceCategory.Network;
|
||||
|
||||
if (DiskRegex.IsMatch(name) || DiskIopsRegex.IsMatch(name) ||
|
||||
DiskThroughputRegex.IsMatch(name) || DiskOtherRegex.IsMatch(name))
|
||||
return DataSourceCategory.Disk;
|
||||
|
||||
if (SrRegex.IsMatch(name) || SrIORegex.IsMatch(name) ||
|
||||
SrOtherRegex.IsMatch(name) || SrReadWriteRegex.IsMatch(name))
|
||||
return DataSourceCategory.Storage;
|
||||
|
||||
if (GpuRegex.IsMatch(name))
|
||||
return DataSourceCategory.Gpu;
|
||||
|
||||
if (NetworkLatencyRegex.IsMatch(name) || XapiLatencyRegex.IsMatch(name) ||
|
||||
StatefileLatencyRegex.IsMatch(name))
|
||||
return DataSourceCategory.Latency;
|
||||
|
||||
if (LoadAvgRegex.IsMatch(name))
|
||||
return DataSourceCategory.LoadAverage;
|
||||
|
||||
if (name.StartsWith("pvsaccelerator"))
|
||||
return DataSourceCategory.Pvs;
|
||||
|
||||
if (XapiMemoryRegex.IsMatch(name) || name.StartsWith("memory"))
|
||||
return DataSourceCategory.Memory;
|
||||
|
||||
return DataSourceCategory.Custom;
|
||||
}
|
||||
|
||||
public static string GetFriendlyDataSourceName(string name, IXenObject iXenObject)
|
||||
{
|
||||
if (iXenObject == null)
|
||||
|
Loading…
Reference in New Issue
Block a user