.NetCore distributed tracking system from scratch using Skywalking

 

This article from zero to build two webapi projects, using Skywalking to track calling relationships between them and the response time. Development environment for VisualStudio2019

 

1: Installation Skywalking , refer to: https://www.cnblogs.com/sunyuliang/p/11422576.html , Skywalking server address after this column is to build a good: 192.168.150.134

 
2: Open VS demo1 of a project to create webapi.
 
       2.1: Add a reference NuGet package for the project SkyAPM.Agent.AspNetCore                     
 
                               
 
 
 
  2.2, add skyapm.json file in the project root directory, and add content to the next, in which the IP address of Servers node into its own IP server according to the actual situation
{
  "SkyWalking": {
    "ServiceName": "Demo01",
    "Namespace": "",
    "HeaderVersions": [
      "sw6"
    ],
    "Sampling": {
      "SamplePer3Secs": -1,
      "Percentage": -1.0
    },
    "Logging": {
      "Level": "Debug",
      "FilePath": "logs/skyapm-{Date}.log"
    },
    "Transport": {
      "Interval": 3000,
      "ProtocolVersion": "v6",
      "QueueSize": 30000,
      "BatchSize": 3000,
      "gRPC": {
        "Servers": "192.168.150.134:11800", 
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000
      }
    }
  }
}

  2.3: Modify skyapm.json file attributes "Copy to enter the directory" to "Copy if newer"

       2.4: Expand the Properties item, open launchSettings.json file in which environment variables added  " SKYWALKING__SERVICENAME " : " ASP-NET-Core-frontend " 

                             

  2.5: Up to now skywalking has been successfully introduced into the system. Next we come to test whether the normal, direct Ctrl + F5 to start the project, visit https: // localhost: 44313 / api / values

         

  2.6: Access Skywalking management background ( remember to replace what IP ) http://192.168.150.134:8080/trace  . Manually choose what time, end time election tomorrow ( selected at the time time will not search data, do not know the time zone or skywalking bug ), click Search. We can see the tracking information of this visit has been synchronized to Skywalking in.

               

 

 Tracking more than a single system is complete, then we'll create a project, step 2 and step basically the same, take a look at multi-track system, this is the Skywalking of value.

 

3: Another re-open a VS project to create a demo02 of webapi.
 
       3.1: Add a reference NuGet package for the project SkyAPM.Agent.AspNetCore     
 
                                
              
 
  3.2, add in the project root directory skyapm.json file, and add to the contents of the next, in which the IP address of Servers node into its own IP server according to the actual situation. Wherein ServiceName node set: Demo02
{
  "SkyWalking": {
    "ServiceName": "Demo02",
    "Namespace": "",
    "HeaderVersions": [
      "sw6"
    ],
    "Sampling": {
      "SamplePer3Secs": -1,
      "Percentage": -1.0
    },
    "Logging": {
      "Level": "Debug",
      "FilePath": "logs/skyapm-{Date}.log"
    },
    "Transport": {
      "Interval": 3000,
      "ProtocolVersion": "v6",
      "QueueSize": 30000,
      "BatchSize": 3000,
      "gRPC": {
        "Servers": "192.168.150.134:11800", 
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000
      }
    }
  }
}

  3.3: Modify skyapm.json file attributes "Copy to enter the directory" to "Copy if newer"

       3.4: Expand the Properties item, open launchSettings.json file in which environment variables added  " ASPNETCORE_HOSTINGSTARTUPASSEMBLIES " : " SkyAPM.Agent.AspNetCore " 

                             

 

   3.5: without references in the ValuesController.cs in:  a using Microsoft.AspNetCore.Mvc;  , HttpClient by calling two methods Demo01 in turn, inside the https: // localhost: 44313 corresponds to our Demo01 project. DETAILED Get method code is as follows:

    

        // GET api/values
        [HttpGet]
        public async Task<string> Get()
        {
            var client = new HttpClient();
            await client.GetStringAsync("https://localhost:44313/api/values/1");
            return  await client.GetStringAsync("https://localhost:44313/api/values");
        }

                               

 

        3.6: Ctrl + F5 to start the project, visit http: // localhost: 21143 / api / values

 

                                  

 

   3.7: Access Skywalking management background ( remember to replace what IP ) http://192.168.150.134:8080/trace  . Manually choose what time, end time election tomorrow ( selected at the time time will not search data, do not know the time zone or skywalking bug ), click Search. You can see the visit of two single system call graph has been synchronized to the Skywalking

                                  

 

 

 Track among the above multiple systems will have been completed, do not write the complete code, configuration just fine.

 

Guess you like

Origin www.cnblogs.com/sunyuliang/p/11424848.html