go-kit 入门(三)日志和仪表化

日志和仪表化

任何服务在日志和仪表化没有就绪的情况下,都不能说是生产环境就绪的。

传输日志

任何需要日志记录的组件都需要将 logger 作为依赖,就像数据库连接一样。因此,我们在 main 函数中构造 logger 对象,然后将其传入需要使用它的组件中。我们始终不去使用一个全局的 logger 对象。

我们可以直接将 logger 传入到 stringService 的实现代码中,但是,还有一个更好的方式。我们可以使用 中间件 (middleware) ,也常常被称为 装饰者。

middleware 是一个函数,它接收一个 endpoint 作为参数,并且返回一个 endpoint。

在函数中,它可以做任何事情。下面就让我们来创建一个基本的日志中间件。

然后,我们将它加入到每一个处理函数中。

事实证明,这项技术是非常有价值的,远远不止于记录日志,Go kit 的很多模块都被实现为端点中间件。

应用日志

那么,在我们的应用中,应该如何记录日志呢?比如那些需要被传入的参数等。事实上,我们能够为我们的服务定义一个中间件,从而获得同样好的组合效果。由于我们的 StringService被定义为一个接口,我们只需要作出一个新的类型,来包装先有的 StringService,让它来执行扩充的记录日志的任务。

然后,将新的类型引入到下面的代码中:

在传输环节使用端点中间件,比如回路断路器和速率限制。在业务环节使用服务中间件,比如日志和仪表化。

仪表化

在 Go kit 中,仪表化意味着使用 包指标 来记录关于服务运行行为的状态。统计执行的任务的数量,在请求完成后记录消耗的时间,以及跟踪所有正在执行的操作的数量,都被认为是 仪表化。

我们可以使用同样的中间件模式,在记录日志的环节我们曾经用过。

然后将其引入到服务中:

stringsvc2

目前位置,完整的服务是 stringsvc2.

此条目发表在GoLang, MircroService分类目录。将固定链接加入收藏夹。

