How to Check Whether API Server is up or Down

Introduction

In this article we will create a small utility using C# that tells us whether our API server is up or down.

Purpose

Our purpose is to check the API server so, we can make a request for our resources. It is recommended that before making any request to the server (API server in our case), we should ensure that our server is ready and up to handle our requests.

Throughout this article we will create a tiny utility to satisfy that purpose.

Requirements

So, what do we require? We just want to know the status of our Web API server.

Creation of Utility

Let‘s create a simple console app that tells us the status of our API server:

Open Visual Studio

Create a C# console application, name it "knowserverstatus" .

Add the following method:

  1. public static void ServerStatusBy(string url)
  2. {
  3. Ping pingSender = new Ping();
  4. PingReply reply = pingSender.Send(url);
  5. Console.WriteLine("Status of Host: {0}", url);
  6. if (reply.Status == IPStatus.Success)
  7. {
  8. Console.WriteLine("IP Address: {0}", reply.Address.ToString());
  9. Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
  10. Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
  11. Console.WriteLine("Don‘t fragment: {0}", reply.Options.DontFragment);
  12. Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
  13. }
  14. else
  15. Console.WriteLine(reply.Status);
  16. }

Do not forget to add following namespace:

  1. using System.Net.NetworkInformation;

Call this method from main:

  1. Console.Write("Enter server url:");
  2. var url = Console.ReadLine();
  3. Console.Clear();
  4. ServerStatusBy(url);
  5. Console.ReadLine();

Run it and we will get the following output:

Elaboration of code

Let‘s elaborate on the preceding code. Here PING sends an Internet Control Message Protocol (ICMP) request to the requested server host/URL and waits to receive the response back. If the value of Status is success then that means our server is up and running.

Here PingReply returns all properties, described as:

Property Description
Address Gets the address of Host
Buffer Gets the buffer of data received, its an array of bytes
PingOption It handles how data transmitted
RoundTrip Gets the number of milliseconds to send ICMP echo request
Status Gets the status of request. If not Success , in other words Host is not up

Conclusion

In this article we discussed all about the PingReply class and using this class, we created a utility to know the status of our server.

src: http://www.c-sharpcorner.com/UploadFile/g_arora/how-to-check-whether-api-server-is-up-or-down/

By Gaurav Kumar Arora on Mar 14, 2015

时间: 04-13

How to Check Whether API Server is up or Down的相关文章

拿nodejs快速搭建简单Oauth认证和restful API server攻略

拿nodejs快速搭建简单Oauth认证和restful API server攻略:http://blog.csdn.net/zhaoweitco/article/details/21708955 最近一直在鼓捣这个东西,拿出来分享下一下经验吧,其实很简单,一点也不难. 首先需求是这样,给自己的网站要增加API服务,API分为两种,公共的和私有授权的,授权的使用Oauth方法认证身份,API格式均为JOSN和JSONP. 嗯,别的语言我也没怎么学过,首先是找合适的框架进行实现吧.本身网站使用的e

Check GitLab API access: FAILED: Failed to connect to internal API

执行 sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production 检查提示Check GitLab API access: FAILED: Failed to connect to internal API 查看gitlab/config/unicorn.rb listen "127.0.0.1:9000", :tcp_nopush => true gitlab/config/gitlab.yml中填写的公网

Simple Web API Server in Golang (2)

In this challenge, I tried to implement a simple OAuth2 server basing on Simple Web API Server in [1]. For OAuth2, go to http://oauth.net/2/. Endpoint /api/2/domains/{domain name}/oauth/access_token Use port 80. We would like to use other ports such

Simple Web API Server in Golang (1)

To be an better Gopher, get your hands dirty. Topcoder offered a serials of challenges for learning Golang. In this blog, I tried to implement "Go Learning Challenge - Simple Web-API Server"[1]. What's used in this challenge ? Following aspects

kubernetes API Server 权限管理实践

API Server 权限管理应用 API Server权限控制方式介绍 API Server权限控制分为三种:Authentication(身份认证).Authorization(授权).AdmissionControl(准入控制). 身份认证: 当客户端向Kubernetes非只读端口发起API请求时,Kubernetes通过三种方式来认证用户的合法性.kubernetes中,验证用户是否有权限操作api的方式有三种:证书认证,token认证,基本信息认证. 证书认证 设置apiserver

A server is already running. Check tmp/pids/server.pid.

A server is already running. Check  tmp/pids/server.pid. 把server.pid删除: 学习了: http://stackoverflow.com/questions/24627701/a-server-is-already-running-check-tmp-pids-server-pid-exiting-rails

Kubernetes API Server原理

Kubernetes API Server功能 Kubernete API Server的核心功能主要是为Kubernetes的各类资源对象(如 node,pod,service等)提供了增.删.改.查以及watch的HTTP Rest接口.API server是集群中各个功能模块之间数据交互和通信的中心枢纽,除此之外它还有以下特性: 集群管理的API入口 资源配额控制的入口 提供完备的集群安全机制 常规API接口 Kubernetes的 API server通过 kube-apiserver进

深度剖析Kubernetes API Server三部曲 - part 1

欢迎来到深入学习Kubernetes API Server的系列文章,在本系列文章中我们将深入的探究Kubernetes API Server的相关实现.如果你对Kubernetes 的内部实现机制比较感兴趣或者正在进行Kubernetes 项目的相关开发工作,那么本系列文章能够为你提供一些帮助.了解学习过go语言,会在某些方面帮助你更好的理解本系列文章.在本期文章中,我们首先会对Kubernetes API Server进行一个总体的大致说明,然后对API的技术术语及请求流作说明.在下几期的文

深度剖析Kubernetes API Server三部曲 - part 3

在本系列的前两部分中我们介绍了API Server的总体流程,以及API对象如何存储到etcd中.在本文中我们将探讨如何扩展API资源.在一开始的时候,扩展API资源的唯一方法是扩展相关API源代码,集成为你所需的资源.或者,推动一个全新的类型为新的核心对象API合入社区代码.但是,这样就会导致核心API资源类型的不断增加,直至API过载.为了避免这种API资源的无限制扩展,在Kubernetes中提供两种扩展核心API的方法: 使用自定义资源定义(CRDs),最开始的时候被称为第三方资源(TP