<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shyam Bhattarai</title>
    <description>The latest articles on DEV Community by Shyam Bhattarai (@shyambh).</description>
    <link>https://dev.to/shyambh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F90569%2Fcee85f55-b727-4060-9478-7063d04eaf12.jpg</url>
      <title>DEV Community: Shyam Bhattarai</title>
      <link>https://dev.to/shyambh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shyambh"/>
    <language>en</language>
    <item>
      <title>A Primer on Mocking gRPC services with Postman</title>
      <dc:creator>Shyam Bhattarai</dc:creator>
      <pubDate>Tue, 08 Aug 2023 10:59:48 +0000</pubDate>
      <link>https://dev.to/shyambh/a-primer-on-mocking-grpc-services-with-postman-k7d</link>
      <guid>https://dev.to/shyambh/a-primer-on-mocking-grpc-services-with-postman-k7d</guid>
      <description>&lt;p&gt;As part of increasing the overall developer productivity, it is a good practice to mock backend services so that the lead time to start the frontend related tasks including, UI/UX development, can proceed without much dependency of a fully functioning backend server.&lt;/p&gt;

&lt;p&gt;Below we can see how a gRPC request can be formed via Postman.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GSRWbzrN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://assets.postman.com/postman-docs/v10/select-protocol-v10.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GSRWbzrN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://assets.postman.com/postman-docs/v10/select-protocol-v10.gif" alt="https://assets.postman.com/postman-docs/v10/select-protocol-v10.gif" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For submitting a valid gRPC request in Postman, a service definition and the method needs to be invoked. Depending upon the service definition, extra parameters like message payloads, metadata and other details can be attached along with the request.&lt;/p&gt;

&lt;p&gt;There are two ways of setting up the service definition in Postman. One way is by uploading a .proto file and another way is by supplying the service endpoint in the URL field.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a service definition by uploading a proto file
&lt;/h3&gt;

&lt;p&gt;One way how the service definition can be instantiated in Postman is by uploading the proto file physically. This can be a good way for the engineers to test the requests in case the service is not yet deployed. &lt;/p&gt;

&lt;p&gt;For this, the proto can be uploaded as below:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Hl3oTt5vt0Y"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Keep in mind that when the Import API button is clicked, then a new API is automatically created in the APIs section in Postman. See below that a New API collection ‘New API’ is created which has a service definition as &lt;code&gt;projects.proto&lt;/code&gt; which is the uploaded proto in the previous step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qeZIs2uU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxbtuikwzjx3a95mn6zq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qeZIs2uU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxbtuikwzjx3a95mn6zq.png" alt="" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Maintaining a service definition by server reflection
&lt;/h3&gt;

&lt;p&gt;Server-reflection is a gRPC feature allowing clients to submit requests without having to have precompiled into the client side. Basically, what that means is that, if the server has server-reflection enabled, then the client can pull the available public methods by simply sending a request to the service endpoint.&lt;/p&gt;

&lt;p&gt;In the example below, we make a request to a Postman gRPC echo service &lt;code&gt;[grpc.postman-echo.com](http://grpc.postman-echo.com)&lt;/code&gt; Further info about making a gRPC request using server-reflection from Postman can be found &lt;a href="https://learning.postman.com/docs/sending-requests/grpc/first-grpc-request/#creating-and-invoking-a-request"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yXq_m7YNUAc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Sample Request and Response
&lt;/h3&gt;

&lt;p&gt;Once the service definition is available, you can click on the &lt;code&gt;Invoke&lt;/code&gt; button to invoke the remote procedures defined by the service definition. You can click on the &lt;code&gt;Use Example Messages&lt;/code&gt; button which prepares a mock message body that needs to be sent along with the request.&lt;/p&gt;

&lt;p&gt;Below is the screenshot showing the mock request and response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Uw249rl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekg2921izi8qosuvbyts.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Uw249rl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekg2921izi8qosuvbyts.jpg" alt="Mocking the gRPC" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Connecting a repository to maintain an API Lifecycle
&lt;/h3&gt;

&lt;p&gt;Even though the developer can manually feed the &lt;code&gt;proto&lt;/code&gt; files directly to Postman, a much shorter feedback loop can be achieved by directly linking a remote repository to fetch the service definitions.&lt;/p&gt;

&lt;p&gt;Moving along, we will see how we can link a Bitbucket repo to fetch the service definitions. This flow will allow both the backend and frontend teams to collaborate real-time. A typical use case for this flow can be thought of as below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The backend team prepares the &lt;code&gt;proto&lt;/code&gt; file and pushed it to the repository&lt;/li&gt;
&lt;li&gt;The frontend team can fetch the &lt;code&gt;proto&lt;/code&gt; file directly from Postman. Postman takes care of maintaining the repo status so that the service definition is always in sync with the latest changes.&lt;/li&gt;
&lt;li&gt;Based on the &lt;code&gt;proto&lt;/code&gt; files, the developer can then build a mock server. The mock server is just what the name suggests. It returns random fake data based on the latest service definition in the repo. The frontend team can then utilize this endpoint to move ahead with their development tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is the actual flow how we can fetch the service definition from the repo. We see here that after we have an active link with the repository (in this case, Bitbucket), we can see the uncommitted changes and any pending changes yet to be pulled from the remote. Please note that once the repo is connected, Postman creates a couple of internal files under &lt;code&gt;.Postman&lt;/code&gt; folder for tracking purposes. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5A1ZpbM7_ds"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Mock gRPC Servers
&lt;/h3&gt;

&lt;p&gt;Once you have created an API (from the APIs option in the sidebar), Postman allows the users to publish the API so that it can be shared within the team.&lt;/p&gt;

&lt;p&gt;In continuation from the example above, we will see how the user can create a mock server from the fetched service definition. While publishing the API, users need to &lt;a href="https://learning.postman.com/docs/designing-and-developing-your-api/versioning-an-api/versioning-an-api-overview/"&gt;version the APIs&lt;/a&gt; which is a neat feature which ensures that a proper versioning is maintained for each change in the server definition.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/1X4ovsSUghI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now we will see how to use this published API to create a mock server and submit a valid request and receive the response as dictated by the service definition.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/9kBKCeF0ekA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Postman to test the gRPC response
&lt;/h3&gt;

&lt;p&gt;Although Postman provides immense value to the development team to cut down on the lead time needed to develop features, it can also provide many different ways to test the actual responses received from the hosted service endpoints.&lt;/p&gt;

&lt;p&gt;Below, we will be invoking procedures and using the scripts to test the responses. The service endpoint for testing is an actual functional endpoint &lt;code&gt;[projects-service.prd.svc.grepsr.net](http://projects-service.prd.svc.grepsr.net)&lt;/code&gt; which allows server-reflection.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ecpE-lSHMlE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Further Reading
&lt;/h3&gt;

&lt;p&gt;Even though we try to maintain this doc for any upcoming updates in the future, you can get the latest information from the official Postman docs &lt;a href="https://learning.postman.com/docs/sending-requests/grpc/grpc-client-overview/"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>testing</category>
      <category>postman</category>
      <category>grpc</category>
    </item>
    <item>
      <title>Grafana for real time JMeter test monitoring</title>
      <dc:creator>Shyam Bhattarai</dc:creator>
      <pubDate>Thu, 24 Oct 2019 04:31:03 +0000</pubDate>
      <link>https://dev.to/shyambh/grafana-for-real-time-jmeter-test-monitoring-39hb</link>
      <guid>https://dev.to/shyambh/grafana-for-real-time-jmeter-test-monitoring-39hb</guid>
      <description>&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;The JMeter tests run are run in a periodic basis as part of the&lt;br&gt;
scheduled performance tests. The test reports including various metrics&lt;br&gt;
and details are generated after the completion of the test run. It would&lt;br&gt;
be advantageous to the team if the test status could be monitored in&lt;br&gt;
real time so that any evidence of a correlation between the failing&lt;br&gt;
components could be established.&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/v0zvwaf2755uo94chtmq.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fv0zvwaf2755uo94chtmq.jpg" alt=""&gt;
  &lt;/a&gt;


&lt;p&gt;&lt;strong&gt;Telegraf&lt;/strong&gt; : Collects the server metrics via an installed agent and stores it in InfluxDB backend&lt;br&gt;&lt;br&gt;
&lt;strong&gt;JMeter&lt;/strong&gt; : Sends the test stats to InfluxDB using BackendListener listener&lt;br&gt;&lt;br&gt;
&lt;strong&gt;InfluxDB&lt;/strong&gt; : Stores the metrics collected&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Grafana&lt;/strong&gt; : Finally, these metrics are visible via Grafana dashboards&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Grafana is an open source, real time metrics visualization tool&lt;br&gt;
which supports a plethora of &lt;a href="https://grafana.com/docs/features/datasources/#supported-data-sources" rel="noopener noreferrer"&gt;data&lt;br&gt;
sources&lt;/a&gt;&lt;br&gt;
including InfluxDB, Elasticsearch, MySQL, MSSQL, etc. The tool can&lt;br&gt;
either be ran locally or can be hosted in &lt;a href="https://grafana.com/cloud#pricing" rel="noopener noreferrer"&gt;&lt;em&gt;Grafana&lt;br&gt;
Cloud&lt;/em&gt;&lt;/a&gt; as well. For this&lt;br&gt;
documentation, we will be looking at the steps to install the tool&lt;br&gt;
locally and add other dependencies along the way. There is a nice&lt;br&gt;
collection of visualization options to show the metrics which are highly&lt;br&gt;
customizable.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Grafana&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Latest version of Grafana can be installed from&lt;br&gt;
&lt;a href="https://grafana.com/get" rel="noopener noreferrer"&gt;here&lt;/a&gt; which also provides the option to&lt;br&gt;
install it locally or use it in a hosted environment. After the&lt;br&gt;
download is complete, the service should up and Grafana should be&lt;br&gt;
available at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;InfluxDB&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After Grafana is successfully installed, the next step is to install&lt;br&gt;
 the backend service, which in this case is InfluxDB. InfluxDB is an&lt;br&gt;
 open source &lt;a href="https://www.influxdata.com/time-series-database/" rel="noopener noreferrer"&gt;time series&lt;br&gt;
 database&lt;/a&gt; which is&lt;br&gt;
 optimized for time-stamped series data and can be downloaded from&lt;br&gt;
 &lt;a href="https://portal.influxdata.com/downloads/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. After the&lt;br&gt;
 installation is complete, the folder structure is created as follows:&lt;/p&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/jh2f1m4sdvf35ojhhqqs.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjh2f1m4sdvf35ojhhqqs.jpg" alt=""&gt;
  &lt;/a&gt;


&lt;p&gt;Among these files, ‘&lt;em&gt;influx.exe&lt;/em&gt;’ is a CLI used to execute Influx Query&lt;br&gt;
Language (InfluxQL) commands and navigate the database. The&lt;br&gt;
‘&lt;em&gt;influxd.exe&lt;/em&gt;’ application is used to launch the InfluxDB server. The&lt;br&gt;
‘&lt;em&gt;influxdb.conf&lt;/em&gt;’ file is the config file that can be edited to&lt;br&gt;
configure the features. It can also be installed and run as a Windows&lt;br&gt;
service. The server needs to be up in order to access the database.&lt;br&gt;
InfluxDB also provides an http endpoint to allow interaction with the&lt;br&gt;
database. In order to enable it, the ‘influxdb.conf’ file needs to be&lt;br&gt;
edited with the changes below :&lt;/p&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/jd179jfoiydh0rpru1g5.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjd179jfoiydh0rpru1g5.jpg" alt=""&gt;Fig. Enabling the HTTP endpoint service and setting up the port address
  
  &lt;/a&gt;


&lt;p&gt;This enables the endpoint service. This can be verified with the&lt;br&gt;
PowerShell command ‘curl &lt;a href="http://localhost:8086/ping" rel="noopener noreferrer"&gt;http://localhost:8086/ping&lt;/a&gt;’. The result&lt;br&gt;
should be as below :&lt;/p&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/u15n1ir33qqpkzb396fn.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu15n1ir33qqpkzb396fn.jpg" alt=""&gt;Fig.Verifying that the InfluxDB endpoint is active

  
  &lt;/a&gt;


&lt;p&gt;First, a database needs to be created in InfluxDB to hold the sample&lt;br&gt;
data from JMeter. To do this, first the influx CLI needs to be opened.&lt;/p&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/hbuua29d93ht4sfjej3o.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhbuua29d93ht4sfjej3o.jpg" alt=""&gt;Fig.Starting the InfluxDB CLI
  
  &lt;/a&gt;


&lt;p&gt;Typing in ‘&lt;em&gt;influx&lt;/em&gt;’ will run the InfluxDB CLI. ‘&lt;em&gt;show databases&lt;/em&gt;’ can&lt;br&gt;
be used to view the existing databases. Currently, there should be just&lt;br&gt;
one database with the name ‘&lt;em&gt;_internal&lt;/em&gt;’. This database holds&lt;br&gt;
information pertaining to InfluxDB itself and is auto-generated during&lt;br&gt;
the installation. The command to create a new database is ‘&lt;em&gt;create&lt;br&gt;
database &amp;lt;database-name&amp;gt;&lt;/em&gt;’.&lt;/p&gt;

&lt;p&gt;The database is created as follows, where the database name is set up as&lt;br&gt;
&lt;strong&gt;jmeterStress&lt;/strong&gt;.&lt;/p&gt;


  &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/8i26bran6m854wukg8oo.jpg" rel="noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8i26bran6m854wukg8oo.jpg" alt=""&gt;Fig.Creating a new database
  
  &lt;/a&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Configurations&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are a couple of configurations which needs be done on JMeter as well as Grafana in order to generate the measurements and display the live results.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;JMX Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Since, the test data needs to be written to the InfluxDB in real-time, a&lt;br&gt;
‘&lt;em&gt;Backend Listener&lt;/em&gt;’ needs to be added to the existing test plan. A&lt;br&gt;
plugin&lt;br&gt;
‘&lt;a href="https://github.com/NovatecConsulting/JMeter-InfluxDB-Writer/releases/" rel="noopener noreferrer"&gt;JMeter-InfluxDB-Writer&lt;/a&gt;’&lt;br&gt;
needs to downloaded in order to write the data to InfluxDB so that the&lt;br&gt;
Grafana JMeter dashboard can integrate seamlessly without much&lt;br&gt;
configuration being needed.&lt;/p&gt;

&lt;p&gt;Below are the steps to configure the backend listener in JMeter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add the Backend Listener to the test plan&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Configure the Backend Listener as follows:&lt;/p&gt;


&lt;a href="https://thepracticaldev.s3.amazonaws.com/i/vmj1bcm24iduj12764oj.jpg" rel="noopener noreferrer"&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvmj1bcm24iduj12764oj.jpg" alt=""&gt;Fig.Configuring the BackendListener options in JMeter

&lt;/a&gt;


&lt;p&gt;‘&lt;strong&gt;testName&lt;/strong&gt;’ is the name of the test.&lt;/p&gt;

&lt;p&gt;‘&lt;strong&gt;influxDBHost&lt;/strong&gt;’ and ‘&lt;em&gt;influxDBPort&lt;/em&gt;’ are set as according to the&lt;br&gt;
InfluxDB host and port addresses.&lt;/p&gt;

&lt;p&gt;‘&lt;strong&gt;influxDBUser&lt;/strong&gt;’ and ‘&lt;em&gt;influxDBPassword&lt;/em&gt;’ are the user credentials&lt;br&gt;
for the InfluxDB.&lt;/p&gt;

&lt;p&gt;‘&lt;strong&gt;influxDBDatabase&lt;/strong&gt;’ is the target DB to store the data.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Linking Grafana and InfluxDB&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now that InfluxDB and Grafana are set up, the connection between the two&lt;br&gt;
needs to be established as well. Below are the steps to achieve this :&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Add datasource&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Navigate to &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; or wherever Grafana is being&lt;br&gt;
hosted. At the start a login page is displayed where the default&lt;br&gt;
username and password values are ‘admin’ and the password can be&lt;br&gt;
changed after the login.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/x9zruimg60vssws2ny0m.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fx9zruimg60vssws2ny0m.jpg" alt=""&gt;Fig.Grafana : Login page
    
    &lt;/a&gt;


&lt;p&gt;After the login, the user is directed towards the default dashboard.&lt;br&gt;
Currently, it holds the options to add a new data source, create a&lt;br&gt;
new dashboard, add users, etc.&lt;/p&gt;

&lt;p&gt;Click on ‘Add data source’ to configuration database connection.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/3fe10h2pwpu8ss6lj76z.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3fe10h2pwpu8ss6lj76z.jpg" alt=""&gt;Fig.Grafana : Default Dashboard
    
    &lt;/a&gt;


&lt;p&gt;Then a time series database can be selected from the list of options&lt;br&gt;
presented. After selecting ‘InfluxDB’ there, a configuration page&lt;br&gt;
opens where the specific details can be configured.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/rtrlo8s91d8l0j2ojxvs.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frtrlo8s91d8l0j2ojxvs.jpg" alt=""&gt;Fig.Data source configuration in Grafana
    
    &lt;/a&gt;


&lt;p&gt;After configuring the database details and clicking ‘&lt;strong&gt;Save &amp;amp;&lt;br&gt;
Test&lt;/strong&gt;’ button, a message saying ‘Data Source is working’ should be&lt;br&gt;
displayed.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Create a Dashboard&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The next step after configuring the data source is to create a&lt;br&gt;
dashboard. There are plenty of options to choose here as well since&lt;br&gt;
Grafana provides a great variety of dashboard template to choose&lt;br&gt;
from.&lt;/p&gt;

&lt;p&gt;This option can be selected by clicking on the ‘+’ icon at the&lt;br&gt;
top-left corner of the menu and selecting ‘&lt;strong&gt;Import&lt;/strong&gt;’ under the&lt;br&gt;
create sub-menu. For our implementation we have used&lt;br&gt;
&lt;a href="https://grafana.com/grafana/dashboards/1152" rel="noopener noreferrer"&gt;this&lt;/a&gt; dashboard which&lt;br&gt;
has all the basic visualization options. The dashboard can be&lt;br&gt;
imported by either supplying it’s dashboard ID or it’s JSON file.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/qk2h0mbd2cx3rf33lxov.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqk2h0mbd2cx3rf33lxov.jpg" alt=""&gt;Fig.Importing the dashboard template
    
    &lt;/a&gt;


&lt;p&gt;After the import is completed, a dashboard with empty visualizations&lt;br&gt;
is generated. By default, the time period filter for which the&lt;br&gt;
report is to be shown will be ‘&lt;strong&gt;Yesterday&lt;/strong&gt;’ with a ‘&lt;strong&gt;Aggregation&lt;br&gt;
Interval&lt;/strong&gt;’ of 1 minute. The ‘Aggregation Interval’ is the interval&lt;br&gt;
at which the data is fetched from the backend. Here, we change it to&lt;br&gt;
1s to collect the data every second. Also, we change the time filter&lt;br&gt;
from ‘Yesterday’ to ‘Last 5 minutes’ to show the latest results.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/92akkyu8beyb92vdj56y.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F92akkyu8beyb92vdj56y.jpg" alt=""&gt;Fig.Changing the ‘Aggregation Interval’ to 1s and time
filter to ‘Last 5 minutes’
    
    &lt;/a&gt;


&lt;p&gt;&lt;strong&gt;Running the JMeter Tests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To verify whether the set up is successful, the JMeter test plan can&lt;br&gt;
be run. As soon as the test are running, the commands below can be&lt;br&gt;
used to verify if the data are getting stored in InfluxDB.&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/gqw64lkom5pk3qgt1h44.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgqw64lkom5pk3qgt1h44.jpg" alt=""&gt;Fig.The metrics are being collected and visualized in real
time’
    
    &lt;/a&gt;


&lt;p&gt;Also, the database is collecting the metrics live from JMeter which&lt;br&gt;
can be verified as below :&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/nds1sxfhjkft7hq6ak6q.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnds1sxfhjkft7hq6ak6q.jpg" alt=""&gt;Fig.Verifying whether the measurements are being collected
    
    &lt;/a&gt;


&lt;p&gt;In InfluxDB, ‘&lt;strong&gt;measurements’&lt;/strong&gt; can be thought of as tables. Each of&lt;br&gt;
these measurements has a timestamped value can be queried like below :&lt;/p&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/v781mj7rg83zn7pvhad5.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fv781mj7rg83zn7pvhad5.jpg" alt=""&gt;Fig.Querying the measurement ‘virtualUsers’
    
    &lt;/a&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Telegraf&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Telegraf is an open source plugin-driven agent used to collect&lt;br&gt;
server metrics. The types of metrics to be collected can be&lt;br&gt;
customized by adding new plugins or editing existing ones. The goal&lt;br&gt;
of using this server agent is to collect the server metrics from the&lt;br&gt;
server where the application is being hosted and have them delivered&lt;br&gt;
to the backend which in our case is InfluxDB which can then be&lt;br&gt;
viewed live from Grafana as earlier.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Installing Telegraf as a Windows Service&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Download Telegraf from the url below which will download the&lt;br&gt;
packaged in a zipped format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://portal.influxdata.com/downloads/" rel="noopener noreferrer"&gt;https://portal.influxdata.com/downloads/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract the contents on a destination folder. The folder should&lt;br&gt;
contain a ‘&lt;em&gt;telegraf.conf&lt;/em&gt;’ file containing the Telegraf&lt;br&gt;
configurations.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


    &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/kpix4blv0rehpgfzjnba.jpg" rel="noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkpix4blv0rehpgfzjnba.jpg" alt=""&gt;
    &lt;/a&gt;


&lt;p&gt;Inside the config file, there are multiple options to collect the&lt;br&gt;
 server metrics as well as other configuration options. For example,&lt;br&gt;
 under the ‘&lt;strong&gt;[agent]&lt;/strong&gt;’, there are options which can be configured&lt;br&gt;
 to select how the metrics will be collected.&lt;/p&gt;

&lt;p&gt;For example, the ‘&lt;strong&gt;interval&lt;/strong&gt;’ config option is used to set the&lt;br&gt;
 duration of the metric being collected.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
        &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/mxp41wfgro99vn6u0ebo.jpg" rel="noopener noreferrer"&gt;&lt;br&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmxp41wfgro99vn6u0ebo.jpg" alt=""&gt;&lt;br&gt;
        &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We can leave these options as it is for now. The main focus is on the&lt;br&gt;
 ‘outputs’ section of this config file. It is here where the output&lt;br&gt;
 format and destinations are specified.&lt;/p&gt;

&lt;p&gt;For example, if the InfluxDB is being hosted locally on port 8086 and&lt;br&gt;
 the metrics are to be collected in a database named ‘jmeterStress’,&lt;br&gt;
 then the following configurations should be specified under the&lt;br&gt;
 &lt;strong&gt;[[outputs.influxdb]]&lt;/strong&gt; section, which is an output plugin of&lt;br&gt;
 Telegraf.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
        &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/qz8h8anlgfgpr02ym4ax.jpg" rel="noopener noreferrer"&gt;&lt;br&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqz8h8anlgfgpr02ym4ax.jpg" alt=""&gt;&lt;br&gt;
        &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now that the backend details are set up, we need to specify which&lt;br&gt;
 metrics are to be collected. This can be set up under the&lt;br&gt;
 ‘&lt;strong&gt;[[inputs.win_perf_counters]]&lt;/strong&gt;’ plugin configuration. Some of&lt;br&gt;
 the common metric options are CPU usage, Process metrics, Disk time&lt;br&gt;
 and queues, Network metrics etc.&lt;/p&gt;

&lt;p&gt;Details of other options are in the url below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_perf_counters" rel="noopener noreferrer"&gt;https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_perf_counters&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once these configurations are done the telegraf agent starts sending&lt;br&gt;
 out the metrics to the backend at the specified interval which can&lt;br&gt;
 then be shown over Grafana in a live manner.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
        &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/notcjh653swt4ggiy2ay.jpg" rel="noopener noreferrer"&gt;&lt;br&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnotcjh653swt4ggiy2ay.jpg" alt=""&gt;&lt;br&gt;Fig. Measurements being collected at InfluxDB from Telegraf
        &lt;br&gt;
        &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;These metrics can then be represented in Grafana by using any one of&lt;br&gt;
 the available templates in the url below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://grafana.com/grafana/dashboards?dataSource=influxdb&amp;amp;search=telegraf" rel="noopener noreferrer"&gt;https://grafana.com/grafana/dashboards?dataSource=influxdb&amp;amp;search=telegraf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
        &lt;a href="https://thepracticaldev.s3.amazonaws.com/i/fx0wt4xhgwennceie7ae.jpg" rel="noopener noreferrer"&gt;&lt;br&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffx0wt4xhgwennceie7ae.jpg" alt=""&gt;&lt;br&gt;Fig. The server metrics being displayed in the Grafana dashboard
        &lt;br&gt;
        &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>jmeter</category>
      <category>grafana</category>
      <category>influxdb</category>
      <category>telegraf</category>
    </item>
  </channel>
</rss>
