I did my best to log metrics directly into carbon through SocketHandler with no luck:
logger.conf
:
[loggers]
keys=root,carbon
[handlers]
keys=carbonHandler
[formatters]
keys=carbonFormatter
[logger_carbon]
level=DEBUG
handlers=carbonHandler
qualname=carbon
propagate=0
[logger_root]
level=DEBUG
handlers=carbonHandler
[handler_carbonHandler]
class=logging.handlers.SocketHandler
level=DEBUG
formatter=carbonFormatter
args=('$HOST', 2003)
[formatter_carbonFormatter]
format=%(message)s %(created)i
And then, tying to log with it:
import logging
import logging.config
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('carbon')
logger.info('test.开发者_如何学Pythonpython 42')
And this is a sad fail...
I can talk to carbon using echo "test.metric 42 $(date +'%s')" | nc $HOST 2003
Do you see anything?
Do I try to do something that won't ever work?
Thanks for any help!
Assuming your config file is exactly as is - replace "$HOST" in your config file with the actual name of the host. What happens then? If that works and you need the name to be environment-dependent, try using
args=(os.environ['HOST'], 2003)
in the config file.
精彩评论