diff --git a/FlowAnalyserMain.py b/FlowAnalyserMain.py index 8541c4d..e0967f0 100644 --- a/FlowAnalyserMain.py +++ b/FlowAnalyserMain.py @@ -5,6 +5,10 @@ import FlowTest from sysjobs import * import sysjob2html import pandas as pd +import logging +from dateutil import tz +from pytz import timezone +import koerselsOverblikUtils def create_app(test_config=None): # create and configure the app @@ -25,7 +29,9 @@ def create_app(test_config=None): os.makedirs(FlowAnalyserMain.instance_path) except OSError: pass - + @FlowAnalyserMain.context_processor + def inject_debug(): + return dict(debug=FlowAnalyserMain.debug) # a simple page that says hello @FlowAnalyserMain.route('/hello') def hello(): @@ -33,23 +39,37 @@ def create_app(test_config=None): @FlowAnalyserMain.route('/test') def test(): listSysjobs=[] - listStartSlutjobs=[] - listStartSlutjobs.append(Sysjobs.getSysjob(session,'BI - Flow - Batch Start – Daglig kl. 20.00',True)[0]) - listStartSlutjobs.append(Sysjobs.getSysjob(session,'BI - Flow - Batch Slut – Daglig kl. 20.00',True)[0]) - listSysjobs.append(listStartSlutjobs[0][0]) + listStartSlutjobs=[Sysjobs.getSysjob(session,'BI - Flow - Batch Start – Daglig kl. 20.00',True)[0][0]] + listStartSlutjobs.append(Sysjobs.getSysjob(session,'BI - Flow - Batch Slut – Daglig kl. 20.00',True)[0][0]) + listStartSlutjobs=koerselsOverblikUtils.convertToAlike(listStartSlutjobs,0,30,0) + sysjobsAlike=koerselsOverblikUtils.timeRangeMerge(listStartSlutjobs, "Batch køretid",0,30,2) + listSysjobs.append(sysjobsAlike) + listSysjobs.extend(listStartSlutjobs) sysjobs=Sysjobs.getSysjob(session,'% - Admin - %',False) + sysjobs=[a for a in sysjobs if a[0].name not in ["BI - Admin - Kill Blocking Queries","BI - Admin - Flow Job Restarter"]] if(sysjobs!=None and len(sysjobs)>0): - for i in sysjobs: - listSysjobs.append(i[0]) - listSysjobs.append(listStartSlutjobs[1][0]) + sysjobs=koerselsOverblikUtils.convertToAlike(sysjobs,0,30,2) + listSysjobs.extend(sysjobs) listSysjobs = [x for x in listSysjobs if len(x.getMedianDag(0,30,2))>0] listSysjobs = sorted(listSysjobs, key=lambda x: x.getMedianDag(0,30,2)[0]) - return render_template('index.html', test=listSysjobs,startSlut=listStartSlutjobs) + return render_template('index.html', test=listSysjobs)#,startSlut=listStartSlutjobs) @FlowAnalyserMain.route('/test3') def test3(): sysjobs=(Sysjobs.getNattensKoersel(session)) return render_template('index3.html', test3=sysjobs) + @FlowAnalyserMain.route('/test4') + def test4(): + sessions=(biadmin_log_ActiveSessionsByInspari.getSessionTimeSpan(session, + datetime.fromisoformat('2023-06-01 23:14:16.817'), + datetime.fromisoformat('2023-06-02 03:14:18.817'))) + return render_template('index4.html', test4=sessions) + @FlowAnalyserMain.route('/test4//') + def test4_getSession(sessionID,logdate): + sessions=(biadmin_log_ActiveSessionsByInspari.getSessionByID(session,int(sessionID), + datetime.fromisoformat(logdate).astimezone(tz.gettz('Europe/Copenhagen')))) + return render_template('index4.html', test4=sessions) + @FlowAnalyserMain.route('/test2') def test2(): with Session(engine) as session: @@ -62,5 +82,8 @@ def create_app(test_config=None): return FlowAnalyserMain engine=inn.getEngine("msdb") +logging.basicConfig() +logging.getLogger("sqlalchemy.engine").setLevel(logging.DEBUG) +logging.getLogger("sqlalchemy.pool").setLevel(logging.DEBUG) with Session(engine) as session: FlowAnalyserMain=create_app() diff --git a/__pycache__/FlowAnalyserMain.cpython-311.pyc b/__pycache__/FlowAnalyserMain.cpython-311.pyc index 376385b..2ce6382 100644 Binary files a/__pycache__/FlowAnalyserMain.cpython-311.pyc and b/__pycache__/FlowAnalyserMain.cpython-311.pyc differ diff --git a/__pycache__/inn.cpython-311.pyc b/__pycache__/inn.cpython-311.pyc index 1f98e29..9d1b71e 100644 Binary files a/__pycache__/inn.cpython-311.pyc and b/__pycache__/inn.cpython-311.pyc differ diff --git a/__pycache__/koerselsOverblikUtils.cpython-311.pyc b/__pycache__/koerselsOverblikUtils.cpython-311.pyc new file mode 100644 index 0000000..7ae39b7 Binary files /dev/null and b/__pycache__/koerselsOverblikUtils.cpython-311.pyc differ diff --git a/__pycache__/sysjobs.cpython-311.pyc b/__pycache__/sysjobs.cpython-311.pyc index 5c5260d..aedd837 100644 Binary files a/__pycache__/sysjobs.cpython-311.pyc and b/__pycache__/sysjobs.cpython-311.pyc differ diff --git a/inn.py b/inn.py index e0b75e8..51fd59b 100644 --- a/inn.py +++ b/inn.py @@ -7,7 +7,7 @@ import urllib def getEngine(database): server = 'bi-dsa-test\dsa' # to specify an alternate port username = 'admindenker' - password = 'biadmin#kode4rm2' + password = 'Min!sterTj€n€r€nhv3r$ta7s11g3' connection_string = "DRIVER={SQL Server};Database="+database+";SERVER="+server diff --git a/koerselsOverblikUtils.py b/koerselsOverblikUtils.py new file mode 100644 index 0000000..227ae23 --- /dev/null +++ b/koerselsOverblikUtils.py @@ -0,0 +1,55 @@ +from datetime import datetime +from typing import List +from sysjobs import Sysjobs + + +class SysjobsAlike: + name=None + startTime=None + endTime=None + stepId=None + antalDage=None + ugeDage=None + def __init__(self,name): + self.name=name + def getName(self): + return self.name + def getMedianDag(self,stepId,antalDage,ugeDage): + medianDag=[self.startTime,self.endTime] + return medianDag + def mergeOneMore(self,sysjobs:Sysjobs): + medianDag=sysjobs.getMedianDag(self.stepId,self.antalDage,self.ugeDage) + if self.startTime>medianDag[0]: + self.startTime=medianDag[0] + if self.endTimemedianDag[0]: + sysjobalike.startTime=medianDag[0] + if sysjobalike.endTime is None or sysjobalike.endTime20230601).distinct() print(stmt) - with Session(engine) as session: + with Session(session) as session: row : Sysjobs res = session.execute(stmt).all() for row in res: @@ -129,7 +155,7 @@ GROUP BY [ctedateconversion].[MedianRun_datetime], resReturn: List['Sysjobs'] = list() stmt = Select(Sysjobs).join(DataflowManagement_JobListe).join(Sysjobhistory).join(DataflowManagement_JobsForExecution).where(Sysjobhistory.step_id==0).where(DataflowManagement_JobListe.Aktiv==1).where(or_(and_(Sysjobhistory.run_date>=int((natStat.strftime('%Y%m%d'))),(Sysjobhistory.run_time>=int((natStat.strftime('%H%M%S'))))),Sysjobhistory.run_date>=int((datetime.today().strftime('%Y%m%d'))))).distinct() row : Sysjobs - stmt.options(contains_eager(Sysjobs.sysjobhistories), contains_eager(Sysjobs.parents), contains_eager(DataflowManagement_JobAfhaengighed.parent)) + res = session.execute(stmt).all() return res @@ -155,6 +181,7 @@ GROUP BY [ctedateconversion].[MedianRun_datetime], def getSmallestWaitOfParent(self): return + class Sysjobhistory(Base): __tablename__ = "sysjobhistory" @@ -229,15 +256,6 @@ class DataflowManagement_JobListe(Base): sysjob: Mapped["Sysjobs"] = relationship(back_populates="dataflow_jobs") -class DataflowManagement_JobAfhaengighed(Base): - __tablename__ = "JobAfhaengighed" - __table_args__ = { "schema": "dataflowmanagement.flw" } - ParentJobID: Mapped[str] = mapped_column(ForeignKey("sysjobs.job_id"), primary_key=True) - ChildJobID: Mapped[str] = mapped_column(ForeignKey("sysjobs.job_id"), primary_key=True) - OprettetDato: Mapped[datetime] = Column(DateTime) - AendretDato: Mapped[datetime] = Column(DateTime) - parent: Mapped[List["Sysjobs"]] = relationship(back_populates="parents",foreign_keys=[ParentJobID]) - child: Mapped[List["Sysjobs"]] = relationship(back_populates="children",foreign_keys=[ChildJobID]) class DataflowManagement_JobMasterSetup(Base): __tablename__ = "JobMasterSetup" @@ -267,8 +285,37 @@ class msdb_sysjobsteps(Base): command:Mapped[str] = mapped_column(NVARCHAR) sysjob: Mapped["Sysjobs"] = relationship(back_populates="sysjobsteps") - - - +class biadmin_log_ActiveSessionsByInspari(Base): + __tablename__="ActiveSessionsByInspari" + __table_args__={"schema":"biadmin.log"} + session_id:Mapped[int]=mapped_column(SMALLINT,primary_key=True) + blocking_session_id:Mapped[int]=mapped_column(SMALLINT) + ElapsedTimeSec:Mapped[float]=mapped_column(DECIMAL) + ElapsedTimeMinutes:Mapped[float]=mapped_column(DECIMAL) + request_start_time:Mapped[datetime]=mapped_column(DateTime) + DatabaseName:Mapped[str]=mapped_column(NVARCHAR) + WaitTimeMs:Mapped[int]=mapped_column(INTEGER) + wait_type:Mapped[str]=mapped_column(NVARCHAR) + host_process_id:Mapped[int]=mapped_column(INTEGER) + MemoryGrantRequestTime:Mapped[datetime]=mapped_column(DateTime) + MemoryGrantGrantedTime:Mapped[datetime]=mapped_column(DateTime) + LogDate:Mapped[datetime]=mapped_column(DATETIME,primary_key=True) + + def getSessionTimeSpan(session:Session,beginTime:datetime,Endtime:datetime): + stmt=Select(biadmin_log_ActiveSessionsByInspari).where(and_(biadmin_log_ActiveSessionsByInspari.request_start_time>=beginTime,biadmin_log_ActiveSessionsByInspari.request_start_time<=Endtime)) + res=session.execute(stmt).all() + return res + def getSessionByID(session:Session,sessionID:int,logDate:datetime=None): + stmt=Select(biadmin_log_ActiveSessionsByInspari).where(and_(biadmin_log_ActiveSessionsByInspari.session_id==sessionID,biadmin_log_ActiveSessionsByInspari.LogDate==logDate)) + res=session.execute(stmt).all() + return res #class AllExecutionMessages(Base): +class BiAdmin_log_WaitingTasks(Base): + __tablename__="WaitingTasks" + __table_args__={"schema":"biadmin.log"} + session_id:Mapped[int]=mapped_column(SMALLINT,primary_key=True) + wait_duration_ms:Mapped[int]=mapped_column(BIGINT) + wait_type:Mapped[str]=mapped_column(NVARCHAR) + blocking_session_id:Mapped[int]=mapped_column(SMALLINT) + LogDate:Mapped[datetime]=mapped_column(DATETIME,primary_key=True) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index d7947ea..0c27855 100644 --- a/templates/index.html +++ b/templates/index.html @@ -18,7 +18,7 @@ data.addRows([ - ['Normal flow','Normal flow',new Date("{{ startSlut[0][0].getMedianDag(0,30,2)[0] }}"),new Date("{{ startSlut[1][0].getMedianDag(0,30,2)[0] }}")], + {% for job in test %} ['{{ job.name }}','{{ job.name }}',new Date("{{ job.getMedianDag(0,30,2)[0] }}"),new Date("{{ job.getMedianDag(0,30,2)[1] }}")], {% endfor %} diff --git a/templates/index4.html b/templates/index4.html new file mode 100644 index 0000000..079374b --- /dev/null +++ b/templates/index4.html @@ -0,0 +1,62 @@ + + + + + + +
+ + diff --git a/test.js b/test.js new file mode 100644 index 0000000..a28bfe0 --- /dev/null +++ b/test.js @@ -0,0 +1 @@ +new Date.today()