WIP: Introduce Intel 2024, 2025, tasycl and oneMath #3
@ -4,6 +4,7 @@
 | 
			
		||||
  imports = [
 | 
			
		||||
    ../module/slurm-exporter.nix
 | 
			
		||||
    ../module/meteocat-exporter.nix
 | 
			
		||||
    ../module/upc-qaire-exporter.nix
 | 
			
		||||
    ./gpfs-probe.nix
 | 
			
		||||
    ./nix-daemon-exporter.nix
 | 
			
		||||
  ];
 | 
			
		||||
@ -112,6 +113,7 @@
 | 
			
		||||
            "127.0.0.1:9966" # GPFS custom exporter
 | 
			
		||||
            "127.0.0.1:9999" # Nix-daemon custom exporter
 | 
			
		||||
            "127.0.0.1:9929" # Meteocat custom exporter
 | 
			
		||||
            "127.0.0.1:9928" # UPC Qaire custom exporter
 | 
			
		||||
            "127.0.0.1:${toString config.services.prometheus.exporters.blackbox.port}"
 | 
			
		||||
          ];
 | 
			
		||||
        }];
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								m/module/upc-qaire-exporter.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								m/module/upc-qaire-exporter.nix
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
{ config, lib, pkgs, ... }:
 | 
			
		||||
 | 
			
		||||
with lib;
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  systemd.services."prometheus-upc-qaire-exporter" = {
 | 
			
		||||
    wantedBy = [ "multi-user.target" ];
 | 
			
		||||
    after = [ "network.target" ];
 | 
			
		||||
    serviceConfig = {
 | 
			
		||||
      Restart = mkDefault "always";
 | 
			
		||||
      PrivateTmp = mkDefault true;
 | 
			
		||||
      WorkingDirectory = mkDefault "/tmp";
 | 
			
		||||
      DynamicUser = mkDefault true;
 | 
			
		||||
      ExecStart = "${pkgs.upc-qaire-exporter}/bin/upc-qaire-exporter";
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@ -55,4 +55,5 @@ final: prev:
 | 
			
		||||
 | 
			
		||||
  prometheus-slurm-exporter = prev.callPackage ./slurm-exporter.nix { };
 | 
			
		||||
  meteocat-exporter = prev.callPackage ./meteocat-exporter/default.nix { };
 | 
			
		||||
  upc-qaire-exporter = prev.callPackage ./upc-qaire-exporter/default.nix { };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										24
									
								
								pkgs/upc-qaire-exporter/default.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								pkgs/upc-qaire-exporter/default.nix
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
{ python3Packages, lib }:
 | 
			
		||||
 | 
			
		||||
python3Packages.buildPythonApplication rec {
 | 
			
		||||
  pname = "upc-qaire-exporter";
 | 
			
		||||
  version = "1.0";
 | 
			
		||||
 | 
			
		||||
  src = ./.;
 | 
			
		||||
 | 
			
		||||
  doCheck = false;
 | 
			
		||||
 | 
			
		||||
  build-system = with python3Packages; [
 | 
			
		||||
    setuptools
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  dependencies = with python3Packages; [
 | 
			
		||||
    prometheus-client
 | 
			
		||||
    requests
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  meta = with lib; {
 | 
			
		||||
    description = "UPC Qaire Prometheus Exporter";
 | 
			
		||||
    platforms = platforms.linux;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								pkgs/upc-qaire-exporter/setup.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								pkgs/upc-qaire-exporter/setup.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#!/usr/bin/env python
 | 
			
		||||
 | 
			
		||||
from setuptools import setup, find_packages
 | 
			
		||||
 | 
			
		||||
setup(name='upc-qaire-exporter',
 | 
			
		||||
      version='1.0',
 | 
			
		||||
      # Modules to import from other scripts:
 | 
			
		||||
      packages=find_packages(),
 | 
			
		||||
      # Executables
 | 
			
		||||
      scripts=["upc-qaire-exporter"],
 | 
			
		||||
     )
 | 
			
		||||
							
								
								
									
										74
									
								
								pkgs/upc-qaire-exporter/upc-qaire-exporter
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								pkgs/upc-qaire-exporter/upc-qaire-exporter
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,74 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
from prometheus_client import start_http_server, Gauge
 | 
			
		||||
import requests, json
 | 
			
		||||
from datetime import datetime, timedelta
 | 
			
		||||
 | 
			
		||||
# Configuration -------------------------------------------
 | 
			
		||||
listening_port = 9928
 | 
			
		||||
update_period = 60 * 5 # Each 5 min
 | 
			
		||||
# ---------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
metric_temp = Gauge('upc_c6_s302_temp', 'UPC C6 S302 temperature sensor')
 | 
			
		||||
 | 
			
		||||
def genparams():
 | 
			
		||||
    d = {}
 | 
			
		||||
    d['topic'] = 'TEMPERATURE'
 | 
			
		||||
    d['shift_dates_to'] = ''
 | 
			
		||||
    d['datapoints'] = 301
 | 
			
		||||
    d['devicesAndColors'] = '1148418@@@#40ACB6'
 | 
			
		||||
 | 
			
		||||
    now = datetime.now()
 | 
			
		||||
 | 
			
		||||
    d['fromDate'] = now.strftime('%d/%m/%Y')
 | 
			
		||||
    d['toDate'] = now.strftime('%d/%m/%Y')
 | 
			
		||||
    d['serviceFrequency'] = 'NONE'
 | 
			
		||||
 | 
			
		||||
    # WTF!
 | 
			
		||||
    for i in range(7):
 | 
			
		||||
        for j in range(48):
 | 
			
		||||
            key = 'week.days[{}].hours[{}].value'.format(i, j)
 | 
			
		||||
            d[key] = 'OPEN'
 | 
			
		||||
 | 
			
		||||
    return d
 | 
			
		||||
 | 
			
		||||
def measure():
 | 
			
		||||
    # First we need to load session
 | 
			
		||||
    s = requests.Session()
 | 
			
		||||
    r = s.get("https://upc.edu/sirena")
 | 
			
		||||
    if r.status_code != 200:
 | 
			
		||||
        print("bad HTTP status code on new session: {}".format(r.status_code))
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    if s.cookies.get("JSESSIONID") is None:
 | 
			
		||||
        print("cannot get JSESSIONID")
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    # Now we can pull the data
 | 
			
		||||
    url = "https://upcsirena.app.dexma.com/l_12535/analysis/by_datapoints/data.json"
 | 
			
		||||
    r = s.post(url, data=genparams())
 | 
			
		||||
 | 
			
		||||
    if r.status_code != 200:
 | 
			
		||||
        print("bad HTTP status code on data: {}".format(r.status_code))
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    #print(r.text)
 | 
			
		||||
    j = json.loads(r.content)
 | 
			
		||||
 | 
			
		||||
    # Just take the last one
 | 
			
		||||
    last = j['data']['chartElementList'][-1]
 | 
			
		||||
    temp = last['values']['1148418-Temperatura']
 | 
			
		||||
 | 
			
		||||
    return temp
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    start_http_server(port=listening_port, addr="localhost")
 | 
			
		||||
    while True:
 | 
			
		||||
        try:
 | 
			
		||||
            metric_temp.set(measure())
 | 
			
		||||
        except:
 | 
			
		||||
            print("measure failed")
 | 
			
		||||
            metric_temp.set(float("nan"))
 | 
			
		||||
 | 
			
		||||
        time.sleep(update_period)
 | 
			
		||||
		Reference in New Issue
	
	Block a user