[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xymon] hobbitgraph.cgi: Attempting to reuse 'mysqlht'



On Thu, Nov 25, 2010 at 17:59, Henrik StÃrner <henrik (at) hswn.dk> wrote:

> On Wed, 24 Nov 2010 16:12:07 +0200, Arie Skliarouk wrote:
>
> > I created a custom mysql parameters check that shows graphs on one
> > server, but not on the other. hobbitgraph.sh (hobbitgraph.cgi?) kept
> > sending following error instead of the actual image:
> > <html><head><title>Invalid request</title></head> <body>Attempting to
> > reuse 'mysqlht'</body></html>
>
> This is an error from the rrdtool library. So I would suspect something
> dodgy with the graph-definition in hobbit-graphs.cfg, or the RRD file
> data is not as you would expect.
>
> Could you show us the graph definition you use ?


See attached. Also attached all files you might require to recreate the
mysql sensor.

Note that the graph works for one machine, but not for the other.


> And the layout of the
> RRD-file - a command like
>
>        rrdtool info mysql.rrd |grep "type ="
>

Both files yield identical output:
ds[mysqlht].type = "GAUGE"
ds[mysqlhq].type = "GAUGE"
ds[mysqlhs].type = "GAUGE"

--
Arie

>
> should give us the necessary info about the datasets and their type.
>
> > If I request the same image for different server, same service - I get
> > the image. If I copy the mysql.rrd file from the
> > /var/lib/hobbit/rrd/atl-db01/mysql.rrd into the
> > /var/lib/hobbit/rrd/pa04, then the image for pa04 shows graph for the
> > atl-db01.
> >
> > Could be that dash in name of that particular server was affecting the
> > hobbitgraph.cgi somehow? I can attach the hobbitgraph.d/mysql.cfg and
> > hobbitserver.d/mysql.cfg if that would help.
>
> It shouldn't, and I know I have hostnames with dash'es in them. Haven't
> noticed any problems with graphs there, but I'll have a look.
>
>
> Regards,
> Henrik
>
> To unsubscribe from the xymon list, send an e-mail to
> xymon-unsubscribe (at) xymon.com
>
>
>
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Report to hobbit run-time parameters of local mysql installation.
# Designed to be located in /usr/lib/hobbit/client/ext directory and invoked by hobbitd
#
# Author: Arie Skliarouk <skliarie (at) gmail.com>
#

# First, create a dumb user that can do status and show variables :
# grant select on devnull.* to monitoring (at) localhost identified by 'monitoring';
# revoke all on devnull.* from monitoring (at) localhost;

# TBD:
# or use the config file $BBHOME/etc/bb-mysql.cfg to set for example :
# user=thisuser
# passwd=thatpassword
# socket=othersocket

import datetime,os,sys
# not supported by python2.5
#from subprocess import Popen, PIPE, STDOUT
import subprocess
import string,re
#import MySQLdb
#import MySQLdb.cursors

testname = "mysql"

def Execute(CommandAndArgs):
  #CommandAndArgs=[BB,BBDISP,"-"]

  DebugStr="[".join(CommandAndArgs)+"]"

  if "BB" in os.environ:
    #stdout=subprocess.Popen(CommandAndArgs,stdin=subprocess.PIPE).stdin
    #stdout.write(DATA)
    subprocess.Popen(CommandAndArgs)

    # Debugging
    #open("/tmp/bb-latency.log","a+").write("{"+DebugStr+"}\n")

  else:
    print DebugStr

"""
my $BBHOME      = $ENV{BBHOME};
my $BB          = $ENV{BB};       # full path to the bin/bb util
my $BBDISP      = $ENV{BBDISP};   # IP of the BBDISPLAY server
my $BBVAR       = $ENV{BBVAR};
my $MACHINE     = $ENV{MACHINE};  # hostname, fqdn
my $COLOR       = "clear";        # global color for the test
my $MSG         = "";             # body of the message
my $HEAD        = "";             # first line of the message (short, optional)
my $DATA        = "";             # data for NCV records (hobbit only)
"""
GREEN='green'
YELLOW='yellow'
RED='red'

### Main Program
# Get status from the running mysql server
#db=MySQLdb.connect(host="localhost",user="monitoring",passwd="monitoring",charset ="utf8", use_unicode = True)
#c = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)

mysql_auth="-umonitoring -pmonitoring";
mysql_client="/usr/bin/mysql";
cmd=mysql_client+" "+mysql_auth+" -Bs"
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
p.stdin.write("select 'DATE', now() ; status; show variables;")
p.stdin.close()
output = p.stdout.read()

# Extract "Slow queries: 0"
slow_queries_pattern=re.compile(r'Slow queries: (\d+) ', re.IGNORECASE)
slow_queries_now=int(slow_queries_pattern.findall(output)[0])

# Slow queries is accumulating value, so we need to report increase of these.
slow_queries=0
# Keep the previous value in /tmp/bb-mysql.dat
slow_queries_file="/tmp/bb-mysql.dat"
if (os.path.exists(slow_queries_file)):
  slow_queries_before=int(open(slow_queries_file,"r").read())
  slow_queries=slow_queries_now-slow_queries_before

open(slow_queries_file,"w").write(str(slow_queries_now))

# Extract "Threads: 1"
threads_pattern=re.compile(r'Threads: (\d+) ', re.IGNORECASE)
threads=threads_pattern.findall(output)[0]

# Extract "Queries per second avg: 0.0"
qps_pattern=re.compile(r'Queries per second avg: (\d+)', re.IGNORECASE)
qps=qps_pattern.findall(output)[0]

#print slow_queries

#c.execute("select now()")
#results=c.fetchall()
#mysql_timestamp=results[0]
#print "Server reports timestamp of [%s]" % mysql_timestamp

#c.execute("status")
#results=c.fetchall()
#; status; show variables"

results={"mysqlhq":qps, "mysqlhs":slow_queries, "mysqlht":threads}

#results_handle=open("/tmp/latency_test.data","r")
#for line in results_handle.readlines():
#  (key,secs)=line.split(":")
#  results[key]=int(string.atof(secs))

# Always successful
color=GREEN

# Send to Hobbit

#Tue May 25 15:36:13 IDT 2010
report_date=datetime.datetime.utcnow().strftime("%a %b %e %T UTC %Y")

if "MACHINE" in os.environ:
  Machine=os.environ["MACHINE"]
else:
  Machine="ENV{MACHINE}"

if "BB" in os.environ:
  BB=os.environ["BB"]
else:
  BB="ENV{BB}"

if "BBDISP" in os.environ:
  BBDISP=os.environ["BBDISP"]
else:
  BBDISP="ENV{BBDISP}"

DATA_values=""
TEXT_values=""
separator=""
for result in results.keys():
  bbtest = result
  status = bbtest + " OK"

  # Notify each measured value
  DATA="status "+Machine+"."+result+" "+color+" "+report_date+" - "+result+" OK\n\n"+result+"="+str(results[result])+"\n"

  CommandAndArgs=[BB,BBDISP,DATA]
  #Execute(CommandAndArgs)

  TEXT_values+=separator+result+"="+str(results[result])
  separator="\n"

# Notify all values (as a text)
DATA="status "+Machine+"."+testname+" "+color+" "+report_date+" - "+testname+" OK\n\n"+TEXT_values+"\n"

CommandAndArgs=[BB,BBDISP,DATA]
Execute(CommandAndArgs)


#open("/tmp/bb-latency.log","a+").write(report_date+": report done\n")