클라이언트 - 범위 지정, 전역

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기6분
  • 클라이언트 API는 데이터베이스에 데이터를 MetricBase 추가하고, 데이터베이스에서 변환을 MetricBase 실행하고, 변환 결과를 수신하는 메서드를 제공합니다.

    Client 클래스는 범위가 지정된 서버 스크립트와 전역 서버 스크립트 모두에서 사용할 수 있습니다. 이 클래스는 애플리케이션의 일부 MetricBase 이며 sn_clotho 네임스페이스 내에서 실행되어야 합니다.

    클라이언트 - Client()

    데이터베이스에 액세스할 MetricBase 클라이언트 클래스의 인스턴스를 만듭니다.

    표 1. 매개변수
    이름 유형 설명
    안 함
    var client = new sn_clotho.Client();

    클라이언트 - 누적(GlideRecord now_GR, 문자열 메트릭)

    지정된 타임스탬프에 메트릭 값을 누적하고 값을 덮어쓰지 않고 결과를 데이터베이스에 저장합니다.

    이 방법 사용 사용하여 킬로와트시(kWhs)의 전기와 같이 누적에 대해 합산할 수 있는 메트릭을 처리합니다. Accumulate는 제공된 타임스탬프에서 각 메트릭을 호출합니다. 예를 들어, 히터, 전기 주전자 및 세탁기에 대해 수집된 킬로와트는 3개의 호출이 누적됩니다.

    표 2. 매개변수
    이름 유형 설명
    now_GR GlideRecord 누적 값을 구할 GlideRecord 계열의 이름입니다.

    참고 항목: getSeries()

    default_value 번호 옵션입니다. 지정된 타임스탬프의 누적에 대한 기본값입니다. 지정된 타임스탬프에 값을 사용할 수 없는 경우 누적하기 위해 첫 번째 호출 중에만 사용됩니다.

    사용 사례에서 total_power에 대한 와트 메트릭을 누적할 수 있습니다. 측정할 파워 미터가 없는 콘센트에 연결된 라우터의 와트를 축적하려고 합니다. 소비 값을 알고 있고 상수인 경우) 상수 값을 기본값으로 사용하여 total_power 누적할 수 있습니다. 예를 들어, 라우터가 지속적으로 연결되어 있고 20와트를 소비하는 경우 20을 사용합니다.

    타임스탬프 값은 DataBuilder API를 사용하여 제공할 수 있습니다.

    기본값: 0

    표 3. 반환
    유형 설명
    안 함

    다음 예시에서는 building_a라는 레코드에 total_power 메트릭 값을 누적하는 방법을 보여줍니다.

    var time = new GlideDateTime();
    
    // total_power is the name of a metric within building_a which stores accumulated values
    
    var dataBuilder1 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder1.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder1, 0);
    
    var dataBuilder2 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder2.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder2, 0);
    
    var dataBuilder3 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder3.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder3, 0);
    
    // As a result of these operations client will save value of
    // 3.5+12+4.3+0(default value) at the timestamp 'time'

    클라이언트 - deleteMetric(String tableName, String metricName)

    데이터베이스의 지정된 테이블에서 지정된 메트릭을 제거합니다.MetricBase

    주:
    이 메서드는 데이터베이스에서 데이터를 MetricBase 삭제합니다. 복구 메커니즘이 없습니다.
    표 4. 매개변수
    이름 유형 설명
    tableName 문자열 지정된 메트릭을 삭제할 테이블의 이름입니다.
    metricName 문자열 메트릭 이름입니다.
    표 5. 반환
    유형 설명
    안 함

    다음 예제에서는 테이블에서 메트릭을 제거하는 방법을 보여 줍니다.

    var client = new sn_clotho.Client();
    
    // delete metric (Speed) from the Drones table
    client.deleteMetric("mb_demo_drone", "mb_demo_mt_speed");

    클라이언트 - deleteSeries(GlideRecord now_GR, String metric)

    지정된 GlideRecord의 지정된 메트릭과 연결된 데이터베이스의 데이터를 MetricBase 제거합니다. 테스트 데이터를 제거하는 데 이 방법을 사용합니다.

    주:
    이 메서드는 데이터베이스에서 데이터를 MetricBase 삭제합니다. 복구 메커니즘이 없습니다.
    표 6. 매개변수
    이름 유형 설명
    now_GR GlideRecord 지정된 메트릭에 대한 시계열 데이터를 삭제할 기록입니다.
    메트릭 문자열 메트릭 이름입니다.
    표 7. 반환
    유형 설명
    void
    var client = new sn_clotho.Client();
    //query drones of a specific model
    var drones = new GlideRecord("mb_demo_drone");
    drones.addQuery("model", "Kingfisher Phantom");
    drones.query();
    
    client.deleteSeries(drones, 'mb_demo_mt_speed');

    클라이언트 - getSeries(GlideRecord now_GR, String metricName, GlideDateTime lastUpdateBefore)

    특정 차원에서 모든 계열을 가져옵니다.

    표 8. 매개변수
    이름 유형 설명
    now_GR GlideRecord 계열을 가져올 기록입니다.
    메트릭 문자열 메트릭 이름입니다.
    lastUpdateBefore Glide날짜/시간 옵션입니다. 평가할 기간의 끝을 나타내는 미래 날짜입니다.
    표 9. 반환
    유형 설명
    배열 지정된 메트릭에 대한 데이터가 포함된 계열을 나타내는 문자열 sys_ids 목록입니다. lastUpdateBefore 매개 변수가 제공되면 lastUpdateBefore 날짜(포함되지 않음)보다 최신의 데이터가 없는 계열을 반환합니다.

    다음 예제에서는 드론 [mb_demo_drone] 테이블에 나열된 속도 값의 전체 목록을 가져오는 방법을 보여 줍니다.

    var client = new sn_clotho.Client();
    
    // query subject records
    var grDrone = new GlideRecord('mb_demo_drone');
    grDrone.query();
    
    var series = client.getSeries(grDrone,'mb_demo_mt_speed');

    클라이언트 - put(Object metricData)

    메트릭 데이터를 MetricBase 데이터베이스에 저장합니다.

    표 10. 매개변수
    이름 유형 설명
    metricData 객체 다음 중 하나입니다.
    • 메트릭 데이터를 포함하는 DataBuilder 객체입니다.
    • 메트릭 데이터를 포함하는 DataBuilder 객체의 배열입니다.
    표 11. 반환
    유형 설명
    void
    var time = new GlideDateTime();
    ​
    // two different GlideRecord instances and metrics
    var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');
    dataBuilder.add(time, 0.6);
    ​
    var dataBuilder2 = new sn_clotho.DataBuilder(gr2, 'disk_free_percentage');
    dataBuilder2.add(time, 0.2);
    ​
    new sn_clotho.Client().put([dataBuilder,dataBuilder2]);