You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by mr...@apache.org on 2009/04/09 21:41:29 UTC
svn commit: r763821 - in /incubator/tashi/trunk: etc/TashiDefaults.cfg
src/tashi/__init__.py src/tashi/ganglialoghandler.py
Author: mryan3
Date: Thu Apr 9 21:41:29 2009
New Revision: 763821
URL: http://svn.apache.org/viewvc?rev=763821&view=rev
Log:
This adds the ganglia log handler. This handler converts log messages into ganglia metrics.
Added:
incubator/tashi/trunk/src/tashi/ganglialoghandler.py
Modified:
incubator/tashi/trunk/etc/TashiDefaults.cfg
incubator/tashi/trunk/src/tashi/__init__.py
Modified: incubator/tashi/trunk/etc/TashiDefaults.cfg
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/etc/TashiDefaults.cfg?rev=763821&r1=763820&r2=763821&view=diff
==============================================================================
--- incubator/tashi/trunk/etc/TashiDefaults.cfg (original)
+++ incubator/tashi/trunk/etc/TashiDefaults.cfg Thu Apr 9 21:41:29 2009
@@ -105,10 +105,12 @@
reverseDns = True
# Logging stuff
+# Switch the "keys" and "handlers" variables below to output log data to ganglia metrics
[loggers]
keys = root
[handlers]
+#keys = consoleHandler,gangliaHandler
keys = consoleHandler
[formatters]
@@ -116,6 +118,7 @@
[logger_root]
level = DEBUG
+#handlers = consoleHandler,gangliaHandler
handlers = consoleHandler
propagate = 1
@@ -125,6 +128,12 @@
formatter = standardFormatter
args = (sys.stdout,)
+[handler_gangliaHandler]
+class = tashi.GangliaLogHandler
+level = NOTSET
+formatter = standardFormatter
+args = (60, 2, 'default')
+
[formatter_standardFormatter]
format=%(asctime)s [%(name)s:%(levelname)s] %(message)s
datefmt=
Modified: incubator/tashi/trunk/src/tashi/__init__.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/__init__.py?rev=763821&r1=763820&r2=763821&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/__init__.py (original)
+++ incubator/tashi/trunk/src/tashi/__init__.py Thu Apr 9 21:41:29 2009
@@ -18,3 +18,4 @@
from util import *
from connectionmanager import ConnectionManager
from version import version
+from ganglialoghandler import GangliaLogHandler
Added: incubator/tashi/trunk/src/tashi/ganglialoghandler.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/ganglialoghandler.py?rev=763821&view=auto
==============================================================================
--- incubator/tashi/trunk/src/tashi/ganglialoghandler.py (added)
+++ incubator/tashi/trunk/src/tashi/ganglialoghandler.py Thu Apr 9 21:41:29 2009
@@ -0,0 +1,66 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+import os.path
+import sys
+import time
+
+import tashi
+
+logging.tashi = tashi
+
+class GangliaLogHandler(logging.Handler):
+ def __init__(self, windowSize, windows, interface):
+ logging.Handler.__init__(self)
+ self.msgIndex = 0
+ self.windowIndex = 0
+ self.lastRollover = time.time()
+ self.name = os.path.basename(sys.argv[0])
+ self.windowSize = windowSize
+ self.windows = windows
+ self.interface = interface.lower()
+ self.disable = False
+
+ def emit(self, record):
+ if (self.disable):
+ return
+ try:
+ now = time.time()
+ msg = self.format(record)
+ if (now > self.lastRollover + self.windowSize):
+ self.lastRollover = now
+ self.msgIndex = 0
+ self.windowIndex = self.windowIndex + 1
+ if (self.windowIndex >= self.windows):
+ self.windowIndex = 0
+ metricName = "tashi_log_%s_%d_%d" % (self.name, self.windowIndex, self.msgIndex)
+ metricValue = msg.replace("'", '"')
+ metricType = "string"
+ if (self.interface == "default"):
+ (stdin, stdout) = os.popen4("gmetric -n '%s' -v '%s' -t '%s'" % (metricName, metricValue, metricType))
+ else:
+ (stdin, stdout) = os.popen4("gmetric -n '%s' -v '%s' -t '%s' -i '%s'" % (metricName, metricValue, metricType, self.interface))
+ stdin.close()
+ res = stdout.read()
+ if (res != ""):
+ print "Failed to exec gmetric, disabling: %s" % (res)
+ self.disable = True
+ stdout.close()
+ self.msgIndex = self.msgIndex + 1
+ except Exception, e:
+ print e