Generate the data

Here, we are SSH to the remote server and retrieving a list of files. Based on whether they're to do or done, we can determine the length of the queue. This is exported to CSV

In [5]:
import pandas as pd
import paramiko
from datetime import datetime
import re
import time
import numpy as np
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import dash_bootstrap_components as dbc
import plotly.express as px

#Connect to remote server
ssh = paramiko.SSHClient()
server = 'IP Address'
username = 'username'
password = 'password'

ssh.load_system_host_keys()
ssh.connect(server, username=username, password=password)

#Run command on remote server
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('stat -c "%y %n" *')

#Run through output and create dataframe
data = []
i = 0
for line in ssh_stdout:
    if i == 0:
        i = i+1
        pass
    else:
        time = line.split()[1]
        date = line.split()[0]
        dttime = (str(date) + ' ' + str(time) + str(line.split()[2])).split('.')[0]
        datetime = (datetime.strptime(dttime, "%Y-%m-%d %H:%M:%S"))
        filename = line.split()[3]
        data.append((datetime.now(), datetime.today().strftime('%Y-%m-%d'), datetime.today().strftime('%H:%m'), date, time[:5], time, filename, datetime.now()-datetime))
        i = i+1

df = pd.DataFrame(data, columns=['datetime_seen', 'Date_Seen', 'Time Seen', 'Date_Created', 'Time_Created', 'datetime_created', 'filename', 'time alive'])

#Calculate how long a file has been there
df['alive_minutes']=df['time alive']/np.timedelta64(1,'m')

#Create function to mark files as done or to do
def applyFunc(s):
    if 'done' in s :
        return 'Done'
    else:
        return 'To Do'
    return ''

#Apply function to column
df["Processed"] = df['filename'].apply(applyFunc)

#Close connection
ssh.close()

#Write to CSV
with open('Desktop/files.csv', 'a') as f:
    df.to_csv(f, header=False)

Dashboard the outcome

In [29]:
df2 = df.groupby(df["Processed"]).count().reset_index()
df3 = df.groupby(df["Date_Created"]).count().reset_index()
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div([
        dbc.NavbarSimple(
    sticky="top",
    color="dark"
),
        dbc.Row(
            [
                dbc.Col(dcc.Graph(id='processed', figure=px.bar(df2, x="Processed", y="datetime_seen").update_layout(showlegend=False, margin=dict(l=20, r=20, t=60, b=20))),width=6),
                dbc.Col(dcc.Graph(id='created', figure=px.bar(df3, x="Date_Created", y="datetime_seen").update_layout(showlegend=False, margin=dict(l=20, r=20, t=60, b=20))),width=6)
            ],
        )   
    ])

Run the server

In [30]:
if __name__ == "__main__":
    app.run_server()
 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_renderer/react@16.8.6.min.js?v=1.1.0&m=1570429578 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_renderer/react-dom@16.8.6.min.js?v=1.1.0&m=1570429578 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_renderer/prop-types@15.7.2.min.js?v=1.1.0&m=1570429577 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_html_components/dash_html_components.min.js?v=1.0.1&m=1570429580 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_core_components/highlight.pack.js?v=1.2.1&m=1570429579 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_core_components/plotly-1.49.4.min.js?v=1.2.1&m=1570429579 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_core_components/dash_core_components.min.js?v=1.2.1&m=1570429579 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_renderer/dash_renderer.min.js?v=1.1.0&m=1570429577 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:10] "GET /_dash-component-suites/dash_bootstrap_components/_components/dash_bootstrap_components.min.js?v=0.7.1&m=1570429613 HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:11] "GET /_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [09/Oct/2019 13:50:11] "GET /_dash-layout HTTP/1.1" 200 -
In [ ]: