NovaStar Program Reference / Data Import / nsrecdata-log-buffer-refile
- Overview
- Command Line Usage
- Examples
- Scheduling
- NovaStar Administrator Interface
- Troubleshooting
- See Also
Overview
The nsrecdata-log-buffer-refile program refiles data that are buffered in the
nsrecdata
log file but have not been inserted in the database.
Although this situation may be mitigated, it may always be an issue due to multiple processes
attempting to insert data and the need to interleave these processes so that real-time data can be inserted
as quickly as possible.
Buffering may be due to:
- The system has a high load and the database tables may be locked for inserts,
in which case the
nsrecdataprogram may quit retrying to insert buffered data (see thensrecdata--bufferretryand--retryintervalcommand parameters, which control buffering). - The system may have been stopped or restarted and buffered data in the log file need to be processed.
This program searches the current nsrecdata
log file and refiles reports that contain Action: buffer.
See also the --filterfile command line parameter, which allows additional filtering.
The program contains logic to ensure that only new buffered records are inserted rather
than refiling all buffered records in the log file.
This program is typically run as a scheduled process to ensure that buffered data reports are filed. Other actions, such as increasing server processing power and memory, can be implemented to improve performance.
The following files are involved and are mentioned below without the leading path:
- Input:
/var/log/novastar5/nsrecdata.log-nsrecdatalog file, which contains log messages for allnsrecdataprocesses, restarted each day by thelogrotateservice
- Intermediate:
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}- lines from thensrecdatalog file containingAction: buffer, indicating lines that have already been processed from the date'snsrecdata.logfile- or,
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}-nofile- lines from thensrecdatalog file containingAction: buffer, if--nofileis specified, used for testing and troubleshooting /var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}-{filter file name}-filtered-out- lines from thensrecdatalog file that contain bothAction: bufferand one of the patterns given in the file specified by--filterfile/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}-new- lines from thensrecdatalog file containingAction: bufferfound in the current run of this script./var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}gets the contents of this file if the data is inserted successfully. Deleted afterwards unless the--keepoption is given.
- Buffered data to refile:
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{date}-toinsert- buffered data formatted for loading. This is lines that have been added to thensrecdatalog file since the last time the buffer refiling script ran, edited to a format thatnsdataimportcan accept (report time,point numid,datavalue) Deleted after the script runs unless the--keepoption is given.
The program only processes new buffered data reports, which minimizes data refiling and associated processing load. The general process is:
- Check if the
nsrecdata-log-buffer-refilescript is already running:- Check if there are any processes with the same name, and if so, print an error message and exit.
- Load yesterday's data, if applicable:
- Check whether the
nsrecdata-log-buffer-refile{suffix}-{date}file exists for today's date. - If it does, skip forward to step 3.
- If it does not, pull all lines with
Action: bufferfromnsrecdata.log.1into/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}-new. - Check whether
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}exists. - If not, skip to step 2.7.
- If yes, determine how many lines are in the file, and remove that many lines
from the beginning of
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}-new. - If
--filterfilewas specified, rungrepon/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}-newusing the filters in the provided filter file, and put the results in/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}-{filter file name}-filtered-out. - The file (
-newif no--filterfile,-filtered-outif there is) is processed to get the data to file in the formatreport time,point numid,datavalue. This is placed into/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{yesterday's date}-toinsert. - The
-toinsertfile is passed tonsdataimport, which is run usingtimeoutwith a timeout of 3600 seconds (1 hour). - Delete the
-toinsertfile unless--keepwas specified. - If
nsdataimportfails, delete the-newfile. This means next time the script runs, it will not check anything from this run. Then, exit the script, skipping all future steps. - If
nsdataimportsucceeds, move the-newfile over the main file, unless--keepwas specified, in which case copy it.
- Check whether the
- Load today's data:
- Pull all lines with
Action: bufferfromnsrecdata.loginto/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}-new. - Check whether
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}exists. - If not, skip to step 3.5.
- If yes, determine how many lines are in the file, and remove that many lines
from the beginning of
/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}-new. - If
--filterfilewas specified, rungrepon/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}-newusing the filters in the provided filter file, and put the results in/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}-{filter file name}-filtered-out. - The file (
-newif no--filterfile,-filtered-outif there is) is processed to get the data to file in the formatreport time,point numid,datavalue. This is placed into/var/log/novastar5/nsrecdata-log-buffer-refile{suffix}-{today's date}-toinsert. - The
-toinsertfile is passed tonsdataimport, which is run usingtimeoutwith a timeout of 3600 seconds (1 hour). - Delete the
-toinsertfile unless--keepwas specified. - If
nsdataimportfails, delete the-newfile. This means next time the script runs, it will not check anything from this run. Then, exit the script, skipping all future steps. - If
nsdataimportsucceeds, move the-newfile over the main file, unless--keepwas specified, in which case copy it.
- Pull all lines with
- Delete old files:
- Unless
--keepwas specified, get all files that match the syntax/var/log/novastar5/nsrecdata-log-buffer-refile*. - Iterate through these files and delete them until the file that matches either the file for yesterday or the file for today (with or without the suffix) is reached, then exit.
- Unless
Command Line Usage
The command line syntax is as follows. Optional values are in square brackets.
nsrecdata-log-buffer-refile [options...]
nsrecdata-log-buffer-refile Command Line Parameters
| Parameter | Description | Default |
|---|---|---|
--debug |
Print additional debug messages to stderr. |
Only standard messages are printed. |
--filterfile=Filename |
Specify a filename with strings to match, useful when only processing certain source addresses or line numbers. This file is passed to grep -f to match the buffered data reports, in addition to matching Action: buffer. Each line is taken as a separate filter, and a line is returned if it matches any filter. For consistency, it is best if the file location given is absolute. By convention, the filter files should be stored in /usr/ns/cus/nsrecdata-log-buffer-refile/. |
All buffer lines are processed. |
-h, --help |
Display the program usage. | |
--keep |
Do not delete temporary or old files. | Files created prior to yesterday and intermediate processing files will be deleted. |
--nofile |
Print matching log file lines to /var/log/novastar5/nsrecdata-log-buffer-refile-dailybufferdata-nofile.log but do not file the data. Use the --debug parameter to print log file locations. This can be used to test the program and if a separate data filing step will be used. |
File the data. |
--suffix=Suffix |
A string to append to temporary files, so that separate processes can be configured, for example /var/log/novastar5/nsrecdsata-log-buffer-refile-suffix.... Note that the dash must be included in the string given. Recommended when using --filterfile so that files with different inclusion criteria are not compared. |
Temporary files use the script name only without a suffix. |
-v, --version |
Display the program version. |
Examples
The nsrecdata log file may contain lines similar to the following:
Jan 10 06:25:10 test-novastar nsrecdata[26609]: Line: 31 SA: 11009 Time: 01/10/2020 06:25:07 ID: 10000980 Data: 0 Scaled: 0.34 Action: buffer
Jan 10 06:25:11 test-novastar nsrecdata[26609]: Line: 31 SA: 11010 Time: 01/10/2020 06:25:08 ID: 10000981 Data: 0 Scaled: 0.34 Action: buffer
Action: buffer indicates buffered data that could not be inserted.
To do a dry run of the refiling, run the following command:
nsrecdata-log-buffer-refile --nofile
To file a subset of data that matches a given set of filters, run the following command:
nsrecdata-log-buffer-refile --filterfile=/usr/ns/cus/nsrecdata-log-buffer-refile/nsrecdata-log-buffer-refile-filter-file.txt
The filter file in the above example indicates text that must be present in the line to be refiled.
To filter for only lines where the first source address is either 11009 or 11010, the filter file could contain the following:
SA: 11009
SA: 11010
To refile all the buffered data without filtering, run the following command:
nsrecdata-log-buffer-refile
Scheduling
This program is typically configured as a NovaStar scheduled process to ensure that buffered data are loaded as quickly as possible.
Because the intent is to load real-time data, the program should be run on an interval that matches the ALERT2 TDMA frame length or transmit frequency for other data, such as Iridium satellite data.
The scheduled process command line can be similar to the examples shown in the previous section.
If additional output is desired for troubleshooting, create a script like the following,
for example named:
/usr/ns/cus/nsrecdata-log-buffer-refile/run-nsrecdata-log-buffer-refile-filter-file.sh.
#!/bin/sh
#
# Run the nsrecdata-log-buffer-refile program and redirect stdout and stderr to
# a log file that can be reviewed for troubleshooting.
# Get the location of this script.
scriptFolder=$(cd $(dirname "$0") && pwd)
scriptName=$(basename $0)
# Use a log file for troubleshooting:
# - use a location in /var/log since /usr/ns/cus is often backed up and want to keep small
logfile="/var/log/novastar5/cron-nsrecdata-log-buffer-refile.log"
now=$(date)
# Run the program:
# - redirect stdout and stderr to the log file
# - any output redirection in the script itself will go to the desired files
echo "Running ${scriptFolder}/${scriptName} at ${now}" > ${logfile}
nsrecdata-log-buffer-refile >> ${logfile} 2>&1
Then run the above script from the scheduler.
NovaStar Administrator Interface
See the Administrator scheduler.
Troubleshooting
Use the --debug and --nofile parameters to troubleshoot
and review the temporary files used to process the buffered log data.
Review the log file created when running the scheduled process, if a log file is created.
See Also
nsrecdataprogram - data collectionnsrecdatalogimportprogram - importnsrecdatalog file data