private static string NormalizedIdentifier(string host, ReportedValue sensor) { // Take the sensor's identifier (eg. /nvidiagpu/0/load/0) // and transform into nvidiagpu.0.load.<name> where <name> // is the name of the sensor lowercased with spaces removed. // A name like "GPU Core" is turned into "gpucore". Also // since some names are like "cpucore#2", turn them into // separate metrics by replacing "#" with "." string identifier = sensor.Identifier.Replace('/', '.').Substring(1); identifier = identifier.Remove(identifier.LastIndexOf('.')).Replace("{", null).Replace("}", null); string name = sensor.Sensor.ToLower().Replace(" ", null).Replace('#', '.'); return($"ohm.{host}.{identifier}.{name}"); }
private PointData NewPoint(DateTime reportTime, ReportedValue sensor) { var sensorType = Enum.GetName(typeof(SensorType), sensor.SensorType); return(PointData.Measurement(sensorType) .Tag("host", _localHost) .Tag("app", "ohm") .Tag("hardware", sensor.Hardware) .Tag("hardware_type", Enum.GetName(typeof(HardwareType), sensor.HardwareType)) .Tag("identifier", sensor.Identifier) .Tag("sensor", sensor.Sensor) .Field("value", sensor.Value) .Field("sensor_index", sensor.SensorIndex) .Timestamp(reportTime.ToUniversalTime(), WritePrecision.S)); }
public string FormatGraphiteData(long epoch, ReportedValue data) { // Graphite API wants <metric> <value> <timestamp>. We prefix the metric // with `ohm` as to not overwrite potentially existing metrics string id = NormalizedIdentifier(_localHost, data); if (!_tags) { return(Invariant($"{id} {data.Value} {epoch:d}")); } return($"{id};" + $"host={_localHost};" + "app=ohm;" + $"hardware={GraphiteEscape(data.Hardware)};" + $"hardware_type={Enum.GetName(typeof(HardwareType), data.HardwareType)};" + $"sensor_type={Enum.GetName(typeof(SensorType), data.SensorType)};" + $"sensor_index={data.SensorIndex};" + $"raw_name={GraphiteEscape(data.Sensor)} " + Invariant($"{data.Value} {epoch:d}")); }
private LineProtocolPoint NewPoint(DateTime reportTime, ReportedValue sensor) { var sensorType = Enum.GetName(typeof(SensorType), sensor.SensorType); var tags = new Dictionary <string, string>() { { "host", _localHost }, { "app", "ohm" }, { "hardware", sensor.Hardware }, { "hardware_type", Enum.GetName(typeof(HardwareType), sensor.HardwareType) }, { "identifier", sensor.Identifier }, { "sensor", sensor.Sensor }, }; var fields = new Dictionary <string, object>() { { "value", sensor.Value }, { "sensor_index", sensor.SensorIndex } }; return(new LineProtocolPoint(sensorType, fields, tags, reportTime.ToUniversalTime())); }
private static (string, double) BaseReport(ReportedValue report) { // Convert reported value into a base value by converting MB and GB into bytes, etc. // Flow rate is still liters per hour, even though liters per second may seem more // "base-unity", as grafana contained the former but not the latter. Fan speed remains // revolutions per minute, as I'm unaware of any manufacturer reporting fan speed as // revolutions per second. double BaseValue() { double value = report.Value; switch (report.SensorType) { case SensorType.Data: // GB = 2^30 Bytes return(value * (1L << 30)); case SensorType.SmallData: // MB = 2^20 Bytes return(value * (1L << 20)); case SensorType.Clock: // MHz return(value * 1000000); default: return(value); } } string BaseUnit() { switch (report.SensorType) { case SensorType.Voltage: // V return("volts"); case SensorType.Frequency: // Hz case SensorType.Clock: // MHz return("hertz"); case SensorType.Temperature: // °C return("celsius"); case SensorType.Power: // W return("watts"); case SensorType.Data: // GB = 2^30 Bytes case SensorType.SmallData: // MB = 2^20 Bytes return("bytes"); case SensorType.Throughput: // B/s return("bytes_per_second"); case SensorType.Load: // % return("load_percent"); case SensorType.Control: // % return("control_percent"); case SensorType.Level: // % return("level_percent"); case SensorType.Fan: // RPM return("revolutions_per_minute"); case SensorType.Flow: // L/h return("liters_per_hour"); case SensorType.Current: return("amps"); case SensorType.TimeSpan: return("seconds"); case SensorType.Factor: // 1 default: return(report.SensorType.ToString().ToLowerInvariant()); } } return(BaseUnit(), BaseValue()); }