private void PollSensors()
 {
     foreach (var sensor in _collector.ReadAllSensors())
     {
         var(unit, value) = BaseReport(sensor);
         var hw   = Enum.GetName(typeof(HardwareType), sensor.HardwareType)?.ToLowerInvariant();
         var name = Rx.Replace($"ohm_{hw}_{unit}", "_");
         _metrics.CreateGauge(name, "Metric reported by open hardware sensor", "hardware", "sensor", "hw_instance")
         .WithLabels(sensor.Hardware, sensor.Sensor, sensor.HardwareInstance)
         .Set(value);
     }
 }
 private void PollSensors()
 {
     foreach (var sensor in _collector.ReadAllSensors())
     {
         _metrics.CreateGauge(
             sensor.Identifier.Substring(1).Replace('/', '_'),
             "Metric reported by open hardware sensor",
             "host", "app", "hardware", "hardware_type", "sensor", "sensor_index")
         .WithLabels(_localHost, "ohm", sensor.Hardware,
                     Enum.GetName(typeof(HardwareType), sensor.HardwareType),
                     sensor.Sensor,
                     sensor.SensorIndex.ToString())
         .Set(sensor.Value);
     }
 }
Esempio n. 3
0
        private async void ReportMetrics(object sender, ElapsedEventArgs e)
        {
            Logger.Debug("Starting to report metrics");
            try
            {
                // Read all the sensors into a list so that they are only polled once.
                // Polling sensors can be relatively expensive so the intermediate
                // list cuts down on the number of potential updates.
                var stopwatch = Stopwatch.StartNew();
                var sensors   = _collector.ReadAllSensors().ToList();
                await _writer.ReportMetrics(e.SignalTime, sensors);

                Logger.Info($"Sent {sensors.Count} metrics in {stopwatch.Elapsed.TotalMilliseconds}ms");
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to send metrics");
            }
        }
Esempio n. 4
0
        private async void ReportMetrics(object sender, ElapsedEventArgs e)
        {
            Logger.Debug("Starting to report metrics");
            try
            {
                // Every 5 seconds (or superseding interval) we connect to graphite
                // and poll the hardware. It may be inefficient to open a new connection
                // every 5 seconds, and there are ways to optimize this, but opening a
                // new connection is the easiest way to ensure that previous failures
                // don't affect future results
                var stopwatch = Stopwatch.StartNew();
                var sensors   = _collector.ReadAllSensors().ToList();
                await _writer.ReportMetrics(e.SignalTime, sensors);

                Logger.Info($"Sent {sensors.Count} metrics in {stopwatch.Elapsed.TotalMilliseconds}ms");
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to send metrics");
            }
        }