简体   繁体   中英

Requests per second, per hour, per day out of a time series

I am relatively new to R, and it's the first time I am trying to use it to actually analyze some data. The problem is the following: I have a CSV file containing a log of the number of requests served a given system in the following form:

# Unix timestamp, number of requests
1354810257,241624
1354810258,244759
1354810259,245307
1354810260,248961

At the moment the file contains the information relative to a week period. Now I need to obtain a graph showing how many requests per second, per hour and per day the system is able to sustain.

I solved it using Python and matplotlib. The code is something similar to this:

import csv
from pylab import *
from itertools import groupby

def by_hour(value):
    return value[0] // 3600

def plot_data_for(data, map_, reduce_):
    keys = []
    values = []
    for k,v in groupby(data, key=map_):
        keys.append(k)
        values.append(reduce_(v))
    return (keys, values)

times = []
requests = []
reader = csv.reader(open("results.csv"))

for row in reader:
    times.append(int(row[0]))
    requests.append(int(row[1]))

increments = map(lambda x: x[1] - x[0], zip(requests, requests[1:] + [requests[-1]]))
plot(*plot_data_for(zip(times, increments), by_hour, lambda values: sum(map(lambda x: x[1], values))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM