|
301 | 301 | host = "0.0.0.0"; |
302 | 302 | }; |
303 | 303 |
|
304 | | - power.ups = { |
305 | | - enable = true; |
306 | | - mode = "netserver"; |
307 | | - ups.eaton5sc = { |
308 | | - driver = "usbhid-ups"; |
309 | | - port = "auto"; |
310 | | - directives = [ |
311 | | - "vendorid = 0463" |
312 | | - "productid = ffff" |
313 | | - ]; |
314 | | - description = "Eaton 5SC1000"; |
315 | | - }; |
316 | | - |
317 | | - upsd.listen = [ |
318 | | - { |
319 | | - address = "0.0.0.0"; |
320 | | - port = 1618; |
321 | | - } |
322 | | - ]; |
323 | | - |
324 | | - upsmon.monitor.eaton5sc = { |
325 | | - user = "monuser"; |
326 | | - system = "eaton5sc@127.0.0.1:1618"; |
327 | | - type = "primary"; |
328 | | - }; |
329 | | - |
330 | | - users.monuser = { |
331 | | - passwordFile = "/etc/nut/mon.pw"; |
332 | | - upsmon = "primary"; |
333 | | - }; |
334 | | - |
335 | | - openFirewall = true; |
336 | | - |
337 | | - }; |
338 | | - |
339 | | - environment.etc."nut/mon.pw" = { |
340 | | - text = "password"; |
341 | | - mode = "0600"; |
342 | | - user = "root"; |
343 | | - group = "nut"; |
344 | | - }; |
345 | | - |
346 | | - services.prometheus.exporters.nut = { |
347 | | - enable = true; |
348 | | - nutServer = "127.0.0.1"; |
349 | | - extraFlags = [ |
350 | | - "--nut.serverport=1618" |
351 | | - # "--metrics.namespace=nut" |
352 | | - "--nut.vars_enable=" |
353 | | - ]; |
354 | | - port = 16180; |
355 | | - listenAddress = "0.0.0.0"; |
356 | | - }; |
357 | | - |
358 | | - services.prometheus = { |
359 | | - enable = true; |
360 | | - scrapeConfigs = [ |
361 | | - { |
362 | | - job_name = "nut"; |
363 | | - metrics_path = "/ups_metrics"; |
364 | | - static_configs = [ |
365 | | - { |
366 | | - targets = [ "127.0.0.1:16180" ]; |
367 | | - # labels.ups = "eaton5sc"; |
368 | | - } |
369 | | - ]; |
370 | | - # metric_relabel_configs = [ |
371 | | - # { |
372 | | - # action = "drop"; |
373 | | - # source_labels = [ "ups" ]; |
374 | | - # regex = ""; # if label missing, value is empty — match and drop |
375 | | - # } |
376 | | - # ]; |
377 | | - } |
378 | | - ]; |
379 | | - }; |
380 | | - services.grafana = { |
381 | | - enable = true; |
382 | | - settings.server = { |
383 | | - http_addr = "0.0.0.0"; |
384 | | - http_port = 3000; |
385 | | - root_url = "https://office-desktop.tail5ca7.ts.net/grafana/"; |
386 | | - serve_from_sub_path = true; |
387 | | - }; |
388 | | - settings.auth = { |
389 | | - disable_login_form = true; |
390 | | - }; |
391 | | - |
392 | | - settings."auth.anonymous" = { |
393 | | - enabled = true; |
394 | | - org_role = "Viewer"; |
395 | | - org_name = "Main Org."; |
396 | | - }; |
397 | | - |
398 | | - # 1) Tell Grafana where to read dashboards from |
399 | | - provision.dashboards.settings = { |
400 | | - apiVersion = 1; |
401 | | - providers = [ |
402 | | - { |
403 | | - name = "mynutdashboard"; |
404 | | - orgId = 1; |
405 | | - folder = "NUT"; |
406 | | - type = "file"; |
407 | | - disableDeletion = false; |
408 | | - editable = true; |
409 | | - options = { |
410 | | - path = "/etc/grafana-dashboards/nut"; |
411 | | - }; |
412 | | - } |
413 | | - ]; |
414 | | - }; |
415 | | - |
416 | | - # 2) Provision Prometheus datasource (so the dashboard has data) |
417 | | - provision.datasources.settings = { |
418 | | - apiVersion = 1; |
419 | | - datasources = [ |
420 | | - { |
421 | | - name = "Prometheus"; |
422 | | - type = "prometheus"; |
423 | | - url = "http://127.0.0.1:9090"; |
424 | | - access = "proxy"; |
425 | | - isDefault = true; |
426 | | - } |
427 | | - ]; |
428 | | - # { |
429 | | - # name = "Prometheus"; |
430 | | - # type = "prometheus"; |
431 | | - # access = "proxy"; |
432 | | - # url = "http://127.0.0.1:9090"; |
433 | | - # isDefault = true; |
434 | | - # } |
435 | | - }; |
436 | | - }; |
437 | | - # TODO fix |
438 | | - environment.etc."grafana-dashboards/nut/mynutdashboard.json" = { |
439 | | - text = |
440 | | - let |
441 | | - raw = builtins.fetchurl { |
442 | | - url = "https://grafana.com/api/dashboards/15406/revisions/1/download"; |
443 | | - sha256 = "1pvyyxyy6prd0aqkvki04ayr4sw2rfyzx9gc3scyhzjy6rq648ca"; |
444 | | - }; |
445 | | - fixed = builtins.replaceStrings [ "$${DS_PROMETHEUS}" ] [ "Prometheus" ] (builtins.readFile raw); |
446 | | - in |
447 | | - fixed; |
448 | | - user = "grafana"; |
449 | | - group = "grafana"; |
450 | | - mode = "0644"; |
451 | | - }; |
452 | | - |
453 | | - systemd.services.upsmon.serviceConfig.LogNamespace = "power"; |
454 | | - systemd.services.upsd.serviceConfig.LogNamespace = "power"; |
455 | | - # The "@" targets the template, covering nut-driver@eaton5sc and any others |
456 | | - systemd.services."nut-driver@".serviceConfig.LogNamespace = "power"; |
457 | | - |
458 | | - environment.etc."systemd/journald@power.conf".text = '' |
459 | | - [Journal] |
460 | | - MaxRetentionSec=infinity |
461 | | - SystemMaxUse=500G |
462 | | - Storage=persistent |
463 | | - ''; |
464 | | - |
465 | 304 | services.vnstat.enable = true; |
466 | 305 | services.ntopng.enable = true; |
467 | 306 | services.ntopng.httpPort = 3123; |
|
0 commit comments