mirror of
https://github.com/weewx/weewx.git
synced 2026-05-24 17:55:15 -04:00
Update pmon.
This commit is contained in:
10
TODO.md
10
TODO.md
@@ -39,11 +39,11 @@ Put legacy (V4.x) docs at weewx.com/legacy_docs.
|
||||
Update the examples:
|
||||
|
||||
- ~~basic~~
|
||||
- colorize_1
|
||||
- colorize_2
|
||||
- colorize_3
|
||||
- fileparse
|
||||
- pmon
|
||||
- ~~colorize_1~~
|
||||
- ~~colorize_2~~
|
||||
- ~~colorize_3~~
|
||||
- ~~fileparse~~
|
||||
- pmon <--- needs separate schema.
|
||||
- xstats
|
||||
- alarm.py
|
||||
- lowBattery.py
|
||||
|
||||
@@ -7,7 +7,7 @@ This example illustrates how to implement a skin and package it so that it can b
|
||||
extension installer. It also illustrates how to internationalize a skin.
|
||||
|
||||
|
||||
Installation instructions
|
||||
Installation instructions using the installer (recommended)
|
||||
-------------------------
|
||||
|
||||
1) install the extension.
|
||||
|
||||
@@ -8,8 +8,8 @@ can be installed by the extension installer. The fileparse driver reads data
|
||||
from a file of name=value pairs.
|
||||
|
||||
|
||||
Installation instructions (recommended)
|
||||
-------------------------
|
||||
Installation instructions using the installer (recommended)
|
||||
-----------------------------------------------------------
|
||||
|
||||
1) Install the extension.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2013 Matthew Wall
|
||||
# Copyright 2013-2013 Matthew Wall
|
||||
"""weewx module that records process information.
|
||||
|
||||
Installation
|
||||
@@ -16,7 +16,7 @@ Add the following to weewx.conf:
|
||||
[DataBindings]
|
||||
[[pmon_binding]]
|
||||
database = pmon_sqlite
|
||||
manager = weewx.manager.DaySummaryManager
|
||||
manager = weewx.manager.Manager
|
||||
table_name = archive
|
||||
schema = user.pmon.schema
|
||||
|
||||
@@ -30,9 +30,6 @@ Add the following to weewx.conf:
|
||||
archive_services = ..., user.pmon.ProcessMonitor
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@@ -41,10 +38,10 @@ from subprocess import Popen, PIPE
|
||||
|
||||
import weedb
|
||||
import weewx.manager
|
||||
import weeutil.weeutil
|
||||
from weeutil.weeutil import to_int
|
||||
from weewx.engine import StdService
|
||||
|
||||
VERSION = "0.6"
|
||||
VERSION = "0.7"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -62,12 +59,13 @@ class ProcessMonitor(StdService):
|
||||
def __init__(self, engine, config_dict):
|
||||
super(ProcessMonitor, self).__init__(engine, config_dict)
|
||||
|
||||
d = config_dict.get('ProcessMonitor', {})
|
||||
self.process = d.get('process', 'weewxd')
|
||||
self.max_age = weeutil.weeutil.to_int(d.get('max_age', 2592000))
|
||||
# To make what follows simpler, isolate the "pmon" part of the configuration file
|
||||
pmon_dict = config_dict.get('ProcessMonitor', {})
|
||||
self.process = pmon_dict.get('process', 'weewxd')
|
||||
self.max_age = to_int(pmon_dict.get('max_age', 2592000))
|
||||
|
||||
# get the database parameters we need to function
|
||||
binding = d.get('data_binding', 'pmon_binding')
|
||||
binding = pmon_dict.get('data_binding', 'pmon_binding')
|
||||
self.dbm = self.engine.db_binder.get_manager(data_binding=binding,
|
||||
initialize=True)
|
||||
|
||||
@@ -120,7 +118,7 @@ class ProcessMonitor(StdService):
|
||||
record = dict()
|
||||
record['dateTime'] = now_ts
|
||||
record['usUnits'] = weewx.METRIC
|
||||
record['interval'] = int((now_ts - last_ts) / 60)
|
||||
record['interval'] = int((now_ts - last_ts) / 60.0)
|
||||
try:
|
||||
cmd = 'ps aux'
|
||||
p = Popen(cmd, shell=True, stdout=PIPE)
|
||||
@@ -138,7 +136,7 @@ class ProcessMonitor(StdService):
|
||||
|
||||
# what follows is a basic unit test of this module. to run the test:
|
||||
#
|
||||
# cd /home/weewx
|
||||
# cd ~/weewx-data
|
||||
# PYTHONPATH=bin python bin/user/pmon.py
|
||||
#
|
||||
if __name__ == "__main__":
|
||||
@@ -183,18 +181,20 @@ if __name__ == "__main__":
|
||||
svc = ProcessMonitor(eng, config)
|
||||
|
||||
nowts = lastts = int(time.time())
|
||||
rec = svc.get_data(nowts, lastts)
|
||||
print(rec)
|
||||
|
||||
time.sleep(5)
|
||||
nowts = int(time.time())
|
||||
rec = svc.get_data(nowts, lastts)
|
||||
print(rec)
|
||||
|
||||
time.sleep(5)
|
||||
lastts = nowts
|
||||
nowts = int(time.time())
|
||||
rec = svc.get_data(nowts, lastts)
|
||||
print(rec)
|
||||
|
||||
os.remove('/var/tmp/pmon.sdb')
|
||||
loop = 0
|
||||
try:
|
||||
while True:
|
||||
rec = svc.get_data(nowts, lastts)
|
||||
print(rec)
|
||||
loop += 1
|
||||
if loop >= 3:
|
||||
break
|
||||
time.sleep(5)
|
||||
lastts = nowts
|
||||
nowts = int(time.time()+0.5)
|
||||
finally:
|
||||
try:
|
||||
os.remove('/var/tmp/pmon.sdb')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
0.7 22jan2023
|
||||
* Ported to WeeWX V5.0
|
||||
|
||||
0.6 17nov2019
|
||||
* ported to python 3
|
||||
* ported to weewx v4
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# installer for pmon
|
||||
# Copyright 2014 Matthew Wall
|
||||
# Copyright 2014-2023 Matthew Wall
|
||||
|
||||
from weecfg.extension import ExtensionInstaller
|
||||
|
||||
@@ -11,7 +11,7 @@ def loader():
|
||||
class ProcessMonitorInstaller(ExtensionInstaller):
|
||||
def __init__(self):
|
||||
super(ProcessMonitorInstaller, self).__init__(
|
||||
version="0.4",
|
||||
version="0.7",
|
||||
name='pmon',
|
||||
description='Collect and display process memory usage.',
|
||||
author="Matthew Wall",
|
||||
|
||||
105
bin/wee_resources/examples/pmon/readme.md
Normal file
105
bin/wee_resources/examples/pmon/readme.md
Normal file
@@ -0,0 +1,105 @@
|
||||
pmon - Process Monitor
|
||||
======================
|
||||
|
||||
Copyright 2014-2023 Matthew Wall
|
||||
|
||||
This example illustrates how to implement a service and package it so that it
|
||||
can be installed by the extension installer. The pmon service collects memory
|
||||
usage information about a single process then saves it in its own database.
|
||||
Data are then displayed using standard WeeWX reporting and plotting utilities.
|
||||
|
||||
|
||||
Installation instructions using the installer (recommended)
|
||||
-----------------------------------------------------------
|
||||
|
||||
1) Install the extension.
|
||||
|
||||
For pip installs:
|
||||
|
||||
weectl extension install ~/weewx-data/examples/pmon
|
||||
|
||||
For package installs
|
||||
|
||||
sudo weectl extension install /usr/share/doc/weewx/examples/pmon
|
||||
|
||||
|
||||
2Restart WeeWX
|
||||
|
||||
sudo systemctl restart weewx
|
||||
|
||||
|
||||
This will result in a skin called `pmon` with a single web page that illustrates
|
||||
how to use the monitoring data. See comments in pmon.py for customization
|
||||
options.
|
||||
|
||||
|
||||
Manual installation instructions
|
||||
--------------------------------
|
||||
|
||||
1) Copy the pmon service file to the WeeWX user directory.
|
||||
|
||||
For pip installs:
|
||||
|
||||
cd ~/weewx-data/examples/pmon
|
||||
cp bin/user/pmon.py ~/etc/weewx-data/bin/user
|
||||
|
||||
For package installs:
|
||||
|
||||
cd /usr/share/doc/weewx/examples/pmon
|
||||
sudo cp bin/user/pmon.py /usr/share/weewx/user
|
||||
|
||||
|
||||
2) Copy the pmon skin to the WeeWX skins directory.
|
||||
|
||||
For pip installs:
|
||||
|
||||
cd ~/weewx-data/examples/pmon
|
||||
cp skins/pmon ~/weewx-data/skins/
|
||||
|
||||
For package installs:
|
||||
|
||||
cd /usr/share/doc/weewx/examples/pmon
|
||||
sudo cp skins/pmon/ /etc/weewx/skins/
|
||||
|
||||
|
||||
3) In the WeeWX configuration file, add a new `[ProcessMonitor]` stanza
|
||||
|
||||
[ProcessMonitor]
|
||||
data_binding = pmon_binding
|
||||
process = weewxd
|
||||
|
||||
4) In the WeeWX configuration file, add a data binding
|
||||
|
||||
[DataBindings]
|
||||
...
|
||||
[[pmon_binding]]
|
||||
database = pmon_sqlite
|
||||
table_name = archive
|
||||
manager = weewx.manager.Manager
|
||||
schema = user.pmon.schema
|
||||
|
||||
5) In the WeeWX configuration file, add a database
|
||||
|
||||
[Databases]
|
||||
...
|
||||
[[pmon_sqlite]]
|
||||
database_name = pmon.sdb
|
||||
driver = weedb.sqlite
|
||||
|
||||
6) In the WeeWX configuration file, add a report
|
||||
|
||||
[StdReport]
|
||||
...
|
||||
[[pmon]]
|
||||
skin = pmon
|
||||
HTML_ROOT = pmon
|
||||
|
||||
7) In the WeeWX configuration file, add the pmon service
|
||||
|
||||
[Engine]
|
||||
[[Services]]
|
||||
process_services = ..., user.pmon.ProcessMonitor
|
||||
|
||||
8) Restart WeeWX
|
||||
|
||||
sudo systemctl restart weewx
|
||||
@@ -1,80 +0,0 @@
|
||||
pmon - Process Monitor
|
||||
Copyright 2014 Matthew Wall
|
||||
|
||||
This example illustrates how to implement a service and package it so that it
|
||||
can be installed by the extension installer. The pmon service collects memory
|
||||
usage information about a single process then saves it in its own database.
|
||||
Data are then displayed using standard WeeWX reporting and plotting utilities.
|
||||
|
||||
|
||||
Installation instructions
|
||||
|
||||
1) Install the extension
|
||||
|
||||
wee_extension --install=/home/weewx/examples/pmon
|
||||
|
||||
2) Restart WeeWX
|
||||
|
||||
sudo /etc/init.d/weewx stop
|
||||
sudo /etc/init.d/weewx start
|
||||
|
||||
|
||||
This will result in a skin called pmon with a single web page that illustrates
|
||||
how to use the monitoring data. See comments in pmon.py for customization
|
||||
options.
|
||||
|
||||
|
||||
Manual installation instructions
|
||||
|
||||
1) Copy the pmon service file to the WeeWX user directory. See https://bit.ly/33YHsqX for where
|
||||
your user directory is located. For example, if you used the setup.py install method:
|
||||
|
||||
cp /home/weewx/examples/pmon/bin/pmon.py /home/weewx/bin/user
|
||||
|
||||
2) Copy files to the WeeWX skins directory. See https://bit.ly/33YHsqX for where your skins
|
||||
directory is located. For example, if you used the setup.py install method:
|
||||
|
||||
cp -rp skins/pmon /home/weewx/skins
|
||||
|
||||
3) In the WeeWX configuration file, add a new [ProcessMonitor] stanza
|
||||
|
||||
[ProcessMonitor]
|
||||
data_binding = pmon_binding
|
||||
process = weewxd
|
||||
|
||||
4) In the WeeWX configuration file, add a data binding
|
||||
|
||||
[DataBindings]
|
||||
...
|
||||
[[pmon_binding]]
|
||||
database = pmon_sqlite
|
||||
table_name = archive
|
||||
manager = weewx.manager.DaySummaryManager
|
||||
schema = user.pmon.schema
|
||||
|
||||
5) In the WeeWX configuration file, add a database
|
||||
|
||||
[Databases]
|
||||
...
|
||||
[[pmon_sqlite]]
|
||||
database_name = pmon.sdb
|
||||
driver = weedb.sqlite
|
||||
|
||||
6) In the WeeWX configuration file, add a report
|
||||
|
||||
[StdReport]
|
||||
...
|
||||
[[pmon]]
|
||||
skin = pmon
|
||||
HTML_ROOT = pmon
|
||||
|
||||
7) In the WeeWX configuration file, add the pmon service
|
||||
|
||||
[Engine]
|
||||
[[Services]]
|
||||
process_services = ..., user.pmon.ProcessMonitor
|
||||
|
||||
8) Restart WeeWX
|
||||
|
||||
sudo /etc/init.d/weewx stop
|
||||
sudo /etc/init.d/weewx start
|
||||
@@ -311,10 +311,10 @@ def modify_config(config_dict, database_dict):
|
||||
# Very old versions of weedb used option 'root', instead of 'SQLITE_ROOT'
|
||||
sqlite_dir = db_dict.get('SQLITE_ROOT', db_dict.get('root', 'archive'))
|
||||
|
||||
db_path = os.path.join(config_dict['WEEWX_ROOT'],
|
||||
sqlite_dir,
|
||||
db_dict['database_name'])
|
||||
db_dict['db_path'] = db_path
|
||||
# If no WEEWX_ROOT, then it should have no influence. Use './'
|
||||
db_dict['db_path'] = os.path.normpath(os.path.join(config_dict.get('WEEWX_ROOT', './'),
|
||||
sqlite_dir,
|
||||
db_dict['database_name']))
|
||||
# These are no longer needed:
|
||||
db_dict.pop('SQLITE_ROOT', None)
|
||||
db_dict.pop('root', None)
|
||||
|
||||
@@ -807,12 +807,8 @@ def get_manager_dict_from_config(config_dict, data_binding,
|
||||
|
||||
# Now get the database dictionary if it's missing:
|
||||
if 'database_dict' not in manager_dict:
|
||||
try:
|
||||
database = manager_dict.pop('database')
|
||||
manager_dict['database_dict'] = get_database_dict_from_config(config_dict,
|
||||
database)
|
||||
except KeyError as e:
|
||||
raise weewx.UnknownDatabase("Unknown database '%s'" % e)
|
||||
database = manager_dict.pop('database')
|
||||
manager_dict['database_dict'] = get_database_dict_from_config(config_dict, database)
|
||||
|
||||
# The schema may be specified as a string, in which case we resolve the python object to which
|
||||
# it refers. Or it may be specified as a dict with field_name=sql_type pairs.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "weewx"
|
||||
version = "5.0.0a12"
|
||||
version = "5.0.0a13"
|
||||
description = "The WeeWX weather software system"
|
||||
authors = ["Tom Keffer <tkeffer@gmail.com>"]
|
||||
license = "GPL3"
|
||||
@@ -34,7 +34,7 @@ packages = [
|
||||
{ include = "weeplot", from = "bin" },
|
||||
{ include = "weeutil", from = "bin" },
|
||||
{ include = "weewx", from = "bin" },
|
||||
{ include = "wee_database", from = "bin" },
|
||||
{ include = "wee_database.py", from = "bin" },
|
||||
{ include = "wee_debug.py", from = "bin" },
|
||||
{ include = "wee_device.py", from = "bin" },
|
||||
{ include = "wee_import.py", from = "bin" },
|
||||
|
||||
Reference in New Issue
Block a user