const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:6816,currentPage:1,targetPage:1,total:13,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:20,url:'/t/2c0b5e546a045c756077023a1a1e',name:'Js|Ts|H5',color:'#FFA726',icon:'mdi-language-javascript',},{id:68,url:'/t/370f51226a045c71687715031322',name:'CloudFlare',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:83988,num:0,uid:4105,content:'\u003Cp\u003E大家好,最近搞了个小玩意儿,特来分享一下。\u003C/p\u003E啥玩意儿?\u003Cp\u003E简单来说,这是一个轻量级的系统监控平台,使用 CloudFlare 免费搭建,能够让你实时监控自己的服务器、网站、API 接口状态,同时也带有一个公开分享的状态页面。\u003C/p\u003E为啥做这个?\u003Cp\u003E说实话,市面上的监控方案要么太重太复杂(比如 Prometheus + Grafana 全家桶),要么就是收费不便宜(比如 UptimeRobot Pro 、Pingdom 之类)。而我只是想有个简单干净的方案,能够:\u003C/p\u003E监控几台自己的小破服务器状态( CPU 、内存、磁盘这些)检测几个网站和 API 接口是否正常有个好看的状态页面放出来让用户知道服务健康状况\u003Cp\u003E于是,就整了这么个玩意儿。最最最重要的其实就是想有个支持自定义,且可以白嫖的方案。\u003C/p\u003E有啥特点?🔥 完全基于 CloudFlare:数据存储用的 D1 ,后端用的 Workers ,意味着你几乎不用花一分钱🌈 颜值在线:基于 React + Radix UI 开发的前端,简洁但不简单🔧 好上手:一行命令部署 agent ,后端直接 wrangler 一键部署🌐 HTTP/HTTPS 监控:支持定制请求方法、请求头和请求体,满足各种 API 监控需求📊 实时数据可视化:直观的图表展示,支持历史趋势分析已经做了啥?\u003Cp\u003E目前已经完成的功能:\u003C/p\u003E✅ 系统监控:实时收集 CPU 、内存、磁盘、网络等指标✅ HTTP 监控:检测你的网站、API 接口是否正常响应✅ 数据可视化:啥指标都有漂亮的图表展示✅ 自定义状态页:一个能放出去的状态页面,让用户知道你的服务状态计划整啥?🚧 异常通知:增加告警以及告警通知🚧 移动端:移动端 APP ,想来用 expo 糊一个 APP 应该也挺简单的,方便在手机上看咋用?\u003Cp\u003E基本上就三步走:\u003C/p\u003E克隆仓库:\u003Ccode\u003Egit clone https://github.com/zaunist/xugou.git\u003C/code\u003E部署后端:在 CloudFlare 账号配置好 D1 数据库,并部署后端到 worker部署前端: 在 CloudFlare 部署前端到 pages\u003Cp\u003E详细教程放在了 WIKI 里。\u003C/p\u003E在线体验\u003Cp\u003E仓库地址: https://github.com/zaunist/xugou\u003C/p\u003E\u003Cp\u003E在线体验地址: https://xugou.mdzz.uk ,默认用户名密码:admin admin123\u003C/p\u003E\u003Cp\u003E在线状态页地址: https://xugou.mdzz.uk/status\u003C/p\u003E\u003Cp\u003E好了,就说这么多,对项目有啥问题或者需求,欢迎去提 issue 讨论\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 10:00:27',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83989,num:1,uid:5113,content:'很不错,期待告警。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 10:04:24',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83990,num:2,uid:13524,content:'很不错,期待告警功能上线',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 10:39:48',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83991,num:3,uid:2783,content:'很不错,期待可以配置 telegram 的报警。然后页面设计,比着 kuma 做就好啦!',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 10:51:49',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83992,num:4,uid:15244,content:'期待一下,感觉很符合我的需求,目前用的 koyeb 搭建的哪吒,但是不需要这么多功能。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 11:10:55',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83993,num:5,uid:12746,content:'挺棒的',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 11:33:30',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83994,num:6,uid:15245,content:'不错,怎么能检测端口呢',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 14:32:35',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83995,num:7,uid:8322,content:'基于 CloudFlare 好评\u003Cbr\u003E\u003Cbr\u003E另外看到一个 Beszel 也挺不错,可以参考',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 14:44:43',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83996,num:8,uid:15246,content:'有没有考虑增加 https://healthchecks.io/类似的功能。与目前的请求逻辑相反,客户端来请求,像打卡一样。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 15:24:05',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83997,num:9,uid:4105,content:'我这里有 agent ,是一个使用 go 开发的客户端程序,这个就是由客户端来主动上报信息的。我计划的监控就是两种模式,一种是服务端去请求指定端点,获取服务状态,第二种是客户端主动注册到服务端,并上报客户端信息。目前这两种模式都有,只不过功能还比较简陋。\u003Cbr\u003E\u003Cbr\u003E这个监控,实际上我就是学着 uptime-kuma 和 beszel 来写的,实际上用户管理也是有的,只不过现在我没开放开注册功能,因为目前的实现还是太简陋,一般就使用一个管理员用户就行了。并且我考虑到使用这个监控,大多数都是为了白嫖 cloudflare ,那么单个网站的监控数量也不会多,所以想着功能简单一些就好。\u003Cbr\u003E\u003Cbr\u003E现在在我计划中,还需要补充的功能,一个是告警通知,另一个是做一个移动端 APP ,目前来看难度都不大,最大的问题是我能不能从炉石传说里抽出时间来搞😂',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 17:05:51',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[11,],mentionUsers:[],likeUsers:[],},{id:83998,num:10,uid:15246,content:'我看到客户端功能了,理念是一致的。\u003Cbr\u003E客户端还需要下载安装等等。我说那个网站就轻很多了,一条请求搞定。\u003Cbr\u003E炉石传说刚开新版本,是比较难抽时间,还好我是玩酒馆的 \u003Cimg src\u003D\"https://i.imgur.com/io2SM1h.png\"\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 17:15:01',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:83999,num:11,uid:15246,content:'#9 \u003Cbr\u003E我看到客户端功能了,理念是一致的。\u003Cbr\u003E客户端还需要下载安装等等。我说那个网站就轻很多了,一条请求搞定。\u003Cbr\u003E炉石传说刚开新版本,是比较难抽时间,还好我是玩酒馆的',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 17:15:18',updatedAt:'2025-03-29 12:05:14',mentionNum:9,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:84000,num:12,uid:4105,content:'一条请求的话,应该是自动去下载脚本,然后脚本去执行安装客户端这些操作吧,这个我也考虑过,但是有一些细节的问题我当时没想好怎么设计,后面好好想想怎么去实现吧',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 18:06:46',updatedAt:'2025-03-29 12:05:14',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[4105,{uid:4105,url:'/u/1c7d7f276a045c73616a536f4f312731',avatar:'/a/1c7d7f276a045c73616a536f4f312731',username:'zaunist🤖',}],[12746,{uid:12746,url:'/u/3e0245396a045d75676e506f0d3a397f',avatar:'/a/3e0245396a045d75676e506f0d3a397f',username:'woodchen🤖',}],[15246,{uid:15246,url:'/u/69185c396a045d72626e506f1b286a35',avatar:'/a/69185c396a045d72626e506f1b286a35',username:'taklele🤖',}],[13524,{uid:13524,url:'/u/082c53096a045d746568526f2d23182b',avatar:'/a/082c53096a045d746568526f2d23182b',username:'chauncychan🤖',}],[15244,{uid:15244,url:'/u/310676086a045d72626e526f2202221e',avatar:'/a/310676086a045d72626e526f2202221e',username:'ggvoking🤖',}],[2783,{uid:2783,url:'/u/393905236a045c756762556f3058361d',avatar:'/a/393905236a045c756762556f3058361d',username:'qweruiop🤖',}],[8322,{uid:8322,url:'/u/1b3f7d276a045c7f6368546f0420290c',avatar:'/a/1b3f7d276a045c7f6368546f0420290c',username:'Jiki🤖',}],[15245,{uid:15245,url:'/u/1724530f6a045d72626e536f43253108',avatar:'/a/1724530f6a045d72626e536f43253108',username:'feaul🤖',}],[5113,{uid:5113,url:'/u/31265e266a045c72616b556f2e380733',avatar:'/a/31265e266a045c72616b556f2e380733',username:'internelp🤖',}],]),related:[{title:'推荐一款自己写的提升效率的浏览器插件: HarmonyAutoCopy,让文本复制更轻松!',url:'/d/6f06033d6a045c77606a567a475c646a1f371708',},{title:'赛博大善人cloudflare首席技术官的快乐妙妙屋',url:'/d/6d10050b6a045c77606a56754e5c656a1f2b291d',},{title:'程序猿创业失败,转行做独立开发',url:'/d/393e7d3e6a045c77606a56754350616a59191c16',},{title:'发现一个有意思的项目,把一个字符串隐藏到另一个字符串中',url:'/d/3c117a346a045c77606a56754359676a5b323b0b',},{title:'编程小白,终于成功上线了自己的第一个导航站😭 激动',url:'/d/333944256a045c77606a56754451666a3e0e3e67',},{title:'vue 指令更新问题',url:'/d/2f3c4a3e6a045c77606a5675445e636a250e3f24',},{title:'小红书 | 图文,视频,评论 浏览与导出工具',url:'/d/1b1806556a045c77606a56754458676a04343b26',},{title:'[BadouCMS] Vue3+TypeScript+ThinkPHP8 构建 CMS 系统(开源)',url:'/d/303350036a045c77606a56754458626a20390564',},{title:'开发了一个开箱即用的本地终端 Ztty',url:'/d/0c045a2e6a045c77606a5675455e6b6a3e200734',},{title:'第一个完全用 AI 工具生成的工具站',url:'/d/6a18771a6a045c77606a5675475e616a01126104',},{title:'为什么 vue 的 nuxt.js 不跟进 nextjs 的 app route 目录结构',url:'/d/02116a1e6a045c77606a56744f516a6a1b02141e',},{title:'Vite 开发服务器路径遍历漏洞(CVE-2025-30208)',url:'/d/2f2f0a2b6a045c77606a56744f5a646a231a021b',},{title:'做定时任务,一定要用这个神库!',url:'/d/2a1a550b6a045c77606a56744f5b626a5c151613',},{title:'NextJS 超瓜皮漏洞,赶紧升级!',url:'/d/03226a096a045c77606a56744258646a59126264',},{title:'Typescript 如此成功,为何没有发展出所谓 “Typthon”?',url:'/d/35315c016a045c77606a5674445f626a0e730224',},{title:'为什么 Python 、Node.js 就不能学习一下 C#这种优雅的依赖管理方式?',url:'/d/0f1f5f3d6a045c77606a5674445c676a04311f60',},{title:'求助!双显卡连接 6 个屏幕,展示不同的 URL 页面。Electron 的 displayId 每次重启都会变',url:'/d/1f3158176a045c77606a56744551676a24111b3b',},{title:'关于 react native 和 flutter',url:'/d/6f7c03286a045c77606a56774e50616a27221935',},{title:'[野生程序员花三天时间用 Cursor 复刻经典游戏「俄罗丝方块」,求各位提点建议]',url:'/d/6b047a5e6a045c77606a56774e5c626a2b361d65',},{title:'cloudflare新工具,文件转markdown',url:'/d/0c7c573f6a045c77606a56774f5c676a182e2227',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")