github.com/jaylevin/jenkins-library@v1.230.4/documentation/docs/steps/influxWriteData.md (about)

     1  # ${docGenStepName}
     2  
     3  ## ${docGenDescription}
     4  
     5  ## Prerequisites
     6  
     7  ### Setting up InfluxDB with Grafana
     8  
     9  The easiest way to start with is using the available official docker images.
    10  You can either run these docker containers on the same host on which you run your Jenkins or each docker on individual VMs (hosts).
    11  Very basic setup can be done like that (with user "admin" and password "adminPwd" for both InfluxDB and Grafana):
    12  
    13      docker run -d -p 8083:8083 -p 8086:8086 --restart=always --name influxdb -v /var/influx_data:/var/lib/influxdb influxdb
    14      docker run -d -p 3000:3000 --name grafana --restart=always --link influxdb:influxdb -e "GF_SECURITY_ADMIN_PASSWORD=adminPwd" grafana/grafana
    15  
    16  For more advanced setup please reach out to the respective documentation:
    17  
    18  - InfluxDB ([Docker Hub](https://hub.docker.com/_/influxdb/) [GitHub](https://github.com/docker-library/docs/tree/master/influxdb))
    19  - Grafana ([Docker Hub](https://hub.docker.com/r/grafana/grafana/) [GitHub](https://github.com/grafana/grafana-docker))
    20  
    21  After you have started your InfluxDB docker you need to create a database:
    22  
    23  - in a Webbrowser open the InfluxDB Web-UI using the following URL: <host of your docker>:8083 (port 8083 is used for access via Web-UI, for Jenkins you use port 8086 to access the DB)
    24  - create new DB (the name of this DB you need to provide later to Jenkins)
    25  - create Admin user (this user you need to provide later to Jenkins)
    26  
    27  !!! hint "With InfluxDB version 1.1 the InfluxDB Web-UI is deprecated"
    28  
    29  You can perform the above steps via commandline:
    30  
    31  - The following command will create a database with name <databasename>
    32  
    33    `curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE \<databasename\>"`
    34  
    35  - The admin user with the name &lt;adminusername&gt; and the password &lt;adminuserpwd&gt; can be created with
    36  
    37    `curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE USER \<adminusername\> WITH PASSWORD '\<adminuserpwd\>' WITH ALL PRIVILEGES"`
    38  
    39  Once you have started both docker containers and Influx and Grafana are running you need to configure the Jenkins Plugin according to your settings.
    40  
    41  ## Pipeline configuration
    42  
    43  To setup your Jenkins you need to do two configuration steps:
    44  
    45  1. Configure Jenkins (via Manage Jenkins)
    46  1. Adapt pipeline configuration
    47  
    48  ### Configure Jenkins
    49  
    50  Once the plugin is available in your Jenkins:
    51  
    52  - go to "Manage Jenkins" > "Configure System" > scroll down to section "influxdb target"
    53  - maintain Influx data
    54  
    55  !!! note "Jenkins as a Service"
    56      For Jenkins as a Service instances this is already preset to the local InfluxDB with the name `jenkins`. In this case there is not need to do any additional configuration.
    57  
    58  ### Adapt pipeline configuration
    59  
    60  You need to define the influxDB server in your pipeline as it is defined in the InfluxDb plugin configuration (see above).
    61  
    62  ```properties
    63  influxDBServer=jenkins
    64  ```
    65  
    66  ## ${docGenParameters}
    67  
    68  ## ${docGenConfiguration}
    69  
    70  ## ${docJenkinsPluginDependencies}
    71  
    72  ## Example
    73  
    74  ```groovy
    75  influxWriteData script: this
    76  ```
    77  
    78  ## Work with InfluxDB and Grafana
    79  
    80  You can access your **Grafana** via Web-UI: &lt;host of your grafana(-docker)&gt;:&lt;port3000&gt;
    81  (or another port in case you have defined another one when starting your docker)
    82  
    83  As a first step you need to add your InfluxDB as Data source to your Grafana:
    84  
    85  - Login as user admin (PW as defined when starting your docker)
    86  - in the navigation go to data sources -> add data source:
    87    - name
    88    - type: InfluxDB
    89    - Url: `http://<host of your InfluxDB server>:<port>`
    90    - Access: direct (not via proxy)
    91    - database: `<name of the DB as specified above>`
    92    - User: `<name of the admin user as specified in step above>`
    93    - Password: `<password of the admin user as specified in step above>`
    94  
    95  !!! note "Jenkins as a Service"
    96      For Jenkins as a Service the data source configuration is already available.
    97  
    98      Therefore no need to go through the data source configuration step unless you want to add additional data sources.
    99  
   100  ## Data collected in InfluxDB
   101  
   102  The Influx plugin collects following data in the project "Piper" context:
   103  
   104  - All data as per default [InfluxDB plugin capabilities](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin)
   105  - Additional data collected via `InfluxData.addField(measurement, key, value)`
   106  
   107  !!! note "Add custom information to your InfluxDB"
   108      You can simply add custom data collected during your pipeline runs via available data objects.
   109      Example:
   110  
   111      ```groovy
   112      //add data to measurement jenkins_custom_data - value can be a String or a Number
   113      commonPipelineEnvironment.setInfluxCustomDataProperty('myProperty', 2018)
   114      ```
   115  
   116  ### Collected InfluxDB measurements
   117  
   118  Measurements are potentially pre-fixed - see parameter `influxPrefix` above.
   119  
   120  | Measurement name | data column | description |
   121  | ---------------- | ----------- | ----------- |
   122  | **All measurements** |<ul><li>build_number</li><li>project_name</li></ul>| All below measurements will have these columns. <br />Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin)|
   123  | jenkins_data | <ul><li>build_result</li><li>build_time</li><li>last_successful_build</li><li>tests_failed</li><li>tests_skipped</li><li>tests_total</li><li>...</li></ul> | Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin)|
   124  | cobertura_data | <ul><li>cobertura_branch_coverage_rate</li><li>cobertura_class_coverage_rate</li><li>cobertura_line_coverage_rate</li><li>cobertura_package_coverage_rate</li><li>...</li></ul>  | Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin) |
   125  | jacoco_data | <ul><li>jacoco_branch_coverage_rate</li><li>jacoco_class_coverage_rate</li><li>jacoco_instruction_coverage_rate</li><li>jacoco_line_coverage_rate</li><li>jacoco_method_coverage_rate</li></ul>  | Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin) |
   126  | performance_data | <ul><li>90Percentile</li><li>average</li><li>max</li><li>median</li><li>min</li><li>error_count</li><li>error_percent</li><li>...</li></ul> | Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin) |
   127  | sonarqube_data | <ul><li>blocker_issues</li><li>critical_issues</li><li>info_issues</li><li>major_issues</li><li>minor_issues</li><li>lines_of_code</li><li>...</li></ul> | Details see [InfluxDB plugin documentation](https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin) |
   128  | jenkins_custom_data | project "Piper" fills following colums by default: <br /><ul><li>build_result</li><li>build_result_key</li><li>build_step (->step in case of error)</li><li>build_error (->error message in case of error)</li></ul> | filled by `commonPipelineEnvironment.setInfluxCustomDataProperty()` |
   129  | pipeline_data | Examples from the project "Piper" templates:<br /><ul><li>build_duration</li><li>opa_duration</li><li>deploy_test_duration</li><li>deploy_test_duration</li><li>fortify_duration</li><li>release_duration</li><li>...</li></ul>| filled by step [`measureDuration`](durationMeasure.md) using parameter `measurementName`|
   130  | step_data | Considered, e.g.:<br /><ul><li>build_url</li><li>bats</li><li>checkmarx</li><li>fortify</li><li>gauge</li><li>nsp</li><li>snyk</li><li>sonar</li><li>...</li></ul>| filled by `InfluxData.addField('step_data', key, value)` |
   131  
   132  ### Examples for InfluxDB queries which can be used in Grafana
   133  
   134  !!! caution "Project Names containing dashes (-)"
   135      The InfluxDB plugin replaces dashes (-) with underscores (\_).
   136  
   137      Please keep this in mind when specifying your project_name for a InfluxDB query.
   138  
   139  #### Example 1: Select last 10 successful builds
   140  
   141  ```sql
   142  select top(build_number,10), build_result from jenkins_data WHERE build_result = 'SUCCESS'
   143  ```
   144  
   145  #### Example 2: Select last 10 step names of failed builds
   146  
   147  ```sql
   148  select top(build_number,10), build_result, build_step from jenkins_custom_data WHERE build_result = 'FAILURE'
   149  ```
   150  
   151  #### Example 3: Select build duration of step for a specific project
   152  
   153  ```sql
   154  select build_duration / 1000 from "pipeline_data" WHERE project_name='PiperTestOrg_piper_test_master'
   155  ```
   156  
   157  #### Example 4: Get transparency about successful/failed steps for a specific project
   158  
   159  ```sql
   160  select top(build_number,10) AS "Build", build_url, build_quality, fortify, gauge, vulas, opa from step_data WHERE project_name='PiperTestOrg_piper_test_master'
   161  ```
   162  
   163  !!! note
   164      With this query you can create transparency about which steps ran successfully / not successfully in your pipeline and which ones were not executed at all.
   165  
   166      By specifying all the steps you consider relevant in your select statement it is very easy to create this transparency.