hubitat2prom/Controllers/HubitatController.cs
/// <summary>
/// Get the Prometheus exporter values for devices configured on the Hubitat hub.
/// </summary>
/// <returns>
/// A valid response looks something like this:
/// <example>
/// switch{device_name="bathroom"} 0.0
/// level{device_name="living_room"} 1.0
/// </example>
/// </returns>
Get the Prometheus exporter values for devices configured on the Hubitat hub.
Get the Prometheus exporter values for devices configured on the Hubitat hub .
[HttpGet]
    [Route("/metrics")]
    public async Task<ContentResult> GetMetrics()
    {
        var deviceDetails = await _hubitat.DeviceDetails();
        var responseContent = new StringBuilder();
        var deviceAttributes = HubitatDeviceMetrics.Export(deviceDetails, HubitatEnv.Instance.HE_METRICS);
        foreach (var deviceAttribute in deviceAttributes)
        {
            responseContent.AppendLine(deviceAttribute.ToString());
        }
        return new ContentResult
        {
            Content = responseContent.ToString()
        };
    }
[ HttpGet ] [ Route ( " " ) ] public async Task < ContentResult > GetMetrics ( ) { var deviceDetails = await _hubitat . DeviceDetails ( ) ; var responseContent = new StringBuilder ( ) ; var deviceAttributes = HubitatDeviceMetrics . Export ( deviceDetails , HubitatEnv . Instance . HE_METRICS ) ; foreach ( var deviceAttribute in deviceAttributes ) { responseContent . AppendLine ( deviceAttribute . ToString ( ) ) ; } return new ContentResult { Content = responseContent . ToString ( ) } ; }
Get the Prometheus exporter values for devices configured on the Hubitat hub.
Get the Prometheus exporter values for devices configured on the Hubitat hub .
A valid response looks something like this.


A valid response looks something like this .