Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Author: Mike Adolphs, 2009 |
| 4 | # Blog: http://www.matejunkie.com/ |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; version 2 of the License only! |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU General Public License |
| 16 | # along with this program; if not, write to the Free Software |
| 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | import sys |
| 20 | import urllib |
| 21 | |
| 22 | def retrieve_status_page(): |
| 23 | statusPage = "http://localhost/server-status?auto" |
| 24 | try: |
| 25 | retrPage = urllib.urlretrieve(statusPage, '/tmp/server-status.log') |
| 26 | return True |
| 27 | except: |
| 28 | return False |
| 29 | |
| 30 | def parse_status_page(): |
| 31 | """Main parsing function to put the server-status file's content into |
| 32 | a dictionary.""" |
| 33 | |
| 34 | file = open('/tmp/server-status.log', 'r') |
| 35 | line = file.readline() |
| 36 | dictStatus = {} |
| 37 | counter = 1 |
| 38 | |
| 39 | while line: |
| 40 | line = line.strip() |
| 41 | if "Total Accesses:" in line: |
| 42 | key = "total.accesses" |
| 43 | val = {'val':int(line.strip("Total Accesses:")), 'unit':'accesses', 'metric_type':'gauge'} |
| 44 | elif "Total kBytes:" in line: |
| 45 | key = "total.kBytes" |
| 46 | val = {'val':float(line.strip("Total kBytes:")), 'unit':'kBytes', 'metric_type':'gauge'} |
| 47 | elif "Uptime:" in line: |
| 48 | key = "uptime" |
| 49 | val = {'val':int(line.strip("Uptime:")), 'unit':'seconds', 'metric_type':'gauge'} |
| 50 | elif "ReqPerSec:" in line: |
| 51 | key = "reqpersec" |
| 52 | val = {'val':float(line.strip("ReqPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 53 | elif "BytesPerSec:" in line: |
| 54 | key = "bytespersec" |
| 55 | val = {'val':float(line.strip("BytesPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 56 | elif "BytesPerReq:" in line: |
| 57 | key = "bytesperreq" |
| 58 | val = {'val':float(line.strip("BytesPerReq:")), 'unit':'rate', 'metric_type':'gauge'} |
| 59 | elif "BusyWorkers:" in line: |
| 60 | key = "busyworkers" |
| 61 | val = {'val':int(line.strip("BusyWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
| 62 | elif "IdleWorkers:" in line: |
| 63 | key = "idleworkers" |
| 64 | val = {'val':int(line.strip("IdleWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
| 65 | |
| 66 | dictStatus[key] = val |
| 67 | counter = counter + 1 |
| 68 | line = file.readline() |
| 69 | |
| 70 | return dictStatus |
| 71 | |