-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create update_monitor_maria_db.sh #12
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/bash | ||
set -Euo pipefail | ||
trap 's=$?; echo "$0: Error on line $LINENO: $BASH_COMMAND"; exit $s' ERR | ||
IFS=$'\n\t' | ||
|
||
# Startup | ||
date | ||
|
||
process_options() { | ||
verbose=false | ||
server="" | ||
user="" | ||
database="" | ||
table="" | ||
|
||
while getopts "hv:s:u:d:t:" opt; do | ||
case $opt in | ||
h) | ||
echo "Usage: $0 -s <server_name> -u <user_name> -d <database_name> -t <table_name>" | ||
echo "Collect condor queue info and update job monitoring database." | ||
echo "Options:" | ||
echo " -h Help" | ||
echo " -v Verbose level [true/false], default: false" | ||
echo " -s Server name" | ||
echo " -u User name" | ||
echo " -d Database name" | ||
echo " -t Table name" | ||
exit 0 | ||
;; | ||
v) | ||
verbose=${OPTARG} | ||
;; | ||
s) | ||
server=${OPTARG} | ||
;; | ||
u) | ||
user=${OPTARG} | ||
;; | ||
d) | ||
database=${OPTARG} | ||
;; | ||
t) | ||
table=${OPTARG} | ||
;; | ||
\?) | ||
echo "Use -h to display proper usage" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
echo "Verbose: $verbose" | ||
if [[ -n $server ]] && [[ -n $user ]] && [[ -n $database ]] && [[ -n $table ]]; then | ||
echo "Server: $server" | ||
echo "User: $user" | ||
echo "Database: $database" | ||
echo "Table: $table" | ||
else | ||
echo "All required arguments not defined." | ||
echo "Use -h to display proper usage" | ||
exit 1 | ||
fi | ||
} | ||
|
||
collect_job_ids() { | ||
# Run the condor_q command and capture the output | ||
output=$(condor_q --nobatch) | ||
|
||
# Extract the ID column and store it in an array | ||
readarray -t ids < <(echo "$output" | awk '{a[NR]=$1} END{for (i=5; i<NR-3; i++) print a[i]}') | ||
} | ||
|
||
store_info_per_id() { | ||
for id in "${ids[@]}"; do | ||
# Extract Job Ads Per Id | ||
IFS= | ||
job_ads="$(condor_q --nobatch -l $id -json)" | ||
IFS=$'\n\t' | ||
|
||
# Extract Job Start Date | ||
job_start_date=$(echo "$job_ads" | jq -r '.[].JobCurrentStartDate') | ||
hr_job_start_date=$(date -d "@$job_start_date" +"%Y-%m-%d %H:%M:%S") | ||
|
||
# Extract Job Status Code: 1=Idle, 2=Running, 5=Held | ||
job_status=$(echo "$job_ads" | jq -r '.[].JobStatus') | ||
|
||
# Extract Exit Code | ||
job_exit_code=$(echo "$job_ads" | jq -r '.[].ExitCode') | ||
|
||
if $verbose; then | ||
echo "Batch Job Id: $id" | ||
echo "Job Status Code: $job_status" | ||
echo "Latest Job Start Time: $hr_job_start_date" | ||
echo "Exit Code: $job_exit_code" | ||
echo "Job Ads:" | ||
echo "$job_ads" | ||
fi | ||
|
||
IFS= | ||
formatted_job_ads=$(printf "%s" "${job_ads}" | sed 's%"%%g') | ||
insert_query="INSERT INTO $table (Date, BatchJobID, Status, ExitCode, JobAd) VALUES (\"$hr_job_start_date\",\"$id\",\"$job_status\",\"$job_exit_code\",\"$formatted_job_ads\")" | ||
insert_query+=" ON DUPLICATE KEY UPDATE Date=\"$hr_job_start_date\", Status=\"$job_status\", ExitCode=\"$job_exit_code\", JobAd=\"$formatted_job_ads\";" | ||
|
||
IFS=$'\t' | ||
mysql --host="$server" --user="$user" --skip-password "$database" -e "$insert_query" | ||
done | ||
} | ||
|
||
process_options "$@" | ||
collect_job_ids | ||
store_info_per_id |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a job finishes it may not be in condor_q. You instead need to find it in condor_history. Additionally, this looks like it updates all jobs. This will definitely not scale. during monitoring you should only query jobs which are in a non end state (e.g. Status 1 or 2 or sentinel values). Additionally, I wouldn't make monitoring do the inserts as there is a nice division of labor: during submission you do the inserts and the monitoring is a separate arm that just updates. the knock on effect is that your query for monitoring is just an update and not an insert unless it is a duplicate then update. I am actually not sure how the DB would recognize the duplicate key as there is no forced uniqueness on the other parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about the scaling. Too many condor queries seem to slow down the entire thing. Gotta be a little smarter about how many times condor is queried within a short period of time.