first jenkins statistics
This commit is contained in:
parent
d1029befcc
commit
2eedd55b2b
1 changed files with 19 additions and 9 deletions
|
@ -19,7 +19,7 @@ class Build:
|
||||||
self.duration = datetime.timedelta(milliseconds=build_dict['duration'])
|
self.duration = datetime.timedelta(milliseconds=build_dict['duration'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def day(self) -> datetime.datetime:
|
def hour(self) -> datetime.datetime:
|
||||||
return datetime.datetime(
|
return datetime.datetime(
|
||||||
year=self.start_time.year,
|
year=self.start_time.year,
|
||||||
month=self.start_time.month,
|
month=self.start_time.month,
|
||||||
|
@ -27,6 +27,14 @@ class Build:
|
||||||
hour=self.start_time.hour,
|
hour=self.start_time.hour,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def day(self) -> datetime.datetime:
|
||||||
|
return datetime.datetime(
|
||||||
|
year=self.start_time.year,
|
||||||
|
month=self.start_time.month,
|
||||||
|
day=self.start_time.day,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class JenkinsStatsReader:
|
class JenkinsStatsReader:
|
||||||
|
|
||||||
|
@ -57,7 +65,8 @@ class JenkinsStatsReader:
|
||||||
if not os.path.isfile(self._JENKINS_DAT_FILE):
|
if not os.path.isfile(self._JENKINS_DAT_FILE):
|
||||||
self.fetch_data()
|
self.fetch_data()
|
||||||
self.parse_data()
|
self.parse_data()
|
||||||
self.create_day_statistics()
|
self.create_statistics('hour')
|
||||||
|
self.create_statistics('day')
|
||||||
|
|
||||||
def fetch_data(self):
|
def fetch_data(self):
|
||||||
response = self._session.get(
|
response = self._session.get(
|
||||||
|
@ -73,23 +82,24 @@ class JenkinsStatsReader:
|
||||||
self.builds[job_name] = [Build(job_name, b) for b in job['allBuilds']]
|
self.builds[job_name] = [Build(job_name, b) for b in job['allBuilds']]
|
||||||
print('{} has {} builds'.format(job_name, len(self.builds[job_name])))
|
print('{} has {} builds'.format(job_name, len(self.builds[job_name])))
|
||||||
|
|
||||||
def create_day_statistics(self):
|
def create_statistics(self, group_by: str):
|
||||||
build_day = {}
|
|
||||||
# only look at Phab
|
# only look at Phab
|
||||||
for job_name, builds in self.builds.items():
|
for job_name, builds in self.builds.items():
|
||||||
print('Writing data for {}'.format(job_name))
|
print('Writing data for {}'.format(job_name))
|
||||||
|
# TODO: add success/failure rates
|
||||||
fieldnames = ['date', '# builds', 'median duration', 'p90 duration', 'p95 duration', 'max duration']
|
fieldnames = ['date', '# builds', 'median duration', 'p90 duration', 'p95 duration', 'max duration']
|
||||||
csv_file = open('tmp/jenkins_{}.csv'.format(job_name), 'w')
|
csv_file = open('tmp/jenkins_{}_{}.csv'.format(job_name, group_by), 'w')
|
||||||
writer = csv.DictWriter(csv_file, fieldnames=fieldnames, dialect=csv.excel)
|
writer = csv.DictWriter(csv_file, fieldnames=fieldnames, dialect=csv.excel)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
build_hist = {}
|
||||||
for build in builds:
|
for build in builds:
|
||||||
build_day.setdefault(build.day, []).append(build)
|
build_hist.setdefault(getattr(build, group_by), []).append(build)
|
||||||
|
|
||||||
for day in sorted(build_day.keys()):
|
for key in sorted(build_hist.keys()):
|
||||||
builds = build_day[day] # type: List[Build]
|
builds = build_hist[key] # type: List[Build]
|
||||||
durations = numpy.array([b.duration.seconds for b in builds])
|
durations = numpy.array([b.duration.seconds for b in builds])
|
||||||
writer.writerow({
|
writer.writerow({
|
||||||
'date': day,
|
'date': key,
|
||||||
'# builds': len(builds),
|
'# builds': len(builds),
|
||||||
'median duration': numpy.median(durations)/60,
|
'median duration': numpy.median(durations)/60,
|
||||||
'p90 duration': numpy.percentile(durations, 90)/60,
|
'p90 duration': numpy.percentile(durations, 90)/60,
|
||||||
|
|
Loading…
Reference in a new issue