Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Security metrics for leaders

After this lesson: I can turn security data into measures with a target, a status and a trend.

60 min lesson6 commandsJupyterLab data science lab: pandas, Matplotlib and scikit-learn in the browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Is it getting better?

Lantern Print's directors paid for training, two-step sign-in and faster updates. Six months on, they ask one question: is it working?

"We blocked 1,320 bad emails" does not answer it. A good measure does.

By the end of this lesson

Note

I can turn security data into measures with a target, a status and a trend.

Key words

WordWhat it means
Metrica number measured the same way each time
Targetthe value leaders want a metric to reach
RAG statusred, amber or green against the target
Trendthe direction a metric moves over time
Vanity metrica number that looks good but guides no decision

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A good metric drives a decision

A useful metric is a rate, not a raw count. It has a target, an owner, and a clear way to measure it each month.

Per cent of devices patched within 14 days is useful: it links to Cyber Essentials and to a risk. Emails blocked is a vanity metric: it rises and falls with what attackers send.

Try it: one metric, one status

Code: python
devices = 42
patched = 38
target = 90
value = round(100 * patched / devices, 1)
status = "green" if value >= target else "amber" if value >= target - 10 else "red"
print(value, "per cent patched in time:", status)
# Two devices miss the next update. Set patched = 36 and run again.

Make a free account to save your work and track your progress.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Six months of figures

monthly.py holds Lantern Print's figures from June to November. metrics.py turns four of them into percentages. It adds the target, the status and whether the trend is better or worse.

For "phishing clicked", lower is better.

Write the monthly figures

Command
docker exec jupyter sh -c "mkdir -p steps && printf '%s\n' 'months = [\"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\"]' 'data = {' '    \"devices\": [40, 40, 40, 41, 41, 42],' '    \"patched in 14 days\": [26, 29, 31, 34, 36, 38],' '    \"accounts\": [30, 30, 31, 31, 32, 32],' '    \"accounts with two-step\": [18, 20, 24, 27, 30, 31],' '    \"test phishing emails\": [30, 30, 30, 30, 30, 30],' '    \"reported\": [4, 6, 9, 11, 14, 17],' '    \"clicked\": [9, 8, 6, 5, 4, 4],' '    \"emails blocked\": [1210, 1460, 905, 1630, 1105, 1320],' '}' '' 'measures = [' '    (\"patched in time\", \"patched in 14 days\", \"devices\", 90, True),' '    (\"two-step sign-in\", \"accounts with two-step\", \"accounts\", 100, True),' '    (\"phishing reported\", \"reported\", \"test phishing emails\", 50, True),' '    (\"phishing clicked\", \"clicked\", \"test phishing emails\", 5, False),' ']' > steps/monthly.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the metrics, part 1

Command
docker exec jupyter sh -c "mkdir -p steps && printf '%s\n' 'from monthly import data, measures, months' '' '' 'def percent(part, whole):' '    return round(100 * part / whole, 1) if whole else 0.0' '' '' 'def rag(value, target, higher_is_better):' '    gap = value - target if higher_is_better else target - value' '    if gap >= 0:' '        return \"green\"' '    return \"amber\" if gap >= -10 else \"red\"' '' '' 'if __name__ == \"__main__\":' '    print(\"measure            \" + \" \".join(f\"{m:>5}\" for m in months) + \"  target  status\")' '    for name, part, whole, target, up in measures:' '        values = [percent(p, w) for p, w in zip(data[part], data[whole])]' '        trend = \"better\" if (values[-1] > values[0]) == up else \"worse\"' '        status = rag(values[-1], target, up)' '        print(f\"{name:<18} \" + \" \".join(f\"{v:5.1f}\" for v in values) + f\"  {target:>5}%  {status}, {trend}\")' > steps/metrics.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the metrics, part 2

Command
docker exec jupyter sh -c "printf '%s\n' '    print(\"emails blocked     \" + \" \".join(f\"{v:>5}\" for v in data[\"emails blocked\"]) + \"  (a count with no target)\")' >> steps/metrics.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Show six months of metrics

Command
docker exec jupyter python3 steps/metrics.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Report to leaders in five lines

Directors need the status, the target and the change since last month, in plain words. They do not need every figure.

board.py prints that report and ends with one fact to act on.

Write the board report

Command
docker exec jupyter sh -c "mkdir -p steps && printf '%s\n' 'from metrics import percent, rag' 'from monthly import data, measures, months' '' 'print(\"Security report to the directors,\", months[-1])' 'for name, part, whole, target, up in measures:' '    now = percent(data[part][-1], data[whole][-1])' '    before = percent(data[part][-2], data[whole][-2])' '    print(f\"  {name}: {now}% against a target of {target}% ({rag(now, target, up)}), {before}% last month\")' 'left = data[\"accounts\"][-1] - data[\"accounts with two-step\"][-1]' 'print(\"accounts still without two-step sign-in:\", left)' > steps/board.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Print the board report

Command
docker exec jupyter python3 steps/board.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think a metric that went up shows security improved. Phishing reports rose because staff learnt to report, which is good; blocked emails rose because attackers sent more. Ask what each number depends on before you celebrate it.

Assignment: status and trend

percent(part, whole) returns a percentage rounded to one decimal place, or 0.0 when whole is 0. rag(value, target, higher_is_better) returns "green" when the target is met, "amber" within 10 points, else "red". trend(values, higher_is_better) compares the last value with the first: "same", "better" or "worse".

Code: python
def percent(part, whole):
    # part as a percentage of whole, rounded to 1 decimal place, or 0.0 when whole is 0.
    return 0.0


def rag(value, target, higher_is_better):
    # "green" when the target is met, "amber" when within 10 points of it, "red" otherwise.
    return ""


def trend(values, higher_is_better):
    # Compare the last value with the first: "same", "better" or "worse".
    return ""

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.