Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        private async void ReportMetrics(object sender, ElapsedEventArgs e)
        {
            Logger.Debug("Starting to report metrics");
            try
            {
                // Every 5 seconds (or superceding 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");
            }
        }