Preface
In front of us we talked about the 8 key locations an application should monitor.
. Well.. The address is as follows:
8 Key performance indicators and measurement methods for applications
Finally sold a small xiaoguanzi about how to monitor the ASP.
Today we will talk about how to monitor it, below:
Read about the technologies and content you need to know in this article:
InfluxDb (Distributed time Series database, open source) (Note: The distributed part has been commercialized the latest distributed version is no longer open source, the single case continues to open source)
Grafana (open source, fully functional metric panel and graphic editor)
App Metrics (lead, open source support for. NET Core's monitoring plug-in, with pipeline injection, minimal intrusion into code)
The test environment of this article is Windows64 bit, of course, this scheme can all be implemented on Linux (even Windows should be a fallback scheme--awkward.)
so this article is divided into 3 steps
1. Install INFLUXDB and create a database
2. Install the Grafana and add the relevant configuration
3. Use the app Metrics in ASP.
Now we're officially starting.
Body
1. Install INFLUXDB,
and create a database
App.metrics supports a lot of libraries, there are InfluxDB, Graphite, Prometheus.
Today we have mainly influxdb as an example.
Download First, InfluxDb
Know you're too lazy to find. The address is as follows: Https://portal.influxdata.com/downloads#influxdb
Download the corresponding version of the system that you need. I'm going to download Windows Binaries (64-bit) directly
Installation steps for Linux I will not say more, a lot of online. Talk about Windows installation Influxdb considerations (.. This thing has a lot better support for liunx than Windows).
Open influxdb.conf after decompression, because the default configuration of Influxdb is all for Linux configuration. So we're going to change the configuration file.
Change the path of the following 3 Liunx to the WINODWS path as follows:
[Meta] is stored "d:/influxdb/meta"
[Data] where the TSM storage engine stores TSM files. "d:/influxdb/data"
Where the TSM storage engine stores WAL files. "d:/influxdb/wal"
Then modify the Web page graphical management interface configuration, the port is as follows:
[Admin] is enabled. true default": 8083"
Last cmd run, go to your unzip directory, execute command:
Influxd-config influxdb.conf
Get results:
We're done with the installation.
We enter the management interface of the listening port: http://localhost:8083/, you will see the following interface:
Then we enter the SQL statement CREATE database "Your library name"
See, it is the implementation of success.
Let's check to see if it's true. Enter the SQL statement: SHOW DATABASES
:
In addition to the default first library, as well as your own added library name, it means that the success of the add, well, the installation is the end of this
2. Install the Grafana and add the relevant configuration
Then we install Grafana,
: Https://grafana.com/get
After we unzip it into the bin directory:
Run Grafana-server.exe directly.
Grafana listens to port 3000 by default, so we enter http://localhost:3000,
Will let you login, directly enter the local administrator account can, account: admin password: admin, enter after:
After the installation is complete, we download the relevant instrument template.
The address is as follows: https://grafana.com/dashboards/2140 (is a JSON file)
Then we import our meter: The operation can:
Then, add the data source above us.
:
Select Add DataSource, and then proceed as follows:
This allows us to complete the Grafana installation configuration and add a data source
3. Use the app Metrics in ASP.
The next step is our play, using AppMetrics in ASP.
We randomly create an ASP. NET Core MVC project:
To add a reference with a NuGet package:
Core program:
Expansion of Pipeline injection:
Extension of ASP. NET Core MVC:
Other relevant libraries to use: ( Note: Our data source is influxdb, so use this library, other libraries please search the suffix of other libraries)
We go back to our familiar C # code, and in startup we write the injected code as follows:
First modify the Configureservices method as follows:
PublicvoidConfigureservices (iservicecollection services) {var database ="TestData";var uri =New Uri ("http://127.0.0.1:8086"); Services. Addmetrics (options ={Options. Globaltags.add ("App","Sample App"); Options. Globaltags.add ("Env", "stage" ); }) . Addhealthchecks (). Addjsonserialization (). Addreporting (Factory => {factory. Addinfluxdb (new influxdbreportersettings { Influxdbsettings = new influxdbsettings (database, URI), Reportinterval = timespan.fromseconds (5new[] {404}); // ADD framework Services. Services. Addmvc (); }
Join our InfluxDB -related configuration, where database is the name of the databases you entered yourself. The URI is the address of your database.
Then we need to inject our metrics monitoring at the start of the program, so modify the Configure code as follows:
PublicvoidConfigure (Iapplicationbuilder app, Ihostingenvironment env, Iloggerfactory loggerfactory, Iapplicationlifetime Lifetime) {Loggerfactory.addconsole (Configuration.getsection ("Logging")); App. Usemetrics (); App. Usemetricsreporting (Lifetime);//loggerfactory.adddebug (); ifelse {app. Useexceptionhandler ( "/home/error ");} App. Usestaticfiles (); App. USEMVC (Routes => {routes. MapRoute (name: "default" "{controller= Home}/{action=index}/{id?} "
Which app. Usemetrics (); App. Usemetricsreporting (Lifetime), is our injected code:
Other places. Don't move the shred. How is there almost nothing invasive ~.
At last, we ran up.
Just click on a few pages in the home, or call.
Then go to the Grafana monitoring page and you will see the following information:
written in the last
This is just a simple talk about how to do the primary monitoring, in fact, there are more features such as heartbeat detection, the latter will be slowly speaking.
The. Net core is also starting to take off the community this year, and the monitoring is just finished, and the author has been active in the update.
It is regrettable that this is supported. NET4.5.2 above, but due to fewer people concerned. So just out of the RC preview version. Support for the latest version is not perfect.
I also gave the author a issues,https://github.com/alhardy/appmetrics/issues/177 on GitHub.
I hope you will join the group of interested friends, here also spit the trough a bit,.. I just have a word. The community needs us to create it in common, rather than waiting to pick out the ready-made Peaches .
Http://www.cnblogs.com/GuZhenYin/p/7170010.html
Real-time performance monitoring of cross-platform of ASP. NET Core