| 1 |
|
| 2 |
|
| 3 |
import argparse |
| 4 |
import json |
| 5 |
from subprocess import run |
| 6 |
from numpy import std |
| 7 |
|
| 8 |
parser = argparse.ArgumentParser(prog="ct-osds-filling", |
| 9 |
description="Script for monitor osds_filling") |
| 10 |
parser.add_argument("-m", |
| 11 |
"--min", |
| 12 |
action="store", |
| 13 |
default=10, |
| 14 |
type=int, |
| 15 |
help="Display OSDs with utilisation < MIN%%") |
| 16 |
parser.add_argument("-M", |
| 17 |
"--max", |
| 18 |
action="store", |
| 19 |
default=80, |
| 20 |
type=int, |
| 21 |
help="Displax OSDs with utilization > MAX%%") |
| 22 |
args = parser.parse_args() |
| 23 |
|
| 24 |
c = run(["ceph", "osd", "df", "-f", "json"], capture_output=True) |
| 25 |
osds = json.loads(c.stdout) |
| 26 |
utilization = [] |
| 27 |
umin = {} |
| 28 |
umax = {} |
| 29 |
for osd in osds['nodes']: |
| 30 |
if osd['reweight'] > 0: |
| 31 |
utilization.append(round(osd['utilization'])) |
| 32 |
if osd['utilization'] < args.min: |
| 33 |
umin[osd['id']] = osd['utilization'] |
| 34 |
if osd['utilization'] > args.max: |
| 35 |
umax[osd['id']] = osd['utilization'] |
| 36 |
|
| 37 |
freq = {} |
| 38 |
for items in utilization: |
| 39 |
freq[items] = (freq[items] + 1) if items in freq else 1 |
| 40 |
div = int(max(freq.values()) / 100) + 1 |
| 41 |
|
| 42 |
print("Utilization distribution:") |
| 43 |
for k, v in sorted(freq.items()): |
| 44 |
nb = round(v / div) |
| 45 |
print(f"{k:2d}% -> {v:<5d}{nb * '#'}") |
| 46 |
|
| 47 |
print(f"\nDeviation: {round(std(utilization),2)}") |
| 48 |
|
| 49 |
print(f"\nOSDs with utilization < {args.min}%:") |
| 50 |
for k, v in sorted(umin.items(), key=lambda x: x[1]): |
| 51 |
print(f"osd.{k:<4d}: {round(v,2)}%") |
| 52 |
print(f"OSDs with utilization > {args.max}%:") |
| 53 |
for k, v in sorted(umax.items(), key=lambda x: x[1]): |
| 54 |
print(f"osd.{k:<4d}: {round(v,2)}%") |