使用Grafana上的InfluxDB计算每秒请求数

时间:2016-06-04 13:51:40

标签: influxdb grafana

我使用telegraf插件nginx来读取Nginx的基本状态信息(ngx_http_stub_status_module)

这是我的查询

request per second query

raw sql:

SELECT derivative(mean("requests"), 1s) FROM "nginx" WHERE $timeFilter GROUP BY time($interval) fill(null)

这是我的数据

time            accepts active  handled host    port    reading requests    server      waitingwriting
1464921070000000000 7   1   7   hysm    80  0   17      localhost   0   1
1464921080000000000 8   1   8   hysm    80  0   19      localhost   0   1
1464921090000000000 8   1   8   hysm    80  0   20      localhost   0   1
1464921100000000000 8   1   8   hysm    80  0   21      localhost   0   1

但是requestPerSecond是0.083,我的查询有什么问题?

request per second graph

1 个答案:

答案 0 :(得分:2)

假设您正在处理某个计数器,那么您想要的查询是

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<math.h>
#include<unistd.h>

struct node
{   int info;
    struct node *link;
};
typedef struct node m;

m *search(int,m*);
m *del(int,m*);
m *ins(int,int,m*);
int posof(int,m*);


int readt(m *t_c,char path[])
{   int t,szt=0;
    FILE *tfile;
    char ch;
    char filename[]="/temp.txt";
    strcat(path,filename);
    tfile=fopen(path,"r");
    if(tfile==NULL)
        exit(0);
    fseek(tfile, 0, SEEK_END);
    szt = ftell(tfile);
    fseek(tfile,0,SEEK_SET);
    if(szt!=0)
    {   while(1)
        {   fscanf(tfile,"%d%c",&t,&ch);
            t_c->info=t;
            t_c->link=(m*)malloc(sizeof(m));
            //printf("%d ",t_c->info);
            t_c=t_c->link;
            if(ch==';')
                break;
        }       
    }
    t_c->link=NULL;
    //free(t_c);
    fclose(tfile);
    return 0;
}
m *search(int Noftarget,m *t_c)
{   int i,p1,p2;
    srand(time(NULL));
    for(i=0;i<100;i++)
    {   p1=(1+rand()%(Noftarget));
        p2=(1+rand()%(Noftarget));
        t_c=del(p1,t_c);
        t_c=ins(p1,p2,t_c);
        break;
    }
    return t_c;
}
m *del(int target,m *t_h)
{   m *t_c;
    int j=1,i;
    t_c=t_h;
    i=posof(target,t_h);
    if(i==1)
    {   free(t_c);
        t_c=t_c->link;
        t_h=t_c;
    }
    else
    {   while(j<i-1)
        {   t_c=t_c->link;
            j++;
        }
        free(t_c->link);
        t_c->link=t_c->link->link;
    }
    return t_h;
}
m *ins(int target,int position,m *t_h)
{   int j=0;
    m *swaptarget,*t_c;
    t_c=t_h;
    swaptarget=(m*)malloc(sizeof(m));
    swaptarget->info=target;
    if(position==1)
    {   swaptarget->link=t_c;
        t_h=swaptarget;
    }
    else
    {   while(j<position-2)
        {   t_c=t_c->link;
            j++;
        }
        swaptarget->link=t_c->link;
        t_c->link=swaptarget;
    }
    return t_h;
}
int posof(int p1,m *t_c)
{   int i=1,a=0;
    while(t_c->link!=NULL)
    {   if(p1==t_c->info)
        {   a=i;
            break;
        }
        t_c=t_c->link;
        i++;
    }
    return a;
}

int main()
{   int Noftarget=7,j,r=1,count=0,noi,szd_n=0,i=0,sz;
    char cwd[200];
    m *t_h;
    getcwd(cwd, sizeof(cwd));
    t_h=(m*)malloc(sizeof(m));
    readt(t_h,cwd);
    print_tsp(t_h);
    t_h=search(Noftarget,t_h);
    print_tsp(t_h);
    while(t_h!=NULL)
    {   free(t_h);
        t_h=t_h->link;
    }
    return 0;
}