metrics: allow list of users

This commit is contained in:
ed 2025-11-20 00:37:36 +09:00
parent c424a55d6f
commit b427d7802a
3 changed files with 4 additions and 3 deletions

View file

@ -1491,6 +1491,7 @@ def add_hooks(ap):
def add_stats(ap): def add_stats(ap):
ap2 = ap.add_argument_group("grafana/prometheus metrics endpoint") ap2 = ap.add_argument_group("grafana/prometheus metrics endpoint")
ap2.add_argument("--stats", action="store_true", help="enable openmetrics at /.cpr/metrics for admin accounts") ap2.add_argument("--stats", action="store_true", help="enable openmetrics at /.cpr/metrics for admin accounts")
ap2.add_argument("--stats-u", metavar="U,U", type=u, default="", help="comma-separated list of users allowed to access /.cpr/metrics even if they aren't admin")
ap2.add_argument("--nos-hdd", action="store_true", help="disable disk-space metrics (used/free space)") ap2.add_argument("--nos-hdd", action="store_true", help="disable disk-space metrics (used/free space)")
ap2.add_argument("--nos-vol", action="store_true", help="disable volume size metrics (num files, total bytes, vmaxb/vmaxn)") ap2.add_argument("--nos-vol", action="store_true", help="disable volume size metrics (num files, total bytes, vmaxb/vmaxn)")
ap2.add_argument("--nos-vst", action="store_true", help="disable volume state metrics (indexing, analyzing, activity)") ap2.add_argument("--nos-vst", action="store_true", help="disable volume state metrics (indexing, analyzing, activity)")

View file

@ -17,10 +17,10 @@ class Metrics(object):
self.hsrv = hsrv self.hsrv = hsrv
def tx(self, cli: "HttpCli") -> bool: def tx(self, cli: "HttpCli") -> bool:
if not cli.avol: args = cli.args
if not cli.avol and cli.uname.lower() not in args.stats_u_set:
raise Pebkac(403, "'stats' not allowed for user " + cli.uname) raise Pebkac(403, "'stats' not allowed for user " + cli.uname)
args = cli.args
if not args.stats: if not args.stats:
raise Pebkac(403, "the stats feature is not enabled in server config") raise Pebkac(403, "the stats feature is not enabled in server config")

View file

@ -1081,7 +1081,7 @@ class SvcHub(object):
vs = os.path.expandvars(os.path.expanduser(vs)) vs = os.path.expandvars(os.path.expanduser(vs))
setattr(al, k, vs) setattr(al, k, vs)
for k in "idp_adm".split(" "): for k in "idp_adm stats_u".split(" "):
vs = getattr(al, k) vs = getattr(al, k)
vsa = [x.strip() for x in vs.split(",")] vsa = [x.strip() for x in vs.split(",")]
vsa = [x.lower() for x in vsa if x] vsa = [x.lower() for x in vsa if x]