Skip to content

Commit d0a6133

Browse files
authored
Merge pull request #2 from NCAR/develop
Add JSON output support and privileges
2 parents 29b9093 + a759e30 commit d0a6133

File tree

5 files changed

+281
-62
lines changed

5 files changed

+281
-62
lines changed

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# qstat-cache
2-
A cached version of the PBS Pro qstat command that reduces load on the scheduler's database
2+
A cached version of the PBS Pro qstat command that reduces load on the
3+
scheduler's database
34

45
## Details
5-
Most users run the qstat command at reasonable intervals and things work well. However, with the advent of workflow managers more users are running qstat at frequencies much too high for current versions of PBS Pro to support well. This utility creates a simple text-based cache of common qstat output and provides a script to serve that data to users. If an option is not cached (e.g., -xf output), the query is sent to PBS's version of qstat for processing. Usage:
6+
Most users run the qstat command at reasonable intervals and things work well.
7+
However, with the advent of workflow managers more users are running qstat at
8+
frequencies much too high for current versions of PBS Pro to support well. This
9+
utility creates a simple text-based cache of common qstat output and provides a
10+
script to serve that data to users. If an option is not cached (e.g., -xf
11+
output), the query is sent to PBS's version of qstat for processing. Usage:
612

713
```
814
Usage: qstat [OPTIONS] [JOBID1 JOBID2...|DESTINATION] [@SERVER]
@@ -20,7 +26,9 @@ be specified per request.
2026
2127
Options:
2228
-h, --help display this help and exit
29+
-a display all jobs (default unless -f specified)
2330
-f display full output for a job
31+
-Fjson display full output in JSON format (use with -f)
2432
-H job output regardless of state or all finished jobs
2533
-l disable labels (no header)
2634
-n display a list of nodes at the end of the line
@@ -34,9 +42,12 @@ Options:
3442
## Installation
3543

3644
1. Clone this repository on your system.
37-
2. Copy or rename the site.cfg.example file to site.cfg and edit the configuration settings.
38-
3. Run the `validate.sh` script to ensure your site.cfg is set up properly (*optional, but recommended*).
39-
4. Schedule the gen_data.sh script to run at regular intervals (typically every minute via a cron job).
45+
2. Copy or rename the site.cfg.example file to site.cfg and edit the
46+
configuration settings.
47+
3. Run the `validate.sh` script to ensure your site.cfg is set up properly
48+
(*optional, but recommended*).
49+
4. Schedule the gen_data.sh script to run at regular intervals (typically every
50+
minute via a cron job).
4051
5. Add the cached version of `qstat` to your (and your users') environment PATH.
4152

4253
### site.cfg settings
@@ -93,20 +104,45 @@ GENFREQ=10
93104
# user queries (use qstat -Bf to get server names)
94105
95106
SERVERMAP=
107+
108+
# Which potentially expensive options do you want to enable
109+
110+
CACHEFLAGS="f Fjson"
111+
112+
# Enable privilege checking according to following user and
113+
# group settings. If false, all queries allowed.
114+
115+
PRIV_MODE=true
116+
117+
# Permit users and groups from these two lists respectively to
118+
# see "full" job output from other users (can contain sensitive
119+
# information if user is passing environment with -V)
120+
121+
PRIV_USERS="root"
122+
PRIV_GROUPS="admins support"
96123
```
97124

98125
### Example crontab
99126

100-
Here is a sample crontab that will run the gen_data.sh script every minute (sub-minute scheduled is recommended and enabled via the site.cfg). The idea here is to run often enough that users and their workflows are satisfied, but not so often that we put our own load on PBS.
127+
Here is a sample crontab that will run the gen_data.sh script every minute
128+
(sub-minute scheduled is recommended and enabled via the site.cfg). The idea
129+
here is to run often enough that users and their workflows are satisfied, but
130+
not so often that we put our own load on PBS.
101131

102132
```
103133
# Run qstat cache generation script every minute
104134
# Added by Joe User on 4 Dec 2019
105-
* * * * * /path/to/qstat_cache/gen_data.sh
135+
* * * * * QSCACHE_SERVER=sitename /path/to/qstat_cache/gen_data.sh
106136
```
107137

108138
## Debugging
109139

110-
There are two environment variables you may set to assist in debugging. Setting `QSCACHE_DEBUG` to `true` will cause qstat to print the error stream from the cache read command if it fails (otherwise this output is suppressed). It will also print the age of the cache, assuming it can be found.
140+
There are two environment variables you may set to assist in debugging. Setting
141+
`QSCACHE_DEBUG` to `2` will cause qstat to print the error stream from the
142+
cache read command if it fails (otherwise this output is suppressed). If set to
143+
`1` or greater, qstat will also print the age of the cache, assuming it can be
144+
found.
111145

112-
If you set `QSCACHE_BYPASS` to `true`, the cache will be bypassed regardless of which options are set, and the scheduler version of qstat will instead be called.
146+
If you set `QSCACHE_BYPASS` to `true`, the cache will be bypassed regardless of
147+
which options are set, and the scheduler version of qstat will instead be
148+
called.

gen_data.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,21 @@ function main_gen {
6363
$PBSPREFIX $QSTATBIN -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-default.dat &
6464
$PBSPREFIX $QSTATBIN -1 -n -s -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-info.dat &
6565
$PBSPREFIX $QSTATBIN -a -1 -n -s -w -x | sed '/^[0-9]/,$!d' | sed 's/\([0-9]\+\) b/ \1b/' > newlist-wide.dat &
66-
$PBSPREFIX $QSTATBIN -f > joblist-full.dat &
66+
67+
if [[ " $CACHEFLAGS " == *" f "* ]]; then
68+
$PBSPREFIX $QSTATBIN -f > joblist-full.dat &
69+
else
70+
rm -f joblist-full.dat
71+
fi
72+
73+
if [[ " $CACHEFLAGS " == *" Fjson "* ]]; then
74+
# Messy sed command fixes observed JSON errors from user environment variables:
75+
# 1. Numbers after a number 0 (octal) that aren't strings
76+
# 2. Trailing decimal points in numbers
77+
$PBSPREFIX $QSTATBIN -f -F json | sed 's/":\(0[0-9][^,]*\)/":"\1"/; s/":\([0-9]*\)\.,/":"\1\.",/' > joblist-fulljson.dat &
78+
else
79+
rm -f joblist-fulljson.dat
80+
fi
6781

6882
wait
6983

0 commit comments

Comments
 (0)