go-kit 入门(三)日志和仪表化》有 518 条评论

  1. One extra technique in support of advertising your website is posting comments on different sites with your website link.

  2. What’s up, just wanted to tell you, I liked this article. It was inspiring. Keep on posting!

  3. Your mode of describing all in this paragraph is truly pleasant, all can simply know it, Thanks a lot.

  4. Hello, how’s it going? Just shared this post with a colleague, we had a good laugh.

  5. Hello, just wanted to say, I loved this blog post. It was practical. Keep on posting!

  6. Hi there to every , because I am in fact eager of reading this webpage’s post to be updated regularly. It consists of good stuff.

  7. Can you tell us more about this? I’d love to find out more details.

  8. Hurrah, what a quality it is! As mostly YouTube video clips have no nice feature, except this is truly a pleasant quality video.

  9. If you are interested to learn SEO techniques then you have to read this article, I am sure you will take much more from this piece of writing about Search engine marketing.

  10. You have to waste less time to search your required topic on web, because nowadays the searching techniques of search engines are good. That’s why I fount this article here.

  11. What’s up, okay brother there are of course multiple blogging websites, however I suggest you to use Google’s without charge blogging services.

  12. This is my first time go to see at here and i am truly happy to read all at single place.

  13. I all the time download a complete film in parts, that’s always present at YouTube, for the reason that my network connection is extremely slow and YouTube fulfils my needs.

  14. This text is priceless. When can I find out more?

  15. Vohycle说:

    buy cheap generic cialis i
    cheap cialis
    price for cialis online pharmacy
    =http://buyhcialisrx.com/#”>cialis online

  16. Every weekend i used to go to see this website, as i wish for enjoyment, since this this site conations really pleasant funny data too.

  17. Hi there to every body, it’s my first visit of this webpage; this blog includes awesome and actually excellent data for readers.

  18. Endeark说:

    get cialis online
    buy cialis online
    walmart cialis online pharmacy
    =http://buyhcialisrx.com/#”>generic cialis

  19. cheap viagra说:

    What’s up everyone, I am sure you will be enjoying here by watching such comical video clips.

  20. What’s up to all, how is everything, I think every one is getting more from this web page, and your views are pleasant in favor of new users.

  21. Hello, how’s it going? Just shared this post with a colleague, we had a good laugh.

  22. YouTube is world’s leading video sharing web site, no one can defeat it. Every one add video clips at YouTube after that get embed code and post everywhere.

  23. always i used to read smaller content which as well clear their motive, and that is also happening with this article which I am reading at this time.

  24. Every weekend i used to go to see this site, because i wish for enjoyment, for the reason that this this website conations truly fastidious funny stuff too.

  25. I have read much concerning free of charge blogging sites, except I have no clear idea about that, can any one inform me which one is most excellent for free blogging and site-building?

  26. When someone writes an article he/she keeps the thought of a user in his/her mind that how a user can know it. Thus that’s why this article is great. Thanks!

  27. sildenafil说:

    Some viewers are eager to watch comical videos, however I like to watch terrible movies on YouTube.

  28. YouTube is world’s leading video sharing web page, no one can defeat it. Every one upload video tutorials at YouTube then obtain embed code and post anywhere.

  29. 50mg viagra说:

    Quality posts is the key to attract the visitors to pay a quick visit the web page, that’s what this web page is providing.

  30. If some one wants to be updated with most up-to-date technologies afterward he must be pay a quick visit this site and be up to date daily.

  31. I always emailed this blog post page to all my friends, since if like to read it after that my links will too.

  32. Hello friends, how is the whole thing, and what you would like to say concerning this article, in my view its actually amazing for me.

  33. The strategies stated in this piece of writing regarding to increase traffic at you own website are actually nice, thanks for such fastidious article.

  34. Jasonpoine说:

    require some problems with the currency switcher plugin. About come up short, USD is in use. I’ve added some products with a evaluation of ‘100’, the quel est le cours du bitcoin store messenger showed ‘$100’. Then I changed the currency to EUR. The one impression: The offshoot milieu seldom shows the fit USD worth ($106,83) but it should conduct the EUR consequence (€100).

  35. Albertpap说:

    The prostate gland is the central a part of a male’s reproductive system. It secretes fluids that help the transportation and activation of sperm. The prostate gland can be found just as you’re watching rectum, below the bladder and around the urethra. When there is prostate problem, it will always be very uncomfortable and inconvenient for that patient as his urinary product is directly affected.

    The common prostate medical problems are prostate infection, enlarged prostate and prostate type of cancer.

    Prostate infection, often known as prostatitis, is easily the most common prostate-related overuse injury in men younger than 55 years. Infections from the prostate related are classified into four types – acute bacterial prostatitis, chronic bacterial prostatitis, chronic abacterial prostatitis and prosttodynia.

    Acute bacterial prostatitis may be the least common of all varieties of prostate infection. It is a result of bacteria found in the large intestines or urinary tract. Patients may feel fever, chills, body aches, back pains and urination problems. This condition is treated by making use of antibiotics or non-steroid anti-inflammatory drugs (NSAIDs) to relieve the swelling.

    Chronic bacterial prostatitis is often a condition associated with a particular defect within the gland as well as the persistence presence of bacteria inside the urinary tract. It can be due to trauma towards the urinary tract or by infections originating from other regions with the body. A patient can experience testicular pain, small of the back pains and urination problems. Although it is uncommon, it could be treated by removal with the prostate defect then the utilization antibiotics and NSAIDs to treat the soreness.

    Non-bacterial prostatitis is the reason for approximately 90% coming from all prostatitis cases; however, researchers have not even to create the cause of these conditions. Some researchers feel that chronic non-bacterial prostatitis occur as a result of unknown infectious agents while other believe that intensive exercise and high lifting may cause these infections.

    Maintaining a Healthy Prostate

    To prevent prostate diseases, an appropriate weight loss program is important. These are some of the things you can do and also hardwearing . prostate healthy.

    1. Drink sufficient water. Proper hydration is necessary for general health and will also also maintain your urinary track clean.

    2. Some studies advise that a number of ejaculations weekly will assist to prevent cancer of the prostate.

    3. Eat steak in moderation. It has been shown that consuming more than four meals of beef per week will raise the risk of prostate diseases and cancer.

    4. Maintain a suitable diet with cereals, vegetable and fruits to make sure sufficient intake of nutrients necessary for prostate health.

    The most crucial measure to take to make certain a normal prostate is always to select regular prostate health screening. If you are forty years of age and above, you need to go for prostate examination at least once annually.

  36. It’s wonderful that you are getting thoughts from this paragraph as well as from our dialogue made at this time.

  37. What’s up my friends, how is everything? Here it is truly pleasant YouTube video clips collection. i enjoyed a lot.

  38. Please upload more video tutorials related to cooking if you have, as I would like to learn more and more about all recipes of cooking.

  39. Hello, I check your blogs daily. Your story-telling style is awesome, keep it up!

  40. I all the time used to study paragraph in news papers but now as I am a user of net thus from now I am using net for posts, thanks to web.

  41. For my study reasons, I all the time used to download the video lectures from YouTube, since it is trouble-free to fan-out from there.

  42. What’s up, how’s it going? Just shared this post with a colleague, we had a good laugh.

  43. viagra cost说:

    Hello Jackson, if you are a new internet user after that you must go to see every day this web site and read the updated content at here.

  44. Hello Dear, are you genuinely visiting this website on a regular basis, if so after that you will without doubt take nice knowledge.

  45. viagra 50 mg说:

    The strategies mentioned in this article about to increase traffic at you own website are actually good, thanks for such nice piece of writing.

  46. viagra 50 mg说:

    No one can reject from the feature of this video posted at this website, nice job, keep it all the time.

  47. Why users still use to read news papers when in this technological globe all is existing on net?

  48. Can you please send by e-mail me the code for this script or please tell me in detail concerning this script?

  49. That’s actually a pleasant movie pointed out in this article regarding how to write a paragraph, therefore i got clear idea from here.

  50. It’s very trouble-free to find out any topic on web as compared to textbooks, as I fount this post at this site.

评论功能已关闭。