本文為大家分享了NancyFx框架檢測(cè)任務(wù)管理器的具體方法,供大家參考,具體內(nèi)容如下
調(diào)兵山ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
先建一個(gè)空的項(xiàng)目和之前的NancyFx系列一樣的步驟
然后建三個(gè)文件夾Models,Module,Views
然后分別安裝一下組件
jQuery
Microsoft.AspNet.SignalR
Microsoft.Owin
Nancy
Nancy.Owin
然后往Model類里面添加CPUHub類,Broadcaster類
CPUHub類
public class CPUHub:Hub { private readonly Broadcaster broadcaster; public CPUHub():this(Broadcaster.broadcaster) { } public CPUHub(Broadcaster broadcaster) { this.broadcaster = broadcaster; } }
Broadcaster類
public class Broadcaster { private readonly static Lazy<Broadcaster> lazy = new Lazy<Broadcaster>(()=>new Broadcaster(GlobalHost.ConnectionManager.GetHubContext<CPUHub>().Clients)); private readonly TimeSpan timeSpan = TimeSpan.FromMilliseconds(1000); private readonly Timer timer; public static Broadcaster broadcaster { get { return lazy.Value; } } private IHubConnectionContext hubConnectionContext { get; set; } private Broadcaster(IHubConnectionContext hubConnectionContexts) { hubConnectionContext = hubConnectionContexts; timer = new Timer(BroadcastCpuUsage,null,timeSpan,timeSpan); } private void BroadcastCpuUsage(object o) { string cpu = GetCurrentCpu(); } private string GetCurrentCpu() { string currentCpu = ""; HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("http://localhost:3039"); var response = httpClient.GetAsync("api/cpu").Result; if (response.IsSuccessStatusCode) { currentCpu = response.Content.ReadAsStringAsync().Result; } return currentCpu; } }
然后在往Module里面添加CPUModule類
public class CPUModule:NancyModule { PerformanceCounter performanceCounter; public CPUModule():base("api/cpu") { InitializePerformanceCounter(); Get("/",Lexan=> { int cpu = (int)Math.Ceiling(performanceCounter.NextValue()); return Response.AsText(cpu.ToString()); }); } private void InitializePerformanceCounter() { performanceCounter = new PerformanceCounter(); performanceCounter.CategoryName = ""; performanceCounter.CounterName = ""; performanceCounter.InstanceName = ""; performanceCounter.NextValue(); Thread.Sleep(1000); } }
然后添加index.html頁(yè)面在根目錄下
<!DOCTYPE html> <html> <head> <title>NancyTaskManager</title> </head> <body> <label id="lblVal"></label> <br /> <canvas id="cvPercentage"></canvas> <br /> <br /> <canvas id="cvGraph" height="450" width="600"></canvas> <script src="Scripts/jquery-2.1.0.js"></script> <script src="Scripts/jquery.signalR-2.0.2.js"></script> <script src="Scripts/Chart.js"></script> <script src="/signalr/hubs"></script> <script src="Scripts/taskManager.js"></script> </body> </html>
繼續(xù)往根目錄里面添加Startup類
[assembly:OwinStartup(typeof( NancyFxTaskManager.Startup))] namespace NancyFxTaskManager { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR().UseNancy(); } } }
好了我們準(zhǔn)備就緒,看看運(yùn)行效果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)頁(yè)標(biāo)題:NancyFx框架檢測(cè)任務(wù)管理器詳解
文章起源:http://m.rwnh.cn/article24/pcddce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、虛擬主機(jī)、軟件開發(fā)、網(wǎng)站內(nèi)鏈、品牌網(wǎng)站制作、全網(wǎng)營(yíng)銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)