Kairosdb 설치 및 셋팅

[kairosdb 설치방법]
  1. Download the tar.gz file from the Downloads section
  2. (https://github.com/kairosdb/kairosdb/releases) 여기서 다운로드
  3. 압축 해제 (tar -xzvf kairosdb-1.1.3-1.tar.gz)
  4. conf/kairosdb.properties이름을 kairosdb.service.datastore 로 바꾸기 (cp kairosdb.properties kairosdb.service.datastore 이걸로 걍 저장해놓음???) In conf/kairosdb.properties change the kairosdb.service.datastore property to the datastore you wish to use. It defaults to an in memory H2 database (that is slow)
  5. H2가 기본인데 느리다 cassandra나 딴거로 바꿔주자 –>  kairosdb.service.datastore=org.kairosdb.datastore.cassandra.CassandraModule ()
    ( 카산드라로 할거면 카산드라 설치되어야함 )
  6. Make sure that JAVA_HOME is set to your java install.
  7. Change to the bin directory and run >./kairosdb.sh run
  8. 백그라운드로 실행하려면  sudo ./kairosdb.sh start
sudo ./kairosdb.sh start
sudo 로 안하면 log 파일 Permission denied뜸
Starting and Stopping

Starting and stoping KairosDB is done by running the kairosdb.sh script from within the bin directory.

To start KairosDB and run in the foreground type

> ./kairosdb.sh run

To run KairosDB as a background process type

> ./kairosdb.sh start

To stop KairosDB when running as a background process type

> ./kairosdb.sh stop

[web UI]
http://localhost:8080 으로 확인가능
  1. Download highcharts and save in the webroot/js directory.
  2. Uncomment the highcharts.js include line in webroot/index.html.
  3. Uncomment the highcharts.js include line in webroot/view.html.
highcharts 다운받고 압출풀고 code 안에 있는 .js 파일을 kairosdb/webroot/js 안에 넣음
webroot/index.html 에 <!– http://js/highcharts.js –> 부분 주석해제
webroot/view.html 에 <!–http://js/highcharts.js–> 부분 주석해제

[cluster]
kairosdb.datastore.cassandra.host_list=10.107.92.241:9160,10.107….
92.242:9160,10.107.92.243:9160 로 넣기 (모두 전체 다 넣어야하는지…?? -> seed 만 넣어도 잘됨)
kairosdb.service.datastore 에서 kairosdb.datastore.cassandra.hector.loadBalancingPolicy=roundRobin 으로 설정
 


 
[custom datapoint]
  1. create 2 files called ComplexDataPoint.java and ComplexDataPointFactory.java and then paste the code provided by the tutorial on the doc: https://kairosdb.github.io/docs/build/html/kairosdevelopment/CustomData.html#example-for-creating-custom-types
  2. download the KairosDB source, then extract the .zip file. tar파일로 해서 바로 리눅스에서 만들 수 있음
  3. paste the 2 files in /KAIROSDB_DOWNLOADED_SOURCE/src/main/java/org/kairosdb/core/datapoints/
  4. configure the CoreModule.java at /KAIROSDB_DOWNLOADED_SOURCE/src/main/java/org/kairosdb/core/, add the following line in the function protected void configure():
    bind(ComplexDataPointFactory.class).in(Singleton.class);
  5. open terminal, cd to KAIROSDB_DOWNLOADED_SOURCE/, then follow the instruction in the file how_to_build.txt

    export CLASSPATH= KAIROSDB_DOWNLOADED_SOURCE/ tools/tablesaw-1.2.4.jar
    java make 치면 좀 오래걸림

  6. when complete, it will create a folder called build, the compiled kairosdb jar file is located in KAIROSDB_DOWNLOADED_SOURCE/build/jar
  7. in your kairosdb installation folder, backup the kairosdb-X.X.X.jar file in YOUR_KAIROSDB_INSTALLATION/lib
    mv kairosdb-X.X.X.jar kairosdb-X.X.X.jar.backup
    
  8. mv the newly compiled jar file to YOUR_KAIROSDB_INSTALLATION/lib
  9. modify the configuration file by adding the following line:
    kairosdb.datapoints.factory.complex=org.kairosdb.core.datapoints.ComplexDataPointFactory
    
  10. restart your kairosdb

For your query, since the registered name is kairosdb.datapoints.factory.complex, replace complex-number with complex in your query string.

how_to_build.txt 내용
Building requires JDK 1.7 or later.
To build set your classpath to the tablesaw jar file like so:
>export CLASSPATH=/home/web_admin/kairosdb-1.1.3/tools/tablesaw-1.2.4.jar
Then to build type
>java make
You can also get help on what targets are available by typing
>java make help

[카산드라]
카산드라에 keyspace는 kairosdb로 저장되고
  • data_points – where the data is kept.
  • row_key_index – index to lookup what rows to get during a query.
  • string_index – used to answer the query of what tags and metrics are in the system.
다음과 같은 테이블이 있음

[send data]

  • pom 파일
<dependency>
    <groupId>org.kairosdb</groupId>
    <artifactId>kairosdb</artifactId>
    <version>1.1.3-1</version>
</dependency>
<dependency>
    <groupId>org.kairosdb</groupId>
    <artifactId>client</artifactId>
    <version>2.2.0</version>
</dependency>
  • 기본 sendMetric
publicvoidsendMetrics(String metric, String key, String value, doubledataPoint) throwsException{
        MetricBuilder builder = MetricBuilder.getInstance();
        builder.addMetric(metric)
                        .addTag(key, value)
                        .addDataPoint(System.currentTimeMillis(), dataPoint);
        HttpClient client = newHttpClient(dbUrl:8080);
        Response response = client.pushMetrics(builder);
        client.shutdown();
    }
  • 여러개 tag나 datapoint 추가 가능
publicvoidsendMetrics(String metric, String key1, String key2, String value, doubledataPoint) throwsException{
        MetricBuilder builder = MetricBuilder.getInstance();
        
        String[] valueArray = value.split(",");
        
        builder.addMetric(metric)
                        .addTag(key1, valueArray[0])
                        .addTag(key2, valueArray[1])
                        .addDataPoint(System.currentTimeMillis(), dataPoint);
        HttpClient client = newHttpClient(dbUrl);
        Response response = client.pushMetrics(builder);
        client.shutdown();
    }
 
 
publicvoidsendMetrics(String metric, Map<String, String> tags, doubledataPoint) throwsException{
        MetricBuilder builder = MetricBuilder.getInstance();
        
        builder.addMetric(metric).addTags(elem.getKey(), elem.getValue()).addDataPoint(System.currentTimeMillis(), dataPoint);
        HttpClient client = newHttpClient(dbUrl);
        Response response = client.pushMetrics(builder);
        client.shutdown();
    }
 
 
publicvoidsendMetrics(String metric, Map<Pair<String, String>, List> tags) throwsException{
        MetricBuilder builder = MetricBuilder.getInstance();
        
        for(Map.Entry<Pair<String, String>, List> elem : tags.entrySet()) {
            Pair<String, String> tag = elem.getKey();
            List dataPoint = elem.getValue();
            
            for(inti = 0; i < dataPoint.size(); i++){
                builder.addMetric(metric).addTag(tag.getFirst(), tag.getSecond()).addDataPoint(System.currentTimeMillis(), dataPoint.get(i));
            }
        }
        
        HttpClient client = newHttpClient(dbUrl);
        Response response = client.pushMetrics(builder);
        client.shutdown();
    }

 


[그라파나 연동]
플러그인 최신버전으로!! (kafirosDB가 최신이니까)
git clone git@github.com:grafana/datasource-plugin-kairosdb.git
(이게 안되면 방화벽 문제 등등으로 git clone https://github.com/grafana/kairosdb-datasource.git 이걸로)

npm install
grunt
sudo service grafana-server restart

Clone into a directory of your choice

Then edit your grafana.ini config file (Default location is at /etc/grafana/grafana.ini) and add this:

[plugin.kairosdb]
path = /home/your/clone/dir/datasource-plugin-kairosdb

Leave a comment