I have a server application on my own server that depends on remote MySQL db running on another server maintained by a third party. How do I monitor when their bd works and when not? I would like my already deployed Prometheus to scrape it but I can't install exporter on their machine. Is there some kind of mysql pinger for Prometheus or something? If not maybe there is another approach?
Asked
Active
Viewed 143 times
1 Answers
2
A simple script to bind to the database works for me when I need to monitor remote MySQL instances. I prefer Python because it integrates well with my monitoring system, but any script that binds to the database and executes a simple query will do. I like to use SELECT NOW()
, but it might be helpful to actually run a query against your data set.
Here's a rough example of a script I'd use to make sure that a remote server is up:
#!/usr/bin/python
import MySQLdb as mdb
import sys
try:
con = mdb.connect('Your Remote Host', 'DB User', 'DB Password', 'DB Name');
cur = con.cursor()
cur.execute("SELECT NOW()")
ts= cur.fetchone()
## Query was successful
print "Today's date : %s " % ts
except mdb.Error, e:
## Something failed, add logic to catch errors here
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()

Nate
- 36
- 3