Skip to content

Commit

Permalink
fixed #5 - class element not always present
Browse files Browse the repository at this point in the history
  • Loading branch information
lampwins committed Dec 11, 2017
1 parent 4b2fb76 commit 2a3665b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

logger = logging.getLogger(__name__)

config = None


class Metrics(object):
"""
Expand Down Expand Up @@ -235,8 +237,12 @@ def get_environment_metrics(registry, dev):

status = 1.0 if env_item.find('status').text.strip() == 'OK' else 0.0
name = env_item.find('name').text.strip()
_class = env_item.find('class').text.strip()
registry.add_metric('environmentItem', status, {'name': name, 'class': _class})
_class = env_item.find('class')
if _class is not None:
_class = _class.text.strip()
registry.add_metric('environmentItem', status, {'name': name, 'class': _class})
else:
registry.add_metric('environmentItem', status, {'name': name})


def get_virtual_chassis_metrics(registry, dev):
Expand Down Expand Up @@ -544,7 +550,7 @@ def get_bgp_metrics(registry, dev):

def metrics(environ, start_response):

# load config file
# load config
with open('junos_exporter.yaml', 'r') as f:
config = yaml.load(f)

Expand Down
17 changes: 17 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
restart: always
image: nginx
volumes:
- ./server/conf.d:/etc/nginx/conf.d
links:
- web:web
ports:
- "9665:80"

web:
build: ./app
volumes:
- ./junos_exporter.yaml:/junos_exporter.yaml
expose:
- "8000"
command: gunicorn app:app -b :8000 --name app --log-level=debug --log-file=- -w 12 --max-requests 10 -k eventlet
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ web:
- /home/prometheus/.ssh/junos_exporter/id_rsa:/ssh_private_key_file
expose:
- "8000"
command: gunicorn app:app -b :8000 --name app --log-level=debug --log-file=- -w 12 --max-requests 10 -k eventlet
command: gunicorn app:app -b :8000 --name app --log-level=info --log-file=- -w 12 --max-requests 10 -k eventlet

0 comments on commit 2a3665b

Please sign in to comment.