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: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 42 | key = "exampleservice.apache.total.accesses" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 43 | val = {'val':int(line.strip("Total Accesses:")), 'unit':'accesses', 'metric_type':'gauge'} |
| 44 | elif "Total kBytes:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 45 | key = "exampleservice.apache.total.kBytes" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 46 | val = {'val':float(line.strip("Total kBytes:")), 'unit':'kBytes', 'metric_type':'gauge'} |
| 47 | elif "Uptime:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 48 | key = "exampleservice.apache.uptime" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 49 | val = {'val':int(line.strip("Uptime:")), 'unit':'seconds', 'metric_type':'gauge'} |
| 50 | elif "ReqPerSec:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 51 | key = "exampleservice.apache.reqpersec" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 52 | val = {'val':float(line.strip("ReqPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 53 | elif "BytesPerSec:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 54 | key = "exampleservice.apache.bytespersec" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 55 | val = {'val':float(line.strip("BytesPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 56 | elif "BytesPerReq:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 57 | key = "exampleservice.apache.bytesperreq" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 58 | val = {'val':float(line.strip("BytesPerReq:")), 'unit':'rate', 'metric_type':'gauge'} |
| 59 | elif "BusyWorkers:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 60 | key = "exampleservice.apache.busyworkers" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 61 | val = {'val':int(line.strip("BusyWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
| 62 | elif "IdleWorkers:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 63 | key = "exampleservice.apache.idleworkers" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 64 | val = {'val':int(line.strip("IdleWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame^] | 65 | |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 66 | dictStatus[key] = val |
| 67 | counter = counter + 1 |
| 68 | line = file.readline() |
| 69 | |
| 70 | return dictStatus |
| 71 | |