summaryrefslogtreecommitdiff
path: root/src/client/app/common
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-09 04:14:26 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-09 04:14:26 +0900
commitc78945436e39121f46e083eac7a6572ca2efe2d2 (patch)
treeb26036a9f38bda54b865e704f8bcd477f2caac0e /src/client/app/common
parentサーバーの統計情報をメモリに記憶するようにするなど (diff)
downloadsharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.tar.gz
sharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.tar.bz2
sharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.zip
#1686
Diffstat (limited to 'src/client/app/common')
-rw-r--r--src/client/app/common/scripts/streaming/notes-stats.ts (renamed from src/client/app/common/scripts/streaming/server.ts)10
-rw-r--r--src/client/app/common/scripts/streaming/server-stats.ts30
-rw-r--r--src/client/app/common/views/widgets/index.ts2
-rw-r--r--src/client/app/common/views/widgets/posts-monitor.vue182
-rw-r--r--src/client/app/common/views/widgets/server.vue6
5 files changed, 222 insertions, 8 deletions
diff --git a/src/client/app/common/scripts/streaming/server.ts b/src/client/app/common/scripts/streaming/notes-stats.ts
index 2ea4239288..9e3e78a709 100644
--- a/src/client/app/common/scripts/streaming/server.ts
+++ b/src/client/app/common/scripts/streaming/notes-stats.ts
@@ -3,15 +3,15 @@ import StreamManager from './stream-manager';
import MiOS from '../../../mios';
/**
- * Server stream connection
+ * Notes stats stream connection
*/
-export class ServerStream extends Stream {
+export class NotesStatsStream extends Stream {
constructor(os: MiOS) {
- super(os, 'server');
+ super(os, 'notes-stats');
}
}
-export class ServerStreamManager extends StreamManager<ServerStream> {
+export class NotesStatsStreamManager extends StreamManager<NotesStatsStream> {
private os: MiOS;
constructor(os: MiOS) {
@@ -22,7 +22,7 @@ export class ServerStreamManager extends StreamManager<ServerStream> {
public getConnection() {
if (this.connection == null) {
- this.connection = new ServerStream(this.os);
+ this.connection = new NotesStatsStream(this.os);
}
return this.connection;
diff --git a/src/client/app/common/scripts/streaming/server-stats.ts b/src/client/app/common/scripts/streaming/server-stats.ts
new file mode 100644
index 0000000000..9983dfcaf0
--- /dev/null
+++ b/src/client/app/common/scripts/streaming/server-stats.ts
@@ -0,0 +1,30 @@
+import Stream from './stream';
+import StreamManager from './stream-manager';
+import MiOS from '../../../mios';
+
+/**
+ * Server stats stream connection
+ */
+export class ServerStatsStream extends Stream {
+ constructor(os: MiOS) {
+ super(os, 'server-stats');
+ }
+}
+
+export class ServerStatsStreamManager extends StreamManager<ServerStatsStream> {
+ private os: MiOS;
+
+ constructor(os: MiOS) {
+ super();
+
+ this.os = os;
+ }
+
+ public getConnection() {
+ if (this.connection == null) {
+ this.connection = new ServerStatsStream(this.os);
+ }
+
+ return this.connection;
+ }
+}
diff --git a/src/client/app/common/views/widgets/index.ts b/src/client/app/common/views/widgets/index.ts
index a4cabc43ba..0190393ba7 100644
--- a/src/client/app/common/views/widgets/index.ts
+++ b/src/client/app/common/views/widgets/index.ts
@@ -4,6 +4,7 @@ import wAnalogClock from './analog-clock.vue';
import wVersion from './version.vue';
import wRss from './rss.vue';
import wServer from './server.vue';
+import wPostsMonitor from './posts-monitor.vue';
import wMemo from './memo.vue';
import wBroadcast from './broadcast.vue';
import wCalendar from './calendar.vue';
@@ -22,6 +23,7 @@ Vue.component('mkw-tips', wTips);
Vue.component('mkw-donation', wDonation);
Vue.component('mkw-broadcast', wBroadcast);
Vue.component('mkw-server', wServer);
+Vue.component('mkw-posts-monitor', wPostsMonitor);
Vue.component('mkw-memo', wMemo);
Vue.component('mkw-rss', wRss);
Vue.component('mkw-version', wVersion);
diff --git a/src/client/app/common/views/widgets/posts-monitor.vue b/src/client/app/common/views/widgets/posts-monitor.vue
new file mode 100644
index 0000000000..bdf811bad0
--- /dev/null
+++ b/src/client/app/common/views/widgets/posts-monitor.vue
@@ -0,0 +1,182 @@
+<template>
+<div class="mkw-posts-monitor">
+ <mk-widget-container :show-header="props.design == 0" :naked="props.design == 2">
+ <template slot="header">%fa:chart-line%%i18n:@title%</template>
+ <button slot="func" @click="toggle" title="%i18n:@toggle%">%fa:sort%</button>
+
+ <div class="qpdmibaztplkylerhdbllwcokyrfxeyj" :class="{ dual: props.view == 0 }" :data-darkmode="$store.state.device.darkmode">
+ <svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" preserveAspectRatio="none" v-show="props.view != 2">
+ <defs>
+ <linearGradient :id="fediGradientId" x1="0" x2="0" y1="1" y2="0">
+ <stop offset="0%" stop-color="hsl(200, 80%, 70%)"></stop>
+ <stop offset="100%" stop-color="hsl(90, 80%, 70%)"></stop>
+ </linearGradient>
+ <mask :id="fediMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
+ <polyline
+ :points="fediPolylinePoints"
+ fill="none"
+ stroke="#fff"
+ stroke-width="1"/>
+ </mask>
+ </defs>
+ <rect
+ x="-1" y="-1"
+ :width="viewBoxX + 2" :height="viewBoxY + 2"
+ :style="`stroke: none; fill: url(#${ fediGradientId }); mask: url(#${ fediMaskId })`"/>
+ <text x="1" y="5">Fedi</text>
+ </svg>
+ <svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" preserveAspectRatio="none" v-show="props.view != 1">
+ <defs>
+ <linearGradient :id="localGradientId" x1="0" x2="0" y1="1" y2="0">
+ <stop offset="0%" stop-color="hsl(200, 80%, 70%)"></stop>
+ <stop offset="100%" stop-color="hsl(90, 80%, 70%)"></stop>
+ </linearGradient>
+ <mask :id="localMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
+ <polyline
+ :points="localPolylinePoints"
+ fill="none"
+ stroke="#fff"
+ stroke-width="1"/>
+ </mask>
+ </defs>
+ <rect
+ x="-1" y="-1"
+ :width="viewBoxX + 2" :height="viewBoxY + 2"
+ :style="`stroke: none; fill: url(#${ localGradientId }); mask: url(#${ localMaskId })`"/>
+ <text x="1" y="5">Local</text>
+ </svg>
+ </div>
+ </mk-widget-container>
+</div>
+</template>
+
+<script lang="ts">
+import define from '../../../common/define-widget';
+import * as uuid from 'uuid';
+
+export default define({
+ name: 'server',
+ props: () => ({
+ design: 0,
+ view: 0
+ })
+}).extend({
+ data() {
+ return {
+ connection: null,
+ connectionId: null,
+ viewBoxY: 30,
+ stats: [],
+ fediGradientId: uuid(),
+ fediMaskId: uuid(),
+ localGradientId: uuid(),
+ localMaskId: uuid(),
+ fediPolylinePoints: '',
+ localPolylinePoints: '',
+ fediPolygonPoints: '',
+ localPolygonPoints: ''
+ };
+ },
+ computed: {
+ viewBoxX(): number {
+ return this.props.view == 0 ? 50 : 100;
+ }
+ },
+ watch: {
+ viewBoxX() {
+ this.draw();
+ }
+ },
+ mounted() {
+ this.connection = (this as any).os.streams.notesStatsStream.getConnection();
+ this.connectionId = (this as any).os.streams.notesStatsStream.use();
+
+ this.connection.on('stats', this.onStats);
+ this.connection.on('statsLog', this.onStatsLog);
+ this.connection.send({
+ type: 'requestLog',
+ id: Math.random().toString()
+ });
+ },
+ beforeDestroy() {
+ this.connection.off('stats', this.onStats);
+ this.connection.off('statsLog', this.onStatsLog);
+ (this as any).os.streams.notesStatsStream.dispose(this.connectionId);
+ },
+ methods: {
+ toggle() {
+ if (this.props.view == 2) {
+ this.props.view = 0;
+ } else {
+ this.props.view++;
+ }
+ this.save();
+ },
+ func() {
+ if (this.props.design == 2) {
+ this.props.design = 0;
+ } else {
+ this.props.design++;
+ }
+ this.save();
+ },
+ draw() {
+ const stats = this.props.view == 0 ? this.stats.slice(0, 50) : this.stats;
+ const fediPeak = Math.max.apply(null, this.stats.map(x => x.all)) || 1;
+ const localPeak = Math.max.apply(null, this.stats.map(x => x.local)) || 1;
+
+ this.fediPolylinePoints = this.stats.map((s, i) => `${this.viewBoxX - ((this.stats.length - 1) - i)},${(1 - (s.all / fediPeak)) * this.viewBoxY}`).join(' ');
+ this.localPolylinePoints = this.stats.map((s, i) => `${this.viewBoxX - ((this.stats.length - 1) - i)},${(1 - (s.local / localPeak)) * this.viewBoxY}`).join(' ');
+
+ this.fediPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${ this.viewBoxY } ${ this.fediPolylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`;
+ this.localPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${ this.viewBoxY } ${ this.localPolylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`;
+ },
+ onStats(stats) {
+ this.stats.push(stats);
+ if (this.stats.length > 100) this.stats.shift();
+ this.draw();
+ },
+ onStatsLog(statsLog) {
+ statsLog.forEach(stats => this.onStats(stats));
+ }
+ }
+});
+</script>
+
+<style lang="stylus" scoped>
+root(isDark)
+ &.dual
+ > svg
+ width 50%
+ float left
+
+ &:first-child
+ padding-right 5px
+
+ &:last-child
+ padding-left 5px
+
+ > svg
+ display block
+ padding 10px
+ width 100%
+
+ > text
+ font-size 5px
+ fill isDark ? rgba(#fff, 0.55) : rgba(#000, 0.55)
+
+ > tspan
+ opacity 0.5
+
+ &:after
+ content ""
+ display block
+ clear both
+
+.qpdmibaztplkylerhdbllwcokyrfxeyj[data-darkmode]
+ root(true)
+
+.qpdmibaztplkylerhdbllwcokyrfxeyj:not([data-darkmode])
+ root(false)
+
+</style>
diff --git a/src/client/app/common/views/widgets/server.vue b/src/client/app/common/views/widgets/server.vue
index 2fdd60499b..d796a3ae05 100644
--- a/src/client/app/common/views/widgets/server.vue
+++ b/src/client/app/common/views/widgets/server.vue
@@ -55,11 +55,11 @@ export default define({
this.fetching = false;
});
- this.connection = (this as any).os.streams.serverStream.getConnection();
- this.connectionId = (this as any).os.streams.serverStream.use();
+ this.connection = (this as any).os.streams.serverStatsStream.getConnection();
+ this.connectionId = (this as any).os.streams.serverStatsStream.use();
},
beforeDestroy() {
- (this as any).os.streams.serverStream.dispose(this.connectionId);
+ (this as any).os.streams.serverStatsStream.dispose(this.connectionId);
},
methods: {
toggle() {