Skip to content

Commit 4d11282

Browse files
committed
samples: monitoring: add Application Monitor sample
Signed-off-by: David Escalona <david.escalona@digi.com>
1 parent 7197c18 commit 4d11282

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Application Monitor Sample Application
2+
======================================
3+
4+
This sample Python application shows how to use the application monitor daemon
5+
API.
6+
7+
The sample registers the application in the application monitor daemon and
8+
starts refreshing it. After 5 loops, the application stops refreshing and waits
9+
to be killed by the application monitor daemon.
10+
11+
Requirements
12+
------------
13+
To run this example you will need:
14+
15+
* An XBee Gateway device.
16+
17+
Setup
18+
-----
19+
No special setup is required.
20+
21+
Run
22+
---
23+
1. The example is already configured, so all you need to do is to build and run
24+
the project in the XBee Gateway.
25+
26+
2. Upon start, the application registers to the application monitor daemon and
27+
starts refreshing it.
28+
29+
3. After 5 refresh loops, the application stops refreshing and waits to be
30+
killed by the application monitor daemon.
31+
32+
Supported platforms
33+
-------------------
34+
* IX15
35+
36+
License
37+
-------
38+
Copyright (c) 2022, Digi International, Inc.
39+
40+
Permission is hereby granted, free of charge, to any person obtaining a copy
41+
of this software and associated documentation files (the "Software"), to deal
42+
in the Software without restriction, including without limitation the rights
43+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44+
copies of the Software, and to permit persons to whom the Software is
45+
furnished to do so, subject to the following conditions:
46+
47+
The above copyright notice and this permission notice shall be included in all
48+
copies or substantial portions of the Software.
49+
50+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56+
SOFTWARE.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2022, Digi International Inc.
2+
#
3+
# Permission to use, copy, modify, and/or distribute this software for any
4+
# purpose with or without fee is hereby granted, provided that the above
5+
# copyright notice and this permission notice appear in all copies.
6+
#
7+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
15+
from digidevice import appmonitor
16+
from digidevice.appmonitor import AppMonitorAction, AppMonitorError
17+
18+
import sys
19+
import time
20+
21+
APP_TIMEOUT = 5000
22+
23+
24+
def main():
25+
print(" +----------------------------+")
26+
print(" | Application Monitor Sample |")
27+
print(" +----------------------------+\n")
28+
29+
try:
30+
print("Registering application...")
31+
mon_handle = appmonitor.register_app(APP_TIMEOUT, AppMonitorAction.KILL)
32+
print("Registration succeed:\n - Timeout: %s\n - Action: %s\n "
33+
"- Restart command: '%s'\n" % (mon_handle.timeout, mon_handle.action.name,
34+
mon_handle.restart_command))
35+
for loop in range(1, 6):
36+
print("Refreshing application... %s" % loop)
37+
mon_handle.refresh()
38+
time.sleep(0.5 * APP_TIMEOUT / 1000)
39+
print("\nStopped refreshing! Application should be killed in a while...")
40+
time.sleep(sys.maxsize)
41+
except AppMonitorError as exc:
42+
print(str(exc))
43+
sys.exit(1)
44+
45+
46+
if __name__ == '__main__':
47+
main()

0 commit comments

Comments
 (0)