Package: slurm2sql
This contains one utility,slurm2sql, which uses theSlurmworkload manager’ssacct,
to export all statistics from jobs and load them to a well-formed
sqlite3 file.  This file can then be queried for analytics much more
easily than the raw database or your own exports.InstallationThere is only a single file with no dependencies.  Python greater than
2.7 is required (dependencies are purposely kept minimal).Theslurm2sqllibrary + command line frontend can be installed via
the Python Package Index:pip install slurm2sql.UsageSample usage:slurm2sql.py [output_db] -- [sacct selection options]For example, to get all data from July and August (-S) for all
users (-a):slurm2sql.py sincejuly.sqlite3 -- -S 2019-07-1 -aTo get the data from the lastNdays.  This will, day by day, get
each of these history and cumulatively update the database.  This
updates a database by default, so that it can be used every day in
order to efficiently keep a running database.  The-uoption means
“don’t delete existing database” (jobs with the same JobID get
updated, not duplicated):slurm2sql.py --history-days=N -u sincejuly.sqlite3 -- -aThe--history-start=YYYY-MM-DDoption can do a similar thing
starting from a certain day, and--history=DD-HH:MM:SSstarts
collecting from a given interval of time ago (the time format is as in
Slurm).To resume from where you left off, first run with one of the history
options.  Then, you can do--history-resume(no-uneeded) and
it will continue fetching day-by-day from the time you last fetched:slurm2sql.py --history-days=N -u sincejuly.sqlite3 -- -a
slurm2sql.py --history-resume sincejuly.sqlite3 -- -aIt can also be used from Python as what is essentially a glorified
parser:db = sqlite3.connect(':memory:')
slurm2sql.slurm2sql(db, ['-S', '2019-08-26'])

# For example, you can then convert to a dataframe:
import pandas as pd
df = pd.read_sql('SELECT * FROM slurm', db)Database formatThere is one table with nameslurm.  There is one viewallocationswhich has only the jobs (not job steps) (where JobStep is null).There is one row for each item returned bysacct.In general, there is one column for each item returned bysacct,
but some of them are converted into a more useful form.  Some columns
are added by re-processing other columns.  In general, just use the
source.  SeeCOLUMNSinslurm2sql.pyfor details.  Extra
columns can easily be added.There are two types of converter functions: easy ones, which map one
slurm column directly to a database column via a function, and line
functions, which take the whole row and can do arbitrary remixing of
the data.ColumnsAll column values are converted to standard units:bytes(not MB,
KB, etc),seconds,fraction 0.0-1.0for things like
percentages.Below are some notable columns which do not exist in sacct (for the
rest, check out thesacct manual page).  It’s good
to verify that any of our custom columns make sense before trusting
them.  For other columns, checkman sacct.Time: approximation of last active time of a job.  The first of
these that exists:End,Start,Submitted.  This is
intended to be used when you need to classify a job by when it ran,
but you don’t care to be that specific.  (Only the Time column is
indexed by default, not the other times)Submit,Start,End: like the sacct equivalents,
but unixtime.  Assume that the sacct timestamps are in localtime of
the machine doing the conversion.  (slurm2sql.unixtimeconverts
slurm-format timestamp to unixtime)Job IDs.  Slurm Job ID is by default of formatJobID.JobSteporArrayJobID_ArrayTaskID.JobStep.
Furthermore, each array job has a “Raw JobID” (different for each
job, and is an actual JobID) in addition to the “ArrayJobID” which
is the same for all jobs in an array.  We split all of these
different IDs into the following fields:JobID: Only the integer Job ID, without the trailing array
tasks or job IDs.  For array jobs, this is the “Raw JobID” as
described above, useArrayJobIDto filter jobs that are the
same.  IntegerArrayJobID: The common array ID for all jobs in an array -
only.  For non-array jobs, same as JobID.  Integer or null.ArrayTaskID: As used above.  Integer on null.JobStep: Job step - only.  If you SQL filter forStepID is nullyou get only the main allocations.  String.JobIDSlurm: The raw output from sacct JobID field, including.and_.  String.ReqMem: The raw slurm value in a format like “5Gn”.  Instead of
parsing this, you probably want to use one of the other values below.ReqMemNode,ReqMemCPU: Requested memory per node or CPU,
either taken from ReqMem (if it matches) or computed (you might want
to check our logic if you rely on this).  In Slurm, you
can request memory either per-node or per-core, and this calculates
the other one for you.ReqMemType:cif the user requested mem-per-core originally,nif mem-per-node.  Extracted fromReqMem.ReqMemRaw: The numeric value of theReqMem, whether it iscorn.ReqGPU: Number of GPUs requested.  Extracted fromReqGRES.GPU information.  At Aalto we store GPU usage information in theCommentfield in JSON of the form{"gpu_util": NN.NN, "gpu_max_mem": NN, "ngpu": N}.  This extracts information from that.GPUMem: Max amount of memory used from any GPU.  Note: all GPU
stats require a separate Aalto-developed script.GPUEff: Percent usage of the GPUs (0.0-1.0).NGPU: Number of GPUs.  Should be the same asReqGPU, but
who knows.MemEff: Memory efficiency (0.0-1.0).  Like inseff.  We
compute it ourselves, so it could be wrong.  Test before trusting!
There can still be corner cases, job steps may be off, etc.  This
also relies on memory reporting being correct, which may not be the
case…CPUEff: CPU efficiency (0.0-1.0).  All the same caveats as above
apply: test before trusting.Quick reference of the other most important columns from the
accounting database:Elapsed: Wall clock timeCPUTime: Reserved CPU time (Elapsed * number of CPUs).  CPUEff ≈
TotalCPU/CPUTime = TotalCPU/(NCPUs x Elapsed)TotalCPU: SystemCPU + TotalCPU, seconds of productive work.Changelog0.9.1Slurm >= 20.11 deprecates theAllocGRESandReqGREScolumns
(usingAlloc/ReqTRESinstead).From this slurm2sql version, a ReqTRES column will be requested
and databases will need to be re-created (or manually added to the
databases).If run on Slurm > 20.11, it will not request ReqGRES and only use
ReqTRES.Development and maintenanceThis could be considered beta right now, but it works and is in use by
people.  There are many different variations of Slurm, if it doesn’t
work for you, send an issue or pull request to help us make it more
general - development is only done in response to feedback.Release process:python setup.py sdist bdist_wheel
twine upload [--repository-url https://test.pypi.org/legacy/] dist/*0.9.0*Originally developed at Aalto University, Finland.