File

src/app/shared/grafana/grafana.service.ts

Description

Grafana Service.

Example

Index

Methods

Constructor

constructor(sharedAboutService: SharedAboutService)

Constructor

Parameters :
Name Type Optional Description
sharedAboutService SharedAboutService

Methods

getDashboardApplication
getDashboardApplication(streamName: string, appName: string)

Return an observable which contains the URL to the application dashboard

Parameters :
Name Type Optional Description
streamName string
appName string
Returns : Observable<string>
getDashboardApplicationInstance
getDashboardApplicationInstance(streamName: string, appName: string, guid: string)

Return an observable which contains the URL to the application instance dashboard

Parameters :
Name Type Optional Description
streamName string
appName string
guid string
Returns : Observable<string>
getDashboardStream
getDashboardStream(stream: StreamDefinition)

Return an observable which contains the URL to the stream dashboard

Parameters :
Name Type Optional Description
stream StreamDefinition
Returns : Observable<string>
getDashboardStreams
getDashboardStreams()

Return an observable which contains the URL to the streams dashboard

Returns : Observable<string>
isAllowed
isAllowed()

Return an observable which contains a boolean True if Grafana is enabled

Returns : Observable<boolean>
import { Injectable } from '@angular/core';
import { StreamDefinition } from '../../streams/model/stream-definition';
import { Observable, of } from 'rxjs';
import { SharedAboutService } from '../services/shared-about.service';
import { map } from 'rxjs/operators';
import { FeatureInfo } from '../model/about/feature-info.model';
import { AboutInfo } from '../model/about/about-info.model';
import { GrafanaInfo } from '../model/about/grafana.model';

/**
 * Grafana Service.
 *
 * @author Damien Vitrac
 */
@Injectable()
export class GrafanaService {

  /**
   * Constructor
   * @param sharedAboutService
   */
  constructor(private sharedAboutService: SharedAboutService) {
  }

  /**
   * Return an observable which contains a boolean
   * True if Grafana is enabled
   */
  isAllowed(): Observable<boolean> {
    return this.sharedAboutService
      .getFeatureInfo()
      .pipe(map((featuredInfo: FeatureInfo) => featuredInfo.grafanaEnabled));
  }

  /**
   * Return an observable which contains the URL to the streams dashboard
   */
  getDashboardStreams(): Observable<string> {
    return this.sharedAboutService
      .getAboutInfo()
      .pipe(
        map((aboutInfo: AboutInfo): GrafanaInfo => aboutInfo.grafanaInfo),
        map((grafanaInfo: GrafanaInfo): string => {
          return grafanaInfo.url + '/d/scdf-streams/streams?refresh=' + grafanaInfo.refreshInterval + 's';
        })
      );
  }

  /**
   * Return an observable which contains the URL to the stream dashboard
   * @param {StreamDefinition} stream
   */
  getDashboardStream(stream: StreamDefinition): Observable<string> {
    return this.sharedAboutService
      .getAboutInfo()
      .pipe(
        map((aboutInfo: AboutInfo): GrafanaInfo => aboutInfo.grafanaInfo),
        map((grafanaInfo: GrafanaInfo): string => {
          return grafanaInfo.url + '/d/scdf-applications/applications?refresh=' + grafanaInfo.refreshInterval +
            's&var-stream_name=' + stream.name + '&var-application_name=All';
        })
      );
  }

  /**
   * Return an observable which contains the URL to the application dashboard
   * @param streamName
   * @param appName
   */
  getDashboardApplication(streamName: string, appName: string): Observable<string> {
    return this.sharedAboutService
      .getAboutInfo()
      .pipe(
        map((aboutInfo: AboutInfo): GrafanaInfo => aboutInfo.grafanaInfo),
        map((grafanaInfo: GrafanaInfo): string => {
          return grafanaInfo.url + '/d/scdf-applications/applications?refresh=' + grafanaInfo.refreshInterval +
            's&var-stream_name=' + streamName + '&var-application_name=' + appName + '&var-name=All';
        })
      );
  }

  /**
   * Return an observable which contains the URL to the application instance dashboard
   * @param streamName
   * @param appName
   * @param guid
   */
  getDashboardApplicationInstance(streamName: string, appName: string, guid: string): Observable<string> {
    return this.sharedAboutService
      .getAboutInfo()
      .pipe(
        map((aboutInfo: AboutInfo): GrafanaInfo => aboutInfo.grafanaInfo),
        map((grafanaInfo: GrafanaInfo): string => {
          return grafanaInfo.url + '/d/scdf-applications/applications?refresh=' + grafanaInfo.refreshInterval +
            's&var-stream_name=' + streamName + '&var-application_name=' + appName +
            '&var-name=All&var-application_guid=' + guid;
        })
      );
  }

}

results matching ""

    No results matching ""