Exemplo n.º 1
0
        /**
         * 查询数据,返回的数据为json格式,结构为: * "[ * " { * " metric: mysql.innodb.row_lock_time, * " tags: { * " host: web01, * " dc: beijing * " }, * " aggregateTags: [], * " dps: { * " 1435716527: 1234, * " 1435716529: 2345 * " } * " }, * " { * " metric: mysql.innodb.row_lock_time, * " tags: { * " host: web02, * " dc: beijing * " }, * " aggregateTags: [], * " dps: { * " 1435716627: 3456 * " } * " } * "]"; * * @param metric 要查询的指标 * @param aggregator 查询的聚合类型, 如: OpentsdbClient.AGGREGATOR_AVG, OpentsdbClient.AGGREGATOR_SUM * @param tagMap 查询的条件 * @param downsample 采样的时间粒度, 如: 1s,2m,1h,1d,2d * @param startTime 查询开始时间,时间格式为yyyy-MM-dd HH:mm:ss * @param endTime 查询结束时间,时间格式为yyyy-MM-dd HH:mm:ss
         */
        public string getData(string metric, Dictionary <string, string> tagMap, string aggregator, string downsample, string startTime, string endTime)
        {
            QueryBuilder queryBuilder = QueryBuilder.getInstance();
            Query        query        = queryBuilder.getQuery();
            long         starttemp    = (DateTimeUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss").ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000;
            long         endtemp      = (DateTimeUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss").ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000;

            query.setStart(starttemp);
            query.setEnd(endtemp);
            List <SubQueries> sqList = new List <SubQueries>();
            SubQueries        sq     = new SubQueries();

            sq.addMetric(metric);
            sq.addTag(tagMap);
            sq.addAggregator(aggregator);
            sq.setDownsample(downsample + "-" + aggregator);
            sqList.Add(sq);
            query.setQueries(sqList);
            try
            {
                log.Info("query request:" + queryBuilder.build()); //这行起到校验作用
                SimpleHttpResponse spHttpResponse = httpClient.pushQueries(queryBuilder, ExpectResponse.DETAIL);
                log.Debug("response.content:" + spHttpResponse.getContent());
                if (spHttpResponse.isSuccess())
                {
                    return(spHttpResponse.getContent());
                }
                return(null);
            }
            catch (Exception e)
            {
                log.Error(e);
                throw e;
            }
        }
Exemplo n.º 2
0
 public Query addSubQuery(SubQueries subQueries)
 {
     this.queries.Add(subQueries);
     return(this);
 }