Added attributes to the statsd data (#2440)
* Added attributes to the statsd data * Updated to allow optional attribute logging
This commit is contained in:
1 parent
31b8e49ad2
commit
ff5c3c9f98
2 files changed
+68
-5
No files matched your search
@@ -26,6 +26,7 @@ CONF_HOST = 'host'
|
||||
CONF_PORT = 'port'
|
||||
CONF_PREFIX = 'prefix'
|
||||
CONF_RATE = 'rate'
|
||||
CONF_ATTR = 'log_attributes'
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
@@ -38,6 +39,7 @@ def setup(hass, config):
|
||||
port = util.convert(conf.get(CONF_PORT), int, DEFAULT_PORT)
|
||||
sample_rate = util.convert(conf.get(CONF_RATE), int, DEFAULT_RATE)
|
||||
prefix = util.convert(conf.get(CONF_PREFIX), str, DEFAULT_PREFIX)
|
||||
show_attribute_flag = conf.get(CONF_ATTR, False)
|
||||
|
||||
statsd_client = statsd.StatsClient(
|
||||
host=host,
|
||||
@@ -57,8 +59,25 @@ def setup(hass, config):
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
states = dict(state.attributes)
|
||||
|
||||
_LOGGER.debug('Sending %s.%s', state.entity_id, _state)
|
||||
statsd_client.gauge(state.entity_id, _state, sample_rate)
|
||||
|
||||
if show_attribute_flag is True:
|
||||
statsd_client.gauge(
|
||||
"%s.state" % state.entity_id,
|
||||
_state,
|
||||
sample_rate
|
||||
)
|
||||
|
||||
# Send attribute values
|
||||
for key, value in states.items():
|
||||
if isinstance(value, (float, int)):
|
||||
stat = "%s.%s" % (state.entity_id, key.replace(' ', '_'))
|
||||
statsd_client.gauge(stat, value, sample_rate)
|
||||
|
||||
else:
|
||||
statsd_client.gauge(state.entity_id, _state, sample_rate)
|
||||
|
||||
# Increment the count
|
||||
statsd_client.incr(state.entity_id, rate=sample_rate)
|
||||
|
||||
Reference in new issue
Block a user