blob: 9600e33dd86c84f2f892e98fa03720898118ed7e [file] [log] [blame]
Matteo Scandolo35113f72017-08-08 13:05:25 -07001
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 Vavilapallib9bcda72017-01-19 18:25:39 +000017#!/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
35import sys
36import urllib
37
38def 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
46def 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 Vavilapalli974c9ce2017-01-25 01:50:27 +000058 key = "exampleservice.apache.total.accesses"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000059 val = {'val':int(line.strip("Total Accesses:")), 'unit':'accesses', 'metric_type':'gauge'}
60 elif "Total kBytes:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000061 key = "exampleservice.apache.total.kBytes"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000062 val = {'val':float(line.strip("Total kBytes:")), 'unit':'kBytes', 'metric_type':'gauge'}
63 elif "Uptime:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000064 key = "exampleservice.apache.uptime"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000065 val = {'val':int(line.strip("Uptime:")), 'unit':'seconds', 'metric_type':'gauge'}
66 elif "ReqPerSec:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000067 key = "exampleservice.apache.reqpersec"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000068 val = {'val':float(line.strip("ReqPerSec:")), 'unit':'rate', 'metric_type':'gauge'}
69 elif "BytesPerSec:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000070 key = "exampleservice.apache.bytespersec"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000071 val = {'val':float(line.strip("BytesPerSec:")), 'unit':'rate', 'metric_type':'gauge'}
72 elif "BytesPerReq:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000073 key = "exampleservice.apache.bytesperreq"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000074 val = {'val':float(line.strip("BytesPerReq:")), 'unit':'rate', 'metric_type':'gauge'}
75 elif "BusyWorkers:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000076 key = "exampleservice.apache.busyworkers"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000077 val = {'val':int(line.strip("BusyWorkers:")), 'unit':'workers', 'metric_type':'gauge'}
78 elif "IdleWorkers:" in line:
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000079 key = "exampleservice.apache.idleworkers"
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000080 val = {'val':int(line.strip("IdleWorkers:")), 'unit':'workers', 'metric_type':'gauge'}
Srikanth Vavilapalli974c9ce2017-01-25 01:50:27 +000081
Srikanth Vavilapallib9bcda72017-01-19 18:25:39 +000082 dictStatus[key] = val
83 counter = counter + 1
84 line = file.readline()
85
86 return dictStatus
87