-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Adding a new plugin for raising alarms if disk usage crosses a…
… threshold"
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- mode: python; -*- | ||
|
||
# | ||
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. | ||
# | ||
|
||
import sys | ||
Import('OpEnv') | ||
|
||
env = OpEnv.Clone() | ||
|
||
setup_sources = [ | ||
'setup.py', | ||
] | ||
|
||
setup_sources_rules = [] | ||
for file in setup_sources: | ||
setup_sources_rules.append(env.Install(".", | ||
"#/controller/src/opserver/plugins/alarm_disk_usage/" + file)) | ||
|
||
local_sources = [ | ||
'__init__.py', | ||
'main.py', | ||
] | ||
local_sources_rules = [] | ||
for file in local_sources: | ||
local_sources_rules.append(env.Install(Dir("alarm_disk_usage"), file)) | ||
|
||
sdist_depends = [setup_sources_rules, local_sources_rules] | ||
cd_cmd = 'cd ' + Dir('.').path + ' && ' | ||
sdist_gen = env.Command('dist/alarm_disk_usage-0.1dev.tar.gz', 'setup.py', | ||
cd_cmd + 'python setup.py sdist') | ||
env.Depends(sdist_gen, sdist_depends) | ||
env.Default(sdist_gen) | ||
OpEnv['ALARM_DISK_USAGE_PKG'] = sdist_gen | ||
|
||
if 'install' in BUILD_TARGETS: | ||
install_cmd = env.Command(None, | ||
'setup.py', | ||
cd_cmd + 'python setup.py install %s' % | ||
env['PYTHON_INSTALL_OPT']) | ||
env.Depends(install_cmd, sdist_depends) | ||
env.Alias('install', install_cmd) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from opserver.plugins.alarm_base import * | ||
from opserver.sandesh.alarmgen_ctrl.sandesh_alarm_base.ttypes import * | ||
import json | ||
|
||
class DiskUsage(AlarmBase): | ||
"""Disk Usage crosses a threshold. | ||
NodeMgr reports disk usage in DatabaseUsageInfo.database_usage""" | ||
|
||
def __init__(self): | ||
AlarmBase.__init__(self, AlarmBase.SYS_ERR) | ||
self._threshold = 0.90 | ||
|
||
def __call__(self, uve_key, uve_data): | ||
or_list = [] | ||
db_usage_info = uve_data.get("DatabaseUsageInfo", None) | ||
if db_usage_info is None: | ||
return None | ||
db_usage_list = db_usage_info.get("database_usage", None) | ||
if db_usage_list is None: | ||
return None | ||
|
||
for db_usage in db_usage_list: | ||
used_space = db_usage["disk_space_used_1k"] | ||
available_space = db_usage["disk_space_available_1k"] | ||
use_space_threshold = available_space * self._threshold | ||
if used_space > use_space_threshold: | ||
or_list.append(AllOf(all_of=[AlarmElement(\ | ||
rule=AlarmTemplate(oper=">", | ||
operand1=Operand1(\ | ||
keys=["DatabaseUsageInfo","database_usage","disk_space_used_1k"]), | ||
operand2=Operand2(json_value=str(use_space_threshold))), | ||
json_operand1_value=str(used_space), | ||
json_vars={\ | ||
"DatabaseUsageInfo.database_usage.disk_space_used_1k":\ | ||
str(used_space), | ||
"DatabaseUsageInfo.database_usage.disk_space_available_1k":\ | ||
str(available_space)})])) | ||
if len(or_list): | ||
return or_list | ||
else: | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. | ||
# | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='alarm_disk_usage', | ||
version='0.1dev', | ||
packages=find_packages(), | ||
entry_points = { | ||
'contrail.analytics.alarms': [ | ||
'ObjectDatabaseInfo = alarm_disk_usage.main:DiskUsage', | ||
'ObjectVRouter = alarm_disk_usage.main:DiskUsage', | ||
'ObjectConfigNode = alarm_disk_usage.main:DiskUsage', | ||
'ObjectCollectorInfo = alarm_disk_usage.main:DiskUsage', | ||
'ObjectBgpRouter = alarm_disk_usage.main:DiskUsage', | ||
], | ||
}, | ||
zip_safe=False, | ||
long_description="DiskUsage Alarm" | ||
) |