Matteo Scandolo | 35113f7 | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 17 | #!/usr/bin/env python |
| 18 | |
| 19 | # Author: Mike Adolphs, 2009 |
| 20 | # Blog: http://www.matejunkie.com/ |
| 21 | # |
| 22 | # This program is free software; you can redistribute it and/or modify |
| 23 | # it under the terms of the GNU General Public License as published by |
| 24 | # the Free Software Foundation; version 2 of the License only! |
| 25 | # |
| 26 | # This program is distributed in the hope that it will be useful, |
| 27 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 | # GNU General Public License for more details. |
| 30 | # |
| 31 | # You should have received a copy of the GNU General Public License |
| 32 | # along with this program; if not, write to the Free Software |
| 33 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 34 | |
| 35 | import sys |
| 36 | import urllib |
| 37 | |
| 38 | def retrieve_status_page(): |
| 39 | statusPage = "http://localhost/server-status?auto" |
| 40 | try: |
| 41 | retrPage = urllib.urlretrieve(statusPage, '/tmp/server-status.log') |
| 42 | return True |
| 43 | except: |
| 44 | return False |
| 45 | |
| 46 | def parse_status_page(): |
| 47 | """Main parsing function to put the server-status file's content into |
| 48 | a dictionary.""" |
| 49 | |
| 50 | file = open('/tmp/server-status.log', 'r') |
| 51 | line = file.readline() |
| 52 | dictStatus = {} |
| 53 | counter = 1 |
| 54 | |
| 55 | while line: |
| 56 | line = line.strip() |
| 57 | if "Total Accesses:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 58 | key = "exampleservice.apache.total.accesses" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 59 | val = {'val':int(line.strip("Total Accesses:")), 'unit':'accesses', 'metric_type':'gauge'} |
| 60 | elif "Total kBytes:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 61 | key = "exampleservice.apache.total.kBytes" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 62 | val = {'val':float(line.strip("Total kBytes:")), 'unit':'kBytes', 'metric_type':'gauge'} |
| 63 | elif "Uptime:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 64 | key = "exampleservice.apache.uptime" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 65 | val = {'val':int(line.strip("Uptime:")), 'unit':'seconds', 'metric_type':'gauge'} |
| 66 | elif "ReqPerSec:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 67 | key = "exampleservice.apache.reqpersec" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 68 | val = {'val':float(line.strip("ReqPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 69 | elif "BytesPerSec:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 70 | key = "exampleservice.apache.bytespersec" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 71 | val = {'val':float(line.strip("BytesPerSec:")), 'unit':'rate', 'metric_type':'gauge'} |
| 72 | elif "BytesPerReq:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 73 | key = "exampleservice.apache.bytesperreq" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 74 | val = {'val':float(line.strip("BytesPerReq:")), 'unit':'rate', 'metric_type':'gauge'} |
| 75 | elif "BusyWorkers:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 76 | key = "exampleservice.apache.busyworkers" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 77 | val = {'val':int(line.strip("BusyWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
| 78 | elif "IdleWorkers:" in line: |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 79 | key = "exampleservice.apache.idleworkers" |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 80 | val = {'val':int(line.strip("IdleWorkers:")), 'unit':'workers', 'metric_type':'gauge'} |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 81 | |
Srikanth Vavilapalli | b9bcda7 | 2017-01-19 18:25:39 +0000 | [diff] [blame] | 82 | dictStatus[key] = val |
| 83 | counter = counter + 1 |
| 84 | line = file.readline() |
| 85 | |
| 86 | return dictStatus |
| 87 | |