In [2]:
import math
import pandas as pd
import mpl_toolkits.axisartist as AA
from mpl_toolkits.axes_grid1 import host_subplot
import matplotlib.pyplot as plt
from datetime import datetime
from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange, IndexDateFormatter

In [3]:
def parse_datetime(x):
    '''
    Parses datetime from cconsole as:
        `[day/month-hour:minute:second.ms]`
        year will be messed up (1900)
    '''
    dt = datetime.strptime(x, '%m/%d/%Y %H:%M:%S.%f')
        
    return dt

In [4]:
mgstatfile = '../vis-part2/mgstat.txt'
data = pd.read_csv(
    mgstatfile, 
    header=1,
    parse_dates=[[0,1]]
   )
data.info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 6297 entries, 0 to 6296
Data columns (total 28 columns):
Date_       Time        6297 non-null datetime64[ns]
  Glorefs               6297 non-null int64
 RemGrefs               6297 non-null int64
 GRratio                6297 non-null int64
  PhyRds                6297 non-null int64
 Rdratio                6297 non-null float64
 Gloupds                6297 non-null int64
 RemGupds               6297 non-null int64
 Rourefs                6297 non-null int64
 RemRrefs               6297 non-null int64
  RouLaS                6297 non-null int64
 RemRLaS                6297 non-null int64
  PhyWrs                6297 non-null int64
   WDQsz                6297 non-null int64
  WDtmpq                6297 non-null int64
 WDphase                6297 non-null int64
  WIJwri                6297 non-null int64
  RouCMs                6297 non-null int64
 Jrnwrts                6297 non-null int64
  ActECP                6297 non-null int64
  Addblk                6297 non-null int64
 PrgBufL                6297 non-null int64
 PrgSrvR                6297 non-null int64
  BytSnt                6297 non-null int64
  BytRcd                6297 non-null int64
  WDpass                6297 non-null int64
  IJUcnt                6297 non-null int64
 IJULock                6297 non-null int64
dtypes: datetime64[ns](1), float64(1), int64(26)
memory usage: 1.3 MB

In [ ]:


In [5]:
data.columns=data.columns.str.strip()
data=data.rename(columns={'Date_       Time':'DateTime'})

In [6]:
data.index=data.DateTime

In [7]:
perfmonfile="../vis-part2/perfmon.txt"
perfmon=pd.read_csv(perfmonfile,
                    header=0,
                    index_col=0,
                    converters={0: parse_datetime}
                   )

In [24]:
data.Glorefs['2017-01-03 00:02':'2017-01-03 00:03']


Out[24]:
DateTime
2017-01-03 00:02:00    450946
2017-01-03 00:02:10    424612
2017-01-03 00:02:20    455305
2017-01-03 00:02:30    364943
2017-01-03 00:02:40    359086
2017-01-03 00:02:50    336705
2017-01-03 00:03:00    384910
2017-01-03 00:03:10    417866
2017-01-03 00:03:20    401970
2017-01-03 00:03:30    426703
2017-01-03 00:03:40    430216
2017-01-03 00:03:50    388392
Name: Glorefs, dtype: int64

In [9]:
perfmon=perfmon.rename(columns={'(PDH-CSV 4.0) (AUS Eastern Daylight Time)(-660)':'DateTime'})
#perfmon.index=perfmon.DateTime

In [33]:
perfmon[perfmon.columns[91]]['2017-01-03 00:02':'2017-01-03 00:03']


Out[33]:
(PDH-CSV 4.0) (AUS Eastern Daylight Time)(-660)
2017-01-03 00:02:19.790    4.0558458375076025
2017-01-03 00:02:49.791    3.5089995597844403
2017-01-03 00:03:19.792    4.9803007143255771
2017-01-03 00:03:49.793    8.8017838086303257
Name: \\WEBSERVER\Processor(_Total)\% Privileged Time, dtype: object

In [12]:
plt.figure(num=None, figsize=(16,5), dpi=80, facecolor='w', edgecolor='k')
#plt.xticks(rotation=70)
host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twinx()
par2 = host.twinx()
offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right",axes=par2,offset=(offset, 0))
par2.axis["right"].toggle(all=True)

host.set_xlabel("time")
host.set_ylabel("Glorefs")

par1.set_ylabel("Rdratio")
par2.set_ylabel("Privileged Time")
ws=30
p1,=host.plot(data.Glorefs,label="Glorefs")
p2,=par1.plot(data.Rdratio,label="Rdratio")
p3,=par2.plot(pd.to_numeric(perfmon[perfmon.columns[91]],errors='coerce'),label="PTime")

host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right"].label.set_color(p3.get_color())

#plt.draw()
#plt.show()
plt.savefig("ptime-out.png")

In [39]:
from bokeh.plotting import *

In [38]:
output_file("mgstat.html")
#output_notebook()
TOOLS="pan,box_zoom,reset,save"

left = figure(tools=TOOLS,x_axis_type='datetime',
    title="Glorefs",width=600, height=350,
   x_axis_label='time'
)
right=figure(tools=TOOLS,x_axis_type='datetime',
    title="PTime",width=600, height=350,
   x_axis_label='time',x_range=left.x_range
)
left.line(data.index,data.Glorefs,legend="Glorefs",line_width=1)
right.line(perfmon.index,pd.to_numeric(perfmon[perfmon.columns[91]],errors='coerce'),legend="privileged time",line_width=1)
p=gridplot([[left,right]])
show(p)



In [ ]: