Class GrafanaClient

java.lang.Object
io.nosqlbench.engine.clients.grafana.GrafanaClient

public class GrafanaClient extends Object
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cacheApiToken(Supplier<String> namer, String role, long ttl, Path keyfilePath, String un, String pw)
    This can be called to create an api token and store it for later use as long as you have the admin credentials for basic auth.
    POST /api/annotations Example Request: POST /api/annotations HTTP/1.1 Accept: application/json Content-Type: application/json { "dashboardId":468, "panelId":1, "time":1507037197339, "timeEnd":1507180805056, "tags":["tag1","tag2"], "text":"Annotation Description" } Example Response: HTTP/1.1 200 Content-Type: application/json { "message":"Annotation added", "id": 1, }
    createApiToken(String name, String role, long ttl)
     
    POST /api/annotations/graphite Example Request: POST /api/annotations/graphite HTTP/1.1 Accept: application/json Content-Type: application/json { "what": "Event - deploy", "tags": ["deploy", "production"], "when": 1467844481, "data": "deploy of master branch happened at Wed Jul 6 22:34:41 UTC 2016" } Example Response: HTTP/1.1 200 Content-Type: application/json { "message":"Graphite annotation added", "id": 1 }
    createSnapshot(GDashboard dashboard, String snid)
     
    void
    Example Request: DELETE /api/annotations/1 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk Example Response: HTTP/1.1 200 Content-Type: application/json { "message":"Annotation deleted" }
    <T> T
    doProxyQuery(String dsname, String path, String query, com.google.gson.reflect.TypeToken<? extends T> asType)
     
    doRangeQuery(String datasource, String expr, String startSpec, String endSpec)
     
    GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100 Example Request: GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Basic YWRtaW46YWRtaW4= Query Parameters: from: epoch datetime in milliseconds. Optional. to: epoch datetime in milliseconds. Optional. limit: number. Optional - default is 100. Max limit for results returned. alertId: number. Optional. Find annotations for a specified alert. dashboardId: number. Optional. Find annotations that are scoped to a specific dashboard panelId: number. Optional. Find annotations that are scoped to a specific panel userId: number. Optional. Find annotations created by a specific user type: string. Optional. alert|annotation Return alerts or user created annotations tags: string. Optional. Use this to filter global annotations. Global annotations are annotations from an annotation data source that are not connected specifically to a dashboard or panel. To do an “AND” filtering with multiple tags, specify the tags parameter multiple times e.g. tags=tag1&tags=tag2. Example Response: HTTP/1.1 200 Content-Type: application/json [ { "id": 1124, "alertId": 0, "dashboardId": 468, "panelId": 2, "userId": 1, "userName": "", "newState": "", "prevState": "", "time": 1507266395000, "timeEnd": 1507266395000, "text": "test", "metric": "", "type": "event", "tags": [ "tag1", "tag2" ], "data": {} }, { "id": 1123, "alertId": 0, "dashboardId": 468, "panelId": 2, "userId": 1, "userName": "", "newState": "", "prevState": "", "time": 1507265111000, "text": "test", "metric": "", "type": "event", "tags": [ "tag1", "tag2" ], "data": {} } ]
     
     
     
     
     
     
     
    void
    PATCH /api/annotations/:id Updates one or more properties of an annotation that matches the specified id. This operation currently supports updating of the text, tags, time and timeEnd properties. Example Request: PATCH /api/annotations/1145 HTTP/1.1 Accept: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk Content-Type: application/json { "text":"New Annotation Description", "tags":["tag6","tag7","tag8"] } Example Response: HTTP/1.1 200 Content-Type: application/json { "message":"Annotation patched" }
    resolveAllTplValues(List<GTemplate> tpls, String timeStart, String timeEnd)
     
    resolveTplValues(GTemplate tpl, String timeStart, String timeEnd, List<GDataSource> dss)
     
    void
    PUT /api/annotations/:id Updates all properties of an annotation that matches the specified id. To only update certain property, consider using the Patch Annotation operation. Example Request: PUT /api/annotations/1141 HTTP/1.1 Accept: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk Content-Type: application/json { "time":1507037197339, "timeEnd":1507180805056, "text":"Annotation Description", "tags":["tag3","tag4","tag5"] } Example Response: HTTP/1.1 200 Content-Type: application/json { "message":"Annotation updated" }

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getConfig

      public GrafanaClientConfig getConfig()
    • findAnnotations

      public List<GAnnotation> findAnnotations(By... by)
      
       GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100
      
       Example Request:
      
       GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100 HTTP/1.1
       Accept: application/json
       Content-Type: application/json
       Authorization: Basic YWRtaW46YWRtaW4=
       Query Parameters:
      
       from: epoch datetime in milliseconds. Optional.
       to: epoch datetime in milliseconds. Optional.
       limit: number. Optional - default is 100. Max limit for results returned.
       alertId: number. Optional. Find annotations for a specified alert.
       dashboardId: number. Optional. Find annotations that are scoped to a specific dashboard
       panelId: number. Optional. Find annotations that are scoped to a specific panel
       userId: number. Optional. Find annotations created by a specific user
       type: string. Optional. alert|annotation Return alerts or user created annotations
       tags: string. Optional. Use this to filter global annotations. Global annotations are annotations from an annotation data source that are not connected specifically to a dashboard or panel. To do an “AND” filtering with multiple tags, specify the tags parameter multiple times e.g. tags=tag1&tags=tag2.
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
       [
           {
               "id": 1124,
               "alertId": 0,
               "dashboardId": 468,
               "panelId": 2,
               "userId": 1,
               "userName": "",
               "newState": "",
               "prevState": "",
               "time": 1507266395000,
               "timeEnd": 1507266395000,
               "text": "test",
               "metric": "",
               "type": "event",
               "tags": [
                   "tag1",
                   "tag2"
               ],
               "data": {}
           },
           {
               "id": 1123,
               "alertId": 0,
               "dashboardId": 468,
               "panelId": 2,
               "userId": 1,
               "userName": "",
               "newState": "",
               "prevState": "",
               "time": 1507265111000,
               "text": "test",
               "metric": "",
               "type": "event",
               "tags": [
                   "tag1",
                   "tag2"
               ],
               "data": {}
           }
       ]
       
      Parameters:
      by -
      Returns:
    • createAnnotation

      public GAnnotation createAnnotation(GAnnotation gAnnotation)
      
       POST /api/annotations
      
       Example Request:
      
       POST /api/annotations HTTP/1.1
       Accept: application/json
       Content-Type: application/json
      
       {
         "dashboardId":468,
         "panelId":1,
         "time":1507037197339,
         "timeEnd":1507180805056,
         "tags":["tag1","tag2"],
         "text":"Annotation Description"
       }
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
      
       {
           "message":"Annotation added",
           "id": 1,
       }
       
      Returns:
    • findDashboards

      public List<GDashboardInfo> findDashboards()
    • findSnapshotBykey

      public GSnapshot findSnapshotBykey(String snapshotKey)
    • findSnapshotBykeyOptionally

      public Optional<GSnapshot> findSnapshotBykeyOptionally(String snapshotKey)
    • findSnapshots

      public List<GSnapshotInfo> findSnapshots()
    • getDashboardByUid

      public GDashboardResponse getDashboardByUid(String uid)
    • createSnapshot

      public GSnapshotInfo createSnapshot(GDashboard dashboard, String snid)
    • createGraphiteAnnotation

      public GAnnotation createGraphiteAnnotation()
      
       POST /api/annotations/graphite
      
       Example Request:
      
       POST /api/annotations/graphite HTTP/1.1
       Accept: application/json
       Content-Type: application/json
      
       {
         "what": "Event - deploy",
         "tags": ["deploy", "production"],
         "when": 1467844481,
         "data": "deploy of master branch happened at Wed Jul 6 22:34:41 UTC 2016"
       }
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
      
       {
           "message":"Graphite annotation added",
           "id": 1
       }
       
      Returns:
    • updateAnnotation

      public void updateAnnotation()
      
       PUT /api/annotations/:id
      
       Updates all properties of an annotation that matches the specified id. To only update certain property, consider using the Patch Annotation operation.
      
       Example Request:
      
       PUT /api/annotations/1141 HTTP/1.1
       Accept: application/json
       Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
       Content-Type: application/json
      
       {
         "time":1507037197339,
         "timeEnd":1507180805056,
         "text":"Annotation Description",
         "tags":["tag3","tag4","tag5"]
       }
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
      
       {
           "message":"Annotation updated"
       }
       
    • patchAnnotation

      public void patchAnnotation()
      
       PATCH /api/annotations/:id
      
       Updates one or more properties of an annotation that matches the specified id.
      
       This operation currently supports updating of the text, tags, time and timeEnd properties.
      
       Example Request:
      
       PATCH /api/annotations/1145 HTTP/1.1
       Accept: application/json
       Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
       Content-Type: application/json
      
       {
         "text":"New Annotation Description",
         "tags":["tag6","tag7","tag8"]
       }
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
      
       {
           "message":"Annotation patched"
       }
       
    • deleteAnnotation

      public void deleteAnnotation(long id)
      
       Example Request:
      
       DELETE /api/annotations/1 HTTP/1.1
       Accept: application/json
       Content-Type: application/json
       Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
       Example Response:
      
       HTTP/1.1 200
       Content-Type: application/json
      
       {
           "message":"Annotation deleted"
       }
       
      Parameters:
      id -
    • cacheApiToken

      public void cacheApiToken(Supplier<String> namer, String role, long ttl, Path keyfilePath, String un, String pw)
      This can be called to create an api token and store it for later use as long as you have the admin credentials for basic auth. This is preferred to continuing to passing basic auth for admin privileges. The permissions can now be narrowed or managed in a modular way.
      Parameters:
      namer - the principal name for the privelege
      role - the Grafana role
      ttl - Length of validity for the granted api token
      keyfilePath - The path of the token. If it is present it will simply be used.
      un - The basic auth username for the Admin role
      pw - The basic auth password for the Admin role
    • createApiToken

      public ApiToken createApiToken(String name, String role, long ttl)
    • doProxyQuery

      public <T> T doProxyQuery(String dsname, String path, String query, com.google.gson.reflect.TypeToken<? extends T> asType)
    • resolveAllTplValues

      public Map<String,Set<String>> resolveAllTplValues(List<GTemplate> tpls, String timeStart, String timeEnd)
    • resolveTplValues

      public Set<String> resolveTplValues(GTemplate tpl, String timeStart, String timeEnd, List<GDataSource> dss)
    • getDatasources

      public List<GDataSource> getDatasources()
    • doRangeQuery

      public GRangeResult doRangeQuery(String datasource, String expr, String startSpec, String endSpec